author | zautrix <zautrix> | 2005-03-18 15:12:58 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-18 15:12:58 (UTC) |
commit | f9f521c487143641b2cf077d04fe1c475001bce2 (patch) (unidiff) | |
tree | 4ffac6d14ceb3e5d77f7634f2b2a49fd91a9e77a | |
parent | 66bc0202d4e2306f7029362fe09d0c7ab0e7cc36 (diff) | |
download | kdepimpi-f9f521c487143641b2cf077d04fe1c475001bce2.zip kdepimpi-f9f521c487143641b2cf077d04fe1c475001bce2.tar.gz kdepimpi-f9f521c487143641b2cf077d04fe1c475001bce2.tar.bz2 |
rec fix
-rw-r--r-- | korganizer/komonthview.cpp | 15 | ||||
-rw-r--r-- | libkcal/recurrence.cpp | 34 |
2 files changed, 14 insertions, 35 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp index cb69832..004ff50 100644 --- a/korganizer/komonthview.cpp +++ b/korganizer/komonthview.cpp | |||
@@ -1215,141 +1215,132 @@ void KOMonthView::showDates(const QDate &start, const QDate &) | |||
1215 | date = date.addDays( 7 ); | 1215 | date = date.addDays( 7 ); |
1216 | } | 1216 | } |
1217 | updateView(); | 1217 | updateView(); |
1218 | } | 1218 | } |
1219 | 1219 | ||
1220 | void KOMonthView::showEvents(QPtrList<Event>) | 1220 | void KOMonthView::showEvents(QPtrList<Event>) |
1221 | { | 1221 | { |
1222 | qDebug("KOMonthView::selectEvents is not implemented yet. "); | 1222 | qDebug("KOMonthView::selectEvents is not implemented yet. "); |
1223 | } | 1223 | } |
1224 | 1224 | ||
1225 | void KOMonthView::changeEventDisplay(Event *, int) | 1225 | void KOMonthView::changeEventDisplay(Event *, int) |
1226 | { | 1226 | { |
1227 | // this should be re-written to be much more efficient, but this | 1227 | // this should be re-written to be much more efficient, but this |
1228 | // quick-and-dirty-hack gets the job done for right now. | 1228 | // quick-and-dirty-hack gets the job done for right now. |
1229 | updateView(); | 1229 | updateView(); |
1230 | } | 1230 | } |
1231 | 1231 | ||
1232 | void KOMonthView::updateView() | 1232 | void KOMonthView::updateView() |
1233 | { | 1233 | { |
1234 | 1234 | ||
1235 | if ( !updatePossible ) | 1235 | if ( !updatePossible ) |
1236 | return; | 1236 | return; |
1237 | //QTime ti; | 1237 | //QTime ti; |
1238 | //ti.start(); | 1238 | //ti.start(); |
1239 | clearSelection(); | 1239 | clearSelection(); |
1240 | QPtrVector<MonthViewCell> *cells; | 1240 | QPtrVector<MonthViewCell> *cells; |
1241 | if ( mShowWeekView ) { | 1241 | if ( mShowWeekView ) { |
1242 | cells = &mCellsW; | 1242 | cells = &mCellsW; |
1243 | } else { | 1243 | } else { |
1244 | cells = &mCells; | 1244 | cells = &mCells; |
1245 | } | 1245 | } |
1246 | #if 1 | 1246 | #if 1 |
1247 | int i; | 1247 | int i; |
1248 | int timeSpan = (*cells).size()-1; | 1248 | int timeSpan = (*cells).size()-1; |
1249 | if ( KOPrefs::instance()->mMonthViewWeek ) | 1249 | if ( KOPrefs::instance()->mMonthViewWeek ) |
1250 | timeSpan = 6; | 1250 | timeSpan = 6; |
1251 | for( i = 0; i < timeSpan + 1; ++i ) { | 1251 | for( i = 0; i < timeSpan + 1; ++i ) { |
1252 | (*cells)[i]->startUpdateCell(); | 1252 | (*cells)[i]->startUpdateCell(); |
1253 | } | 1253 | } |
1254 | 1254 | ||
1255 | QPtrList<Event> events = calendar()->events(); | 1255 | QPtrList<Event> events = calendar()->events(); |
1256 | Event *event; | 1256 | Event *event; |
1257 | QDateTime dt; | 1257 | QDateTime dt; |
1258 | bool ok; | 1258 | bool ok; |
1259 | QDate endDate = mStartDate.addDays( timeSpan ); | 1259 | QDate endDate = mStartDate.addDays( timeSpan ); |
1260 | for( event = events.first(); event; event = events.next() ) { // for event | 1260 | for( event = events.first(); event; event = events.next() ) { // for event |
1261 | if ( event->doesRecur() ) { | 1261 | if ( event->doesRecur() ) { |
1262 | bool last; | 1262 | bool last; |
1263 | qDebug("********************************************** "); | ||
1264 | qDebug("Event summary: %s ", event->summary().latin1()); | ||
1265 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); | 1263 | QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); |
1266 | QDateTime incidenceEnd; | 1264 | QDateTime incidenceEnd; |
1267 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); | 1265 | int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); |
1268 | qDebug("eventlen %d ", eventlen); | ||
1269 | bool invalid = false; | 1266 | bool invalid = false; |
1270 | while( true ) { | 1267 | while( true ) { |
1271 | if ( incidenceStart.isValid() ) { | 1268 | if ( incidenceStart.isValid() ) { |
1272 | incidenceEnd = incidenceStart.addDays( eventlen ); | 1269 | incidenceEnd = incidenceStart.addDays( eventlen ); |
1273 | int st = incidenceStart.date().daysTo( endDate ); | 1270 | int st = incidenceStart.date().daysTo( endDate ); |
1274 | if ( st >= 0 ) { // start before timeend | 1271 | if ( st >= 0 ) { // start before timeend |
1275 | int end = mStartDate.daysTo( incidenceEnd.date() ); | 1272 | int end = mStartDate.daysTo( incidenceEnd.date() ); |
1276 | if ( end >= 0 ) { // end after timestart --- got one! | 1273 | if ( end >= 0 ) { // end after timestart --- got one! |
1277 | //normalize | 1274 | //normalize |
1278 | st = timeSpan - st; | 1275 | st = timeSpan - st; |
1279 | if ( st < 0 ) st = 0; | 1276 | if ( st < 0 ) st = 0; |
1280 | if ( end > timeSpan ) end = timeSpan; | 1277 | if ( end > timeSpan ) end = timeSpan; |
1281 | int iii; | 1278 | int iii; |
1282 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); | 1279 | //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); |
1283 | for ( iii = st;iii<= end;++iii) | 1280 | for ( iii = st;iii<= end;++iii) |
1284 | (*cells)[iii]->insertEvent( event ); | 1281 | (*cells)[iii]->insertEvent( event ); |
1285 | } | 1282 | } |
1286 | } | 1283 | } |
1287 | } else { | 1284 | } else { |
1288 | if ( invalid ) | 1285 | if ( invalid ) |
1289 | break; | 1286 | break; |
1290 | invalid = true; | 1287 | invalid = true; |
1291 | qDebug("invalid %s", event->summary().latin1()); | 1288 | //qDebug("invalid %s", event->summary().latin1()); |
1292 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; | 1289 | incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; |
1293 | } | 1290 | } |
1294 | if ( last ) | 1291 | if ( last ) |
1295 | break; | 1292 | break; |
1296 | bool ok; | 1293 | bool ok; |
1297 | qDebug("TRY next occurence %s ", incidenceStart.toString().latin1()); | ||
1298 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); | 1294 | incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); |
1299 | if ( ! ok ) { | 1295 | if ( ! ok ) |
1300 | qDebug("NOT OK "); | ||
1301 | break; | 1296 | break; |
1302 | } | 1297 | if ( incidenceStart.date() > endDate ) |
1303 | if ( incidenceStart.date() > endDate ) { | ||
1304 | qDebug("incidenceStart.date() > endDate "); | ||
1305 | break; | 1298 | break; |
1306 | } | ||
1307 | qDebug("next occurence %s ", incidenceStart.toString().latin1()); | ||
1308 | } | 1299 | } |
1309 | } else { // no recur | 1300 | } else { // no recur |
1310 | int st = event->dtStart().date().daysTo( endDate ); | 1301 | int st = event->dtStart().date().daysTo( endDate ); |
1311 | if ( st >= 0 ) { // start before timeend | 1302 | if ( st >= 0 ) { // start before timeend |
1312 | int end = mStartDate.daysTo( event->dtEnd().date() ); | 1303 | int end = mStartDate.daysTo( event->dtEnd().date() ); |
1313 | if ( end >= 0 ) { // end after timestart --- got one! | 1304 | if ( end >= 0 ) { // end after timestart --- got one! |
1314 | //normalize | 1305 | //normalize |
1315 | st = timeSpan - st; | 1306 | st = timeSpan - st; |
1316 | if ( st < 0 ) st = 0; | 1307 | if ( st < 0 ) st = 0; |
1317 | if ( end > timeSpan ) end = timeSpan; | 1308 | if ( end > timeSpan ) end = timeSpan; |
1318 | int iii; | 1309 | int iii; |
1319 | for ( iii = st;iii<= end;++iii) | 1310 | for ( iii = st;iii<= end;++iii) |
1320 | (*cells)[iii]->insertEvent( event ); | 1311 | (*cells)[iii]->insertEvent( event ); |
1321 | } | 1312 | } |
1322 | } | 1313 | } |
1323 | } | 1314 | } |
1324 | } | 1315 | } |
1325 | // insert due todos | 1316 | // insert due todos |
1326 | QPtrList<Todo> todos = calendar()->todos( ); | 1317 | QPtrList<Todo> todos = calendar()->todos( ); |
1327 | Todo *todo; | 1318 | Todo *todo; |
1328 | for(todo = todos.first(); todo; todo = todos.next()) { | 1319 | for(todo = todos.first(); todo; todo = todos.next()) { |
1329 | //insertTodo( todo ); | 1320 | //insertTodo( todo ); |
1330 | if ( todo->hasDueDate() ) { | 1321 | if ( todo->hasDueDate() ) { |
1331 | int day = mStartDate.daysTo( todo->dtDue().date() ); | 1322 | int day = mStartDate.daysTo( todo->dtDue().date() ); |
1332 | if ( day >= 0 && day < timeSpan + 1) { | 1323 | if ( day >= 0 && day < timeSpan + 1) { |
1333 | (*cells)[day]->insertTodo( todo ); | 1324 | (*cells)[day]->insertTodo( todo ); |
1334 | } | 1325 | } |
1335 | } | 1326 | } |
1336 | } | 1327 | } |
1337 | 1328 | ||
1338 | for( i = 0; i < timeSpan+1; ++i ) { | 1329 | for( i = 0; i < timeSpan+1; ++i ) { |
1339 | (*cells)[i]->finishUpdateCell(); | 1330 | (*cells)[i]->finishUpdateCell(); |
1340 | } | 1331 | } |
1341 | processSelectionChange(); | 1332 | processSelectionChange(); |
1342 | (*cells)[0]->setFocus(); | 1333 | (*cells)[0]->setFocus(); |
1343 | 1334 | ||
1344 | 1335 | ||
1345 | #else | 1336 | #else |
1346 | // old code | 1337 | // old code |
1347 | //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); | 1338 | //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); |
1348 | int i; | 1339 | int i; |
1349 | for( i = 0; i < (*cells).count(); ++i ) { | 1340 | for( i = 0; i < (*cells).count(); ++i ) { |
1350 | (*cells)[i]->updateCell(); | 1341 | (*cells)[i]->updateCell(); |
1351 | } | 1342 | } |
1352 | 1343 | ||
1353 | //qDebug("KOMonthView::updateView() "); | 1344 | //qDebug("KOMonthView::updateView() "); |
1354 | processSelectionChange(); | 1345 | processSelectionChange(); |
1355 | // qDebug("---------------------------------------------------------------------+ "); | 1346 | // qDebug("---------------------------------------------------------------------+ "); |
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp index 8a175c9..6ee5499 100644 --- a/libkcal/recurrence.cpp +++ b/libkcal/recurrence.cpp | |||
@@ -931,97 +931,97 @@ QDateTime Recurrence::getPreviousDateTime(const QDateTime &afterDateTime, bool * | |||
931 | count = rDuration; | 931 | count = rDuration; |
932 | if (last && count == rDuration) | 932 | if (last && count == rDuration) |
933 | *last = true; | 933 | *last = true; |
934 | } | 934 | } |
935 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); | 935 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); |
936 | if (rDuration == 0) { | 936 | if (rDuration == 0) { |
937 | if (endtime > rEndDateTime) | 937 | if (endtime > rEndDateTime) |
938 | endtime = rEndDateTime; | 938 | endtime = rEndDateTime; |
939 | if (last && endtime == rEndDateTime) | 939 | if (last && endtime == rEndDateTime) |
940 | *last = true; | 940 | *last = true; |
941 | } | 941 | } |
942 | return endtime; | 942 | return endtime; |
943 | } | 943 | } |
944 | 944 | ||
945 | QDate Recurrence::getPreviousDate(const QDate &afterDate, bool *last) const | 945 | QDate Recurrence::getPreviousDate(const QDate &afterDate, bool *last) const |
946 | { | 946 | { |
947 | if (last) | 947 | if (last) |
948 | *last = false; | 948 | *last = false; |
949 | switch (recurs) | 949 | switch (recurs) |
950 | { | 950 | { |
951 | case rMinutely: | 951 | case rMinutely: |
952 | case rHourly: | 952 | case rHourly: |
953 | return getPreviousDateTime(QDateTime(afterDate, QTime(0,0,0)), last).date(); | 953 | return getPreviousDateTime(QDateTime(afterDate, QTime(0,0,0)), last).date(); |
954 | case rDaily: | 954 | case rDaily: |
955 | case rWeekly: | 955 | case rWeekly: |
956 | case rMonthlyPos: | 956 | case rMonthlyPos: |
957 | case rMonthlyDay: | 957 | case rMonthlyDay: |
958 | case rYearlyMonth: | 958 | case rYearlyMonth: |
959 | case rYearlyDay: | 959 | case rYearlyDay: |
960 | case rYearlyPos: | 960 | case rYearlyPos: |
961 | return getPreviousDateNoTime(afterDate, last); | 961 | return getPreviousDateNoTime(afterDate, last); |
962 | default: | 962 | default: |
963 | return QDate(); | 963 | return QDate(); |
964 | } | 964 | } |
965 | } | 965 | } |
966 | 966 | ||
967 | 967 | ||
968 | /***************************** PROTECTED FUNCTIONS ***************************/ | 968 | /***************************** PROTECTED FUNCTIONS ***************************/ |
969 | 969 | ||
970 | bool Recurrence::recursSecondly(const QDate &qd, int secondFreq) const | 970 | bool Recurrence::recursSecondly(const QDate &qd, int secondFreq) const |
971 | { | 971 | { |
972 | if ((qd >= mRecurStart.date()) && | 972 | if ((qd >= mRecurStart.date()) && |
973 | ((rDuration > 0) && (qd <= endDate()) || | 973 | ((rDuration > 0) && (qd <= endDate()) || |
974 | ((rDuration == 0) && (qd <= rEndDateTime.date())) || | 974 | ((rDuration == 0) && (qd <= rEndDateTime.date())) || |
975 | (rDuration == -1))) { | 975 | (rDuration == -1))) { |
976 | // The date queried falls within the range of the event. | 976 | // The date queried falls within the range of the event. |
977 | if (secondFreq < 24*3600) | 977 | if (secondFreq < 24*3600) |
978 | return true; // the event recurs at least once each day | 978 | return true; // the event recurs at least once each day |
979 | int after = mRecurStart.secsTo(QDateTime(qd)); | 979 | int after = mRecurStart.secsTo(QDateTime(qd)) - 1; |
980 | if (after / secondFreq != (after + 24*3600) / secondFreq) | 980 | if (after / secondFreq != (after + 24*3600) / secondFreq) |
981 | return true; | 981 | return true; |
982 | } | 982 | } |
983 | return false; | 983 | return false; |
984 | } | 984 | } |
985 | 985 | ||
986 | bool Recurrence::recursMinutelyAt(const QDateTime &dt, int minuteFreq) const | 986 | bool Recurrence::recursMinutelyAt(const QDateTime &dt, int minuteFreq) const |
987 | { | 987 | { |
988 | if ((dt >= mRecurStart) && | 988 | if ((dt >= mRecurStart) && |
989 | ((rDuration > 0) && (dt <= endDateTime()) || | 989 | ((rDuration > 0) && (dt <= endDateTime()) || |
990 | ((rDuration == 0) && (dt <= rEndDateTime)) || | 990 | ((rDuration == 0) && (dt <= rEndDateTime)) || |
991 | (rDuration == -1))) { | 991 | (rDuration == -1))) { |
992 | // The time queried falls within the range of the event. | 992 | // The time queried falls within the range of the event. |
993 | if (((mRecurStart.secsTo(dt) / 60) % minuteFreq) == 0) | 993 | if (((mRecurStart.secsTo(dt) / 60) % minuteFreq) == 0) |
994 | return true; | 994 | return true; |
995 | } | 995 | } |
996 | return false; | 996 | return false; |
997 | } | 997 | } |
998 | 998 | ||
999 | bool Recurrence::recursDaily(const QDate &qd) const | 999 | bool Recurrence::recursDaily(const QDate &qd) const |
1000 | { | 1000 | { |
1001 | QDate dStart = mRecurStart.date(); | 1001 | QDate dStart = mRecurStart.date(); |
1002 | if ((dStart.daysTo(qd) % rFreq) == 0) { | 1002 | if ((dStart.daysTo(qd) % rFreq) == 0) { |
1003 | // The date is a day which recurs | 1003 | // The date is a day which recurs |
1004 | if (qd >= dStart | 1004 | if (qd >= dStart |
1005 | && ((rDuration > 0 && qd <= endDate()) || | 1005 | && ((rDuration > 0 && qd <= endDate()) || |
1006 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1006 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1007 | rDuration == -1)) { | 1007 | rDuration == -1)) { |
1008 | // The date queried falls within the range of the event. | 1008 | // The date queried falls within the range of the event. |
1009 | return true; | 1009 | return true; |
1010 | } | 1010 | } |
1011 | } | 1011 | } |
1012 | return false; | 1012 | return false; |
1013 | } | 1013 | } |
1014 | 1014 | ||
1015 | bool Recurrence::recursWeekly(const QDate &qd) const | 1015 | bool Recurrence::recursWeekly(const QDate &qd) const |
1016 | { | 1016 | { |
1017 | QDate dStart = mRecurStart.date(); | 1017 | QDate dStart = mRecurStart.date(); |
1018 | if ((dStart.daysTo(qd)/7) % rFreq == 0) { | 1018 | if ((dStart.daysTo(qd)/7) % rFreq == 0) { |
1019 | // The date is in a week which recurs | 1019 | // The date is in a week which recurs |
1020 | if (qd >= dStart | 1020 | if (qd >= dStart |
1021 | && ((rDuration > 0 && qd <= endDate()) || | 1021 | && ((rDuration > 0 && qd <= endDate()) || |
1022 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1022 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1023 | rDuration == -1)) { | 1023 | rDuration == -1)) { |
1024 | // The date queried falls within the range of the event. | 1024 | // The date queried falls within the range of the event. |
1025 | // check if the bits set match today. | 1025 | // check if the bits set match today. |
1026 | int i = qd.dayOfWeek()-1; | 1026 | int i = qd.dayOfWeek()-1; |
1027 | if (rDays.testBit((uint) i)) | 1027 | if (rDays.testBit((uint) i)) |
@@ -1143,197 +1143,194 @@ bool Recurrence::recursYearlyByPos(const QDate &qd) const | |||
1143 | return false; | 1143 | return false; |
1144 | } | 1144 | } |
1145 | 1145 | ||
1146 | bool Recurrence::recursYearlyByDay(const QDate &qd) const | 1146 | bool Recurrence::recursYearlyByDay(const QDate &qd) const |
1147 | { | 1147 | { |
1148 | QDate dStart = mRecurStart.date(); | 1148 | QDate dStart = mRecurStart.date(); |
1149 | // calculate how many years ahead this date is from the original | 1149 | // calculate how many years ahead this date is from the original |
1150 | // event's date | 1150 | // event's date |
1151 | int yearsAhead = (qd.year() - dStart.year()); | 1151 | int yearsAhead = (qd.year() - dStart.year()); |
1152 | if (yearsAhead % rFreq == 0) { | 1152 | if (yearsAhead % rFreq == 0) { |
1153 | // The date is in a year which recurs | 1153 | // The date is in a year which recurs |
1154 | if (qd >= dStart | 1154 | if (qd >= dStart |
1155 | && ((rDuration > 0 && qd <= endDate()) || | 1155 | && ((rDuration > 0 && qd <= endDate()) || |
1156 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1156 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1157 | rDuration == -1)) { | 1157 | rDuration == -1)) { |
1158 | // The date queried falls within the range of the event. | 1158 | // The date queried falls within the range of the event. |
1159 | int i = qd.dayOfYear(); | 1159 | int i = qd.dayOfYear(); |
1160 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1160 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1161 | if (i == *qlin.current()) | 1161 | if (i == *qlin.current()) |
1162 | return true; | 1162 | return true; |
1163 | } | 1163 | } |
1164 | } | 1164 | } |
1165 | } | 1165 | } |
1166 | return false; | 1166 | return false; |
1167 | } | 1167 | } |
1168 | 1168 | ||
1169 | /* Get the date of the next recurrence, after the specified date. | 1169 | /* Get the date of the next recurrence, after the specified date. |
1170 | * If 'last' is non-null, '*last' is set to true if the next recurrence is the | 1170 | * If 'last' is non-null, '*last' is set to true if the next recurrence is the |
1171 | * last recurrence, else false. | 1171 | * last recurrence, else false. |
1172 | * Reply = date of next recurrence, or invalid date if none. | 1172 | * Reply = date of next recurrence, or invalid date if none. |
1173 | */ | 1173 | */ |
1174 | QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const | 1174 | QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const |
1175 | { | 1175 | { |
1176 | 1176 | ||
1177 | if (last) | 1177 | if (last) |
1178 | *last = false; | 1178 | *last = false; |
1179 | QDate dStart = mRecurStart.date(); | 1179 | QDate dStart = mRecurStart.date(); |
1180 | if (preDate < dStart) | 1180 | if (preDate < dStart) |
1181 | return dStart; | 1181 | return dStart; |
1182 | QDate earliestDate = preDate.addDays(1); | 1182 | QDate earliestDate = preDate.addDays(1); |
1183 | QDate nextDate; | 1183 | QDate nextDate; |
1184 | 1184 | ||
1185 | switch (recurs) { | 1185 | switch (recurs) { |
1186 | case rDaily: | 1186 | case rDaily: |
1187 | nextDate = dStart.addDays((dStart.daysTo(preDate)/rFreq + 1) * rFreq); | 1187 | nextDate = dStart.addDays((dStart.daysTo(preDate)/rFreq + 1) * rFreq); |
1188 | break; | 1188 | break; |
1189 | 1189 | ||
1190 | case rWeekly: { | 1190 | case rWeekly: { |
1191 | QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart | 1191 | QDate start = dStart.addDays(-((dStart.dayOfWeek() - rWeekStart + 7)%7)); // start of week for dStart |
1192 | int earliestDayOfWeek = earliestDate.dayOfWeek(); | 1192 | int earliestDayOfWeek = earliestDate.dayOfWeek(); |
1193 | int weeksAhead = start.daysTo(earliestDate) / 7; | 1193 | int weeksAhead = start.daysTo(earliestDate) / 7; |
1194 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week | 1194 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week |
1195 | weeksAhead -= notThisWeek; // latest week which recurred | 1195 | weeksAhead -= notThisWeek; // latest week which recurred |
1196 | int weekday = 0; | 1196 | int weekday = 0; |
1197 | // First check for any remaining day this week, if this week is a recurring week | 1197 | // First check for any remaining day this week, if this week is a recurring week |
1198 | if (!notThisWeek) | 1198 | if (!notThisWeek) |
1199 | weekday = getFirstDayInWeek(earliestDayOfWeek); | 1199 | weekday = getFirstDayInWeek(earliestDayOfWeek); |
1200 | // Check for a day in the next scheduled week | 1200 | // Check for a day in the next scheduled week |
1201 | if (!weekday && earliestDayOfWeek > 1) | 1201 | if (!weekday ) |
1202 | weekday = getFirstDayInWeek(rWeekStart) + rFreq*7; | 1202 | weekday = getFirstDayInWeek(rWeekStart) + rFreq*7; |
1203 | if (weekday) | 1203 | nextDate = start.addDays(weeksAhead*7 + weekday - 1); |
1204 | nextDate = start.addDays(weeksAhead*7 + weekday - 1); | ||
1205 | break; | 1204 | break; |
1206 | } | 1205 | } |
1207 | case rMonthlyDay: | 1206 | case rMonthlyDay: |
1208 | case rMonthlyPos: { | 1207 | case rMonthlyPos: { |
1209 | int startYear = dStart.year(); | 1208 | int startYear = dStart.year(); |
1210 | int startMonth = dStart.month(); // 1..12 | 1209 | int startMonth = dStart.month(); // 1..12 |
1211 | int earliestYear = earliestDate.year(); | 1210 | int earliestYear = earliestDate.year(); |
1212 | int monthsAhead = (earliestYear - startYear)*12 + earliestDate.month() - startMonth; | 1211 | int monthsAhead = (earliestYear - startYear)*12 + earliestDate.month() - startMonth; |
1213 | int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month | 1212 | int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month |
1214 | monthsAhead -= notThisMonth; // latest month which recurred | 1213 | monthsAhead -= notThisMonth; // latest month which recurred |
1215 | // Check for the first later day in the current month | 1214 | // Check for the first later day in the current month |
1216 | if (!notThisMonth) | 1215 | if (!notThisMonth) |
1217 | nextDate = getFirstDateInMonth(earliestDate); | 1216 | nextDate = getFirstDateInMonth(earliestDate); |
1218 | if (!nextDate.isValid() && earliestDate.day() > 1) { | 1217 | if (!nextDate.isValid() ) { |
1219 | // Check for a day in the next scheduled month | 1218 | // Check for a day in the next scheduled month |
1220 | int months = startMonth - 1 + monthsAhead + rFreq; | 1219 | int months = startMonth - 1 + monthsAhead + rFreq; |
1221 | nextDate = getFirstDateInMonth(QDate(startYear + months/12, months%12 + 1, 1)); | 1220 | nextDate = getFirstDateInMonth(QDate(startYear + months/12, months%12 + 1, 1)); |
1222 | } | 1221 | } |
1223 | break; | 1222 | break; |
1224 | } | 1223 | } |
1225 | case rYearlyMonth: | 1224 | case rYearlyMonth: |
1226 | case rYearlyPos: | 1225 | case rYearlyPos: |
1227 | case rYearlyDay: { | 1226 | case rYearlyDay: { |
1228 | int startYear = dStart.year(); | 1227 | int startYear = dStart.year(); |
1229 | int yearsAhead = earliestDate.year() - startYear; | 1228 | int yearsAhead = earliestDate.year() - startYear; |
1230 | int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year | 1229 | int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year |
1231 | yearsAhead -= notThisYear; // latest year which recurred | 1230 | yearsAhead -= notThisYear; // latest year which recurred |
1232 | // Check for the first later date in the current year | 1231 | // Check for the first later date in the current year |
1233 | if (!notThisYear) | 1232 | if (!notThisYear) |
1234 | nextDate = getFirstDateInYear(earliestDate); | 1233 | nextDate = getFirstDateInYear(earliestDate); |
1235 | // Check for a date in the next scheduled year | 1234 | // Check for a date in the next scheduled year |
1236 | if (!nextDate.isValid() && earliestDate.dayOfYear() > 1) | 1235 | if (!nextDate.isValid() && earliestDate.dayOfYear() > 1) |
1237 | nextDate = getFirstDateInYear(QDate(startYear + yearsAhead + rFreq, 1, 1)); | 1236 | nextDate = getFirstDateInYear(QDate(startYear + yearsAhead + rFreq, 1, 1)); |
1238 | break; | 1237 | break; |
1239 | } | 1238 | } |
1240 | case rNone: | 1239 | case rNone: |
1241 | default: | 1240 | default: |
1242 | return QDate(); | 1241 | return QDate(); |
1243 | } | 1242 | } |
1244 | 1243 | ||
1245 | if (rDuration >= 0 && nextDate.isValid()) { | 1244 | if (rDuration >= 0 && nextDate.isValid()) { |
1246 | // Check that the date found is within the range of the recurrence | 1245 | // Check that the date found is within the range of the recurrence |
1247 | QDate end = endDate(); | 1246 | QDate end = endDate(); |
1248 | if (nextDate > end) | 1247 | if (nextDate > end) |
1249 | return QDate(); | 1248 | return QDate(); |
1250 | if (last && nextDate == end) | 1249 | if (last && nextDate == end) |
1251 | *last = true; | 1250 | *last = true; |
1252 | } | 1251 | } |
1253 | return nextDate; | 1252 | return nextDate; |
1254 | } | 1253 | } |
1255 | 1254 | ||
1256 | /* Get the date of the last previous recurrence, before the specified date. | 1255 | /* Get the date of the last previous recurrence, before the specified date. |
1257 | * Reply = date of previous recurrence, or invalid date if none. | 1256 | * Reply = date of previous recurrence, or invalid date if none. |
1258 | */ | 1257 | */ |
1259 | QDate Recurrence::getPreviousDateNoTime(const QDate &afterDate, bool *last) const | 1258 | QDate Recurrence::getPreviousDateNoTime(const QDate &afterDate, bool *last) const |
1260 | { | 1259 | { |
1261 | if (last) | 1260 | if (last) |
1262 | *last = false; | 1261 | *last = false; |
1263 | QDate dStart = mRecurStart.date(); | 1262 | QDate dStart = mRecurStart.date(); |
1264 | QDate latestDate = afterDate.addDays(-1); | 1263 | QDate latestDate = afterDate.addDays(-1); |
1265 | if (latestDate < dStart) | 1264 | if (latestDate < dStart) |
1266 | return QDate(); | 1265 | return QDate(); |
1267 | QDate prevDate; | 1266 | QDate prevDate; |
1268 | 1267 | ||
1269 | switch (recurs) { | 1268 | switch (recurs) { |
1270 | case rDaily: | 1269 | case rDaily: |
1271 | prevDate = dStart.addDays((dStart.daysTo(latestDate) / rFreq) * rFreq); | 1270 | prevDate = dStart.addDays((dStart.daysTo(latestDate) / rFreq) * rFreq); |
1272 | break; | 1271 | break; |
1273 | 1272 | ||
1274 | case rWeekly: { | 1273 | case rWeekly: { |
1275 | QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart | 1274 | QDate start = dStart.addDays(-((dStart.dayOfWeek() - rWeekStart + 7)%7)); // start of week for dStart |
1276 | int latestDayOfWeek = latestDate.dayOfWeek(); | 1275 | int latestDayOfWeek = latestDate.dayOfWeek(); |
1277 | int weeksAhead = start.daysTo(latestDate) / 7; | 1276 | int weeksAhead = start.daysTo(latestDate) / 7; |
1278 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week | 1277 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week |
1279 | weeksAhead -= notThisWeek; // latest week which recurred | 1278 | weeksAhead -= notThisWeek; // latest week which recurred |
1280 | int weekday = 0; | 1279 | int weekday = 0; |
1281 | // First check for any previous day this week, if this week is a recurring week | 1280 | // First check for any previous day this week, if this week is a recurring week |
1282 | if (!notThisWeek) | 1281 | if (!notThisWeek) |
1283 | weekday = getLastDayInWeek(latestDayOfWeek); | 1282 | weekday = getLastDayInWeek(latestDayOfWeek); |
1284 | // Check for a day in the previous scheduled week | 1283 | // Check for a day in the previous scheduled week |
1285 | if (!weekday) { | 1284 | if (!weekday) { |
1285 | if (!notThisWeek) | ||
1286 | weeksAhead -= rFreq; | ||
1286 | int weekEnd = (rWeekStart + 5)%7 + 1; | 1287 | int weekEnd = (rWeekStart + 5)%7 + 1; |
1287 | if (latestDayOfWeek < weekEnd) { | 1288 | weekday = getLastDayInWeek(weekEnd); |
1288 | if (!notThisWeek) | ||
1289 | weeksAhead -= rFreq; | ||
1290 | weekday = getLastDayInWeek(weekEnd); | ||
1291 | } | ||
1292 | } | 1289 | } |
1293 | if (weekday) | 1290 | if (weekday) |
1294 | prevDate = start.addDays(weeksAhead*7 + weekday - 1); | 1291 | prevDate = start.addDays(weeksAhead*7 + weekday - 1); |
1295 | break; | 1292 | break; |
1296 | } | 1293 | } |
1297 | case rMonthlyDay: | 1294 | case rMonthlyDay: |
1298 | case rMonthlyPos: { | 1295 | case rMonthlyPos: { |
1299 | int startYear = dStart.year(); | 1296 | int startYear = dStart.year(); |
1300 | int startMonth = dStart.month(); // 1..12 | 1297 | int startMonth = dStart.month(); // 1..12 |
1301 | int latestYear = latestDate.year(); | 1298 | int latestYear = latestDate.year(); |
1302 | int monthsAhead = (latestYear - startYear)*12 + latestDate.month() - startMonth; | 1299 | int monthsAhead = (latestYear - startYear)*12 + latestDate.month() - startMonth; |
1303 | int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month | 1300 | int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month |
1304 | monthsAhead -= notThisMonth; // latest month which recurred | 1301 | monthsAhead -= notThisMonth; // latest month which recurred |
1305 | // Check for the last earlier day in the current month | 1302 | // Check for the last earlier day in the current month |
1306 | if (!notThisMonth) | 1303 | if (!notThisMonth) |
1307 | prevDate = getLastDateInMonth(latestDate); | 1304 | prevDate = getLastDateInMonth(latestDate); |
1308 | if (!prevDate.isValid() && latestDate.day() < latestDate.daysInMonth()) { | 1305 | if (!prevDate.isValid() && latestDate.day() < latestDate.daysInMonth()) { |
1309 | // Check for a day in the previous scheduled month | 1306 | // Check for a day in the previous scheduled month |
1310 | if (!notThisMonth) | 1307 | if (!notThisMonth) |
1311 | monthsAhead -= rFreq; | 1308 | monthsAhead -= rFreq; |
1312 | int months = startMonth + monthsAhead; // get the month after the one that recurs | 1309 | int months = startMonth + monthsAhead; // get the month after the one that recurs |
1313 | prevDate = getLastDateInMonth(QDate(startYear + months/12, months%12 + 1, 1).addDays(-1)); | 1310 | prevDate = getLastDateInMonth(QDate(startYear + months/12, months%12 + 1, 1).addDays(-1)); |
1314 | } | 1311 | } |
1315 | break; | 1312 | break; |
1316 | } | 1313 | } |
1317 | case rYearlyMonth: | 1314 | case rYearlyMonth: |
1318 | case rYearlyPos: | 1315 | case rYearlyPos: |
1319 | case rYearlyDay: { | 1316 | case rYearlyDay: { |
1320 | int startYear = dStart.year(); | 1317 | int startYear = dStart.year(); |
1321 | int yearsAhead = latestDate.year() - startYear; | 1318 | int yearsAhead = latestDate.year() - startYear; |
1322 | int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year | 1319 | int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year |
1323 | yearsAhead -= notThisYear; // latest year which recurred | 1320 | yearsAhead -= notThisYear; // latest year which recurred |
1324 | // Check for the first later date in the current year | 1321 | // Check for the first later date in the current year |
1325 | if (!notThisYear) | 1322 | if (!notThisYear) |
1326 | prevDate = getLastDateInYear(latestDate); | 1323 | prevDate = getLastDateInYear(latestDate); |
1327 | if (!prevDate.isValid() && latestDate.dayOfYear() < latestDate.daysInYear()) { | 1324 | if (!prevDate.isValid() && latestDate.dayOfYear() < latestDate.daysInYear()) { |
1328 | // Check for a date in the next scheduled year | 1325 | // Check for a date in the next scheduled year |
1329 | if (!notThisYear) | 1326 | if (!notThisYear) |
1330 | yearsAhead -= rFreq; | 1327 | yearsAhead -= rFreq; |
1331 | prevDate = getLastDateInYear(QDate(startYear + yearsAhead, 12, 31)); | 1328 | prevDate = getLastDateInYear(QDate(startYear + yearsAhead, 12, 31)); |
1332 | } | 1329 | } |
1333 | break; | 1330 | break; |
1334 | } | 1331 | } |
1335 | case rNone: | 1332 | case rNone: |
1336 | default: | 1333 | default: |
1337 | return QDate(); | 1334 | return QDate(); |
1338 | } | 1335 | } |
1339 | 1336 | ||
@@ -3355,59 +3352,50 @@ QDate Recurrence::getLastDateInYear(const QDate &latestDate) const | |||
3355 | case rMar1: | 3352 | case rMar1: |
3356 | if (latestMonth >= 3) | 3353 | if (latestMonth >= 3) |
3357 | return QDate(latestYear, 3, 1); | 3354 | return QDate(latestYear, 3, 1); |
3358 | break; | 3355 | break; |
3359 | case rFeb28: | 3356 | case rFeb28: |
3360 | return QDate(latestYear, 2, 28); | 3357 | return QDate(latestYear, 2, 28); |
3361 | case rFeb29: | 3358 | case rFeb29: |
3362 | break; | 3359 | break; |
3363 | } | 3360 | } |
3364 | } | 3361 | } |
3365 | } | 3362 | } |
3366 | } | 3363 | } |
3367 | break; | 3364 | break; |
3368 | } | 3365 | } |
3369 | case rYearlyPos: { | 3366 | case rYearlyPos: { |
3370 | QValueList<int> dayList; | 3367 | QValueList<int> dayList; |
3371 | int latestYear = latestDate.year(); | 3368 | int latestYear = latestDate.year(); |
3372 | int latestMonth = latestDate.month(); | 3369 | int latestMonth = latestDate.month(); |
3373 | int latestDay = latestDate.day(); | 3370 | int latestDay = latestDate.day(); |
3374 | for (it.toLast(); it.current(); --it) { | 3371 | for (it.toLast(); it.current(); --it) { |
3375 | int month = *it.current(); | 3372 | int month = *it.current(); |
3376 | if (month <= latestMonth) { | 3373 | if (month <= latestMonth) { |
3377 | QDate monthBegin(latestYear, month, 1); | 3374 | QDate monthBegin(latestYear, month, 1); |
3378 | getMonthlyPosDays(dayList, monthBegin.daysInMonth(), monthBegin.dayOfWeek()); | 3375 | getMonthlyPosDays(dayList, monthBegin.daysInMonth(), monthBegin.dayOfWeek()); |
3379 | for (QValueList<int>::ConstIterator id = dayList.fromLast(); id != dayList.end(); --id) { | 3376 | for (QValueList<int>::ConstIterator id = dayList.fromLast(); id != dayList.end(); --id) { |
3380 | if (*id <= latestDay) | 3377 | if (*id <= latestDay) |
3381 | return monthBegin.addDays(*id - 1); | 3378 | return monthBegin.addDays(*id - 1); |
3382 | } | 3379 | } |
3383 | latestDay = 31; | 3380 | latestDay = 31; |
3384 | } | 3381 | } |
3385 | } | 3382 | } |
3386 | break; | 3383 | break; |
3387 | } | 3384 | } |
3388 | case rYearlyDay: { | 3385 | case rYearlyDay: { |
3389 | int latestDay = latestDate.dayOfYear(); | 3386 | int latestDay = latestDate.dayOfYear(); |
3390 | for (it.toLast(); it.current(); --it) { | 3387 | for (it.toLast(); it.current(); --it) { |
3391 | int day = *it.current(); | 3388 | int day = *it.current(); |
3392 | if (day <= latestDay) | 3389 | if (day <= latestDay) |
3393 | return latestDate.addDays(day - latestDay); | 3390 | return latestDate.addDays(day - latestDay); |
3394 | } | 3391 | } |
3395 | break; | 3392 | break; |
3396 | } | 3393 | } |
3397 | } | 3394 | } |
3398 | return QDate(); | 3395 | return QDate(); |
3399 | } | 3396 | } |
3400 | 3397 | ||
3401 | void Recurrence::dump() const | 3398 | void Recurrence::dump() const |
3402 | { | 3399 | { |
3403 | kdDebug() << "Recurrence::dump():" << endl; | 3400 | ; |
3404 | |||
3405 | kdDebug() << " type: " << recurs << endl; | ||
3406 | |||
3407 | kdDebug() << " rDays: " << endl; | ||
3408 | int i; | ||
3409 | for( i = 0; i < 7; ++i ) { | ||
3410 | kdDebug() << " " << i << ": " | ||
3411 | << ( rDays.testBit( i ) ? "true" : "false" ) << endl; | ||
3412 | } | ||
3413 | } | 3401 | } |