From 623baafce35937c6733b0118a3d2b3e3ea48c7c7 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Mon, 22 Sep 2014 21:54:38 +0300 Subject: [PATCH] Added a new algorithm to fix #15 Added a few if statmenst to fix that issue. in addition , added a privat function to convert the returnd dayOfWeek (QDate returns sunday=7 monday=2...) to JCE Manager format (AKA: sunday=1, monday=2 ....). checked on linux. working great! Issue #15. --- src/jceData/CSV/csv_exporter.cpp | 42 +++++++++++++++++++++++++++++++- src/jceData/CSV/csv_exporter.h | 2 ++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/jceData/CSV/csv_exporter.cpp b/src/jceData/CSV/csv_exporter.cpp index 5f2963d..375321d 100644 --- a/src/jceData/CSV/csv_exporter.cpp +++ b/src/jceData/CSV/csv_exporter.cpp @@ -69,8 +69,20 @@ bool CSV_Exporter::exportCalendar(calendarSchedule *calSched, CalendarDialog *ca QString room = coursePtr->getRoom(); QDate currentDate = cal->getStartDate(); // currentDate will iterate throuh the semester + int firstDayOfSemester = currentDate.dayOfWeek(); //Returns the weekday (1 = Monday to 7 = Sunday) for this date. - currentDate = currentDate.addDays(day-1); //selecting the REAL starting day of that course + changeDayNumberFromQtToNormal(&firstDayOfSemester); //Get sync with our day numbers. + + /* + * these 6 lines will get the right day for the starting poin in a + * semester for eatch course. + */ + if(day > firstDayOfSemester) + currentDate = currentDate.addDays(day-firstDayOfSemester); //add the gap + else if(day < firstDayOfSemester) + currentDate = currentDate.addDays(6); //move a week nius one day + else// == + currentDate = currentDate; //just for clearaty /* * secondary loop - We have course info and starting day. @@ -180,3 +192,31 @@ QString CSV_Exporter::makeLine(QString name, QDate *date, int startH, int startM return CSV_line; } + +void CSV_Exporter::changeDayNumberFromQtToNormal(int *QtDay) +{ + switch(*QtDay){ + case 7: + *QtDay = SUNDAY; + break; + case 1: + *QtDay = MONDAY; + break; + case 2: + *QtDay = TUESDAY; + break; + case 3: + *QtDay = WENDSDAY; + break; + case 4: + *QtDay = THURSDAY; + break; + case 5: + *QtDay = FRIDAY; + break; + default: + *QtDay = 7; + break; + } + return; //Done. +} diff --git a/src/jceData/CSV/csv_exporter.h b/src/jceData/CSV/csv_exporter.h index c6c73e3..99218b7 100644 --- a/src/jceData/CSV/csv_exporter.h +++ b/src/jceData/CSV/csv_exporter.h @@ -24,6 +24,8 @@ public: private: static QString getFileFath(); static QString makeLine(QString name,QDate *date,int startH,int startM,int endH,int endM,QString lecturer,QString room,QString type); + static void changeDayNumberFromQtToNormal(int *); + enum DAYS{SUNDAY=1, MONDAY=2, TUESDAY=3, WENDSDAY=4, THURSDAY=5, FRIDAY=6}; }; #endif // CSV_EXPORTER_H