-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 | |||
@@ -1257,18 +1257,15 @@ void KOMonthView::updateView() | |||
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 |
@@ -1285,29 +1282,23 @@ void KOMonthView::updateView() | |||
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! |
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp index 8a175c9..6ee5499 100644 --- a/libkcal/recurrence.cpp +++ b/libkcal/recurrence.cpp | |||
@@ -973,13 +973,13 @@ bool Recurrence::recursSecondly(const QDate &qd, int secondFreq) const | |||
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 | ||
@@ -1185,26 +1185,25 @@ QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const | |||
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 |
@@ -1212,13 +1211,13 @@ QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const | |||
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 | } |
@@ -1269,29 +1268,27 @@ QDate Recurrence::getPreviousDateNoTime(const QDate &afterDate, bool *last) cons | |||
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: |
@@ -3397,17 +3394,8 @@ QDate Recurrence::getLastDateInYear(const QDate &latestDate) const | |||
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 | } |