-rw-r--r-- | libkcal/recurrence.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp index e84f672..5181eaf 100644 --- a/libkcal/recurrence.cpp +++ b/libkcal/recurrence.cpp | |||
@@ -834,96 +834,97 @@ QDateTime Recurrence::getNextDateTime(const QDateTime &preDateTime, bool *last) | |||
834 | case rYearlyMonth: | 834 | case rYearlyMonth: |
835 | case rYearlyDay: | 835 | case rYearlyDay: |
836 | case rYearlyPos: { | 836 | case rYearlyPos: { |
837 | QDate preDate = preDateTime.date(); | 837 | QDate preDate = preDateTime.date(); |
838 | if (!mFloats && mRecurStart.time() > preDateTime.time()) | 838 | if (!mFloats && mRecurStart.time() > preDateTime.time()) |
839 | preDate = preDate.addDays(-1); | 839 | preDate = preDate.addDays(-1); |
840 | return QDateTime(getNextDateNoTime(preDate, last), mRecurStart.time()); | 840 | return QDateTime(getNextDateNoTime(preDate, last), mRecurStart.time()); |
841 | } | 841 | } |
842 | default: | 842 | default: |
843 | return QDateTime(); | 843 | return QDateTime(); |
844 | } | 844 | } |
845 | 845 | ||
846 | // It's a sub-daily recurrence | 846 | // It's a sub-daily recurrence |
847 | if (preDateTime < mRecurStart) | 847 | if (preDateTime < mRecurStart) |
848 | return mRecurStart; | 848 | return mRecurStart; |
849 | int count = mRecurStart.secsTo(preDateTime) / freq + 2; | 849 | int count = mRecurStart.secsTo(preDateTime) / freq + 2; |
850 | if (rDuration > 0) { | 850 | if (rDuration > 0) { |
851 | if (count > rDuration) | 851 | if (count > rDuration) |
852 | return QDateTime(); | 852 | return QDateTime(); |
853 | if (last && count == rDuration) | 853 | if (last && count == rDuration) |
854 | *last = true; | 854 | *last = true; |
855 | } | 855 | } |
856 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); | 856 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); |
857 | if (rDuration == 0) { | 857 | if (rDuration == 0) { |
858 | if (endtime > rEndDateTime) | 858 | if (endtime > rEndDateTime) |
859 | return QDateTime(); | 859 | return QDateTime(); |
860 | if (last && endtime == rEndDateTime) | 860 | if (last && endtime == rEndDateTime) |
861 | *last = true; | 861 | *last = true; |
862 | } | 862 | } |
863 | return endtime; | 863 | return endtime; |
864 | } | 864 | } |
865 | 865 | ||
866 | QDate Recurrence::getNextDate(const QDate &preDate, bool *last) const | 866 | QDate Recurrence::getNextDate(const QDate &preDate, bool *last) const |
867 | { | 867 | { |
868 | if (last) | 868 | if (last) |
869 | *last = false; | 869 | *last = false; |
870 | switch (recurs) | 870 | switch (recurs) |
871 | { | 871 | { |
872 | case rMinutely: | 872 | case rMinutely: |
873 | case rHourly: | 873 | case rHourly: |
874 | return getNextDateTime(QDateTime(preDate, QTime(23,59,59)), last).date(); | 874 | return getNextDateTime(QDateTime(preDate, QTime(23,59,59)), last).date(); |
875 | case rDaily: | 875 | case rDaily: |
876 | case rWeekly: | 876 | case rWeekly: |
877 | case rMonthlyPos: | 877 | case rMonthlyPos: |
878 | case rMonthlyDay: | 878 | case rMonthlyDay: |
879 | case rYearlyMonth: | 879 | case rYearlyMonth: |
880 | case rYearlyDay: | 880 | case rYearlyDay: |
881 | case rYearlyPos: | 881 | case rYearlyPos: |
882 | qDebug("Recurrence::getNextDate: MAY BE BROKEN "); | ||
882 | return getNextDateNoTime(preDate, last); | 883 | return getNextDateNoTime(preDate, last); |
883 | default: | 884 | default: |
884 | return QDate(); | 885 | return QDate(); |
885 | } | 886 | } |
886 | } | 887 | } |
887 | 888 | ||
888 | 889 | ||
889 | QDateTime Recurrence::getPreviousDateTime(const QDateTime &afterDateTime, bool *last) const | 890 | QDateTime Recurrence::getPreviousDateTime(const QDateTime &afterDateTime, bool *last) const |
890 | { | 891 | { |
891 | if (last) | 892 | if (last) |
892 | *last = false; | 893 | *last = false; |
893 | int freq; | 894 | int freq; |
894 | switch (recurs) | 895 | switch (recurs) |
895 | { | 896 | { |
896 | case rMinutely: | 897 | case rMinutely: |
897 | freq = rFreq * 60; | 898 | freq = rFreq * 60; |
898 | break; | 899 | break; |
899 | case rHourly: | 900 | case rHourly: |
900 | freq = rFreq * 3600; | 901 | freq = rFreq * 3600; |
901 | break; | 902 | break; |
902 | case rDaily: | 903 | case rDaily: |
903 | case rWeekly: | 904 | case rWeekly: |
904 | case rMonthlyPos: | 905 | case rMonthlyPos: |
905 | case rMonthlyDay: | 906 | case rMonthlyDay: |
906 | case rYearlyMonth: | 907 | case rYearlyMonth: |
907 | case rYearlyDay: | 908 | case rYearlyDay: |
908 | case rYearlyPos: { | 909 | case rYearlyPos: { |
909 | QDate afterDate = afterDateTime.date(); | 910 | QDate afterDate = afterDateTime.date(); |
910 | if (!mFloats && mRecurStart.time() < afterDateTime.time()) | 911 | if (!mFloats && mRecurStart.time() < afterDateTime.time()) |
911 | afterDate = afterDate.addDays(1); | 912 | afterDate = afterDate.addDays(1); |
912 | return QDateTime(getPreviousDateNoTime(afterDate, last), mRecurStart.time()); | 913 | return QDateTime(getPreviousDateNoTime(afterDate, last), mRecurStart.time()); |
913 | } | 914 | } |
914 | default: | 915 | default: |
915 | return QDateTime(); | 916 | return QDateTime(); |
916 | } | 917 | } |
917 | 918 | ||
918 | // It's a sub-daily recurrence | 919 | // It's a sub-daily recurrence |
919 | if (afterDateTime <= mRecurStart) | 920 | if (afterDateTime <= mRecurStart) |
920 | return QDateTime(); | 921 | return QDateTime(); |
921 | int count = (mRecurStart.secsTo(afterDateTime) - 1) / freq + 1; | 922 | int count = (mRecurStart.secsTo(afterDateTime) - 1) / freq + 1; |
922 | if (rDuration > 0) { | 923 | if (rDuration > 0) { |
923 | if (count > rDuration) | 924 | if (count > rDuration) |
924 | count = rDuration; | 925 | count = rDuration; |
925 | if (last && count == rDuration) | 926 | if (last && count == rDuration) |
926 | *last = true; | 927 | *last = true; |
927 | } | 928 | } |
928 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); | 929 | QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); |
929 | if (rDuration == 0) { | 930 | if (rDuration == 0) { |
@@ -1121,96 +1122,97 @@ bool Recurrence::recursYearlyByPos(const QDate &qd) const | |||
1121 | rDuration == -1)) { | 1122 | rDuration == -1)) { |
1122 | // The date queried falls within the range of the event. | 1123 | // The date queried falls within the range of the event. |
1123 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1124 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1124 | if (month == *qlin.current()) { | 1125 | if (month == *qlin.current()) { |
1125 | // The month recurs | 1126 | // The month recurs |
1126 | QValueList<int> days; | 1127 | QValueList<int> days; |
1127 | getMonthlyPosDays(days, qd.daysInMonth(), QDate(year, month, 1).dayOfWeek()); | 1128 | getMonthlyPosDays(days, qd.daysInMonth(), QDate(year, month, 1).dayOfWeek()); |
1128 | for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { | 1129 | for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { |
1129 | if (*it == day) | 1130 | if (*it == day) |
1130 | return true; | 1131 | return true; |
1131 | } | 1132 | } |
1132 | } | 1133 | } |
1133 | } | 1134 | } |
1134 | } | 1135 | } |
1135 | } | 1136 | } |
1136 | return false; | 1137 | return false; |
1137 | } | 1138 | } |
1138 | 1139 | ||
1139 | bool Recurrence::recursYearlyByDay(const QDate &qd) const | 1140 | bool Recurrence::recursYearlyByDay(const QDate &qd) const |
1140 | { | 1141 | { |
1141 | QDate dStart = mRecurStart.date(); | 1142 | QDate dStart = mRecurStart.date(); |
1142 | // calculate how many years ahead this date is from the original | 1143 | // calculate how many years ahead this date is from the original |
1143 | // event's date | 1144 | // event's date |
1144 | int yearsAhead = (qd.year() - dStart.year()); | 1145 | int yearsAhead = (qd.year() - dStart.year()); |
1145 | if (yearsAhead % rFreq == 0) { | 1146 | if (yearsAhead % rFreq == 0) { |
1146 | // The date is in a year which recurs | 1147 | // The date is in a year which recurs |
1147 | if (qd >= dStart | 1148 | if (qd >= dStart |
1148 | && ((rDuration > 0 && qd <= endDate()) || | 1149 | && ((rDuration > 0 && qd <= endDate()) || |
1149 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1150 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1150 | rDuration == -1)) { | 1151 | rDuration == -1)) { |
1151 | // The date queried falls within the range of the event. | 1152 | // The date queried falls within the range of the event. |
1152 | int i = qd.dayOfYear(); | 1153 | int i = qd.dayOfYear(); |
1153 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1154 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1154 | if (i == *qlin.current()) | 1155 | if (i == *qlin.current()) |
1155 | return true; | 1156 | return true; |
1156 | } | 1157 | } |
1157 | } | 1158 | } |
1158 | } | 1159 | } |
1159 | return false; | 1160 | return false; |
1160 | } | 1161 | } |
1161 | 1162 | ||
1162 | /* Get the date of the next recurrence, after the specified date. | 1163 | /* Get the date of the next recurrence, after the specified date. |
1163 | * If 'last' is non-null, '*last' is set to true if the next recurrence is the | 1164 | * If 'last' is non-null, '*last' is set to true if the next recurrence is the |
1164 | * last recurrence, else false. | 1165 | * last recurrence, else false. |
1165 | * Reply = date of next recurrence, or invalid date if none. | 1166 | * Reply = date of next recurrence, or invalid date if none. |
1166 | */ | 1167 | */ |
1167 | QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const | 1168 | QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const |
1168 | { | 1169 | { |
1170 | |||
1169 | if (last) | 1171 | if (last) |
1170 | *last = false; | 1172 | *last = false; |
1171 | QDate dStart = mRecurStart.date(); | 1173 | QDate dStart = mRecurStart.date(); |
1172 | if (preDate < dStart) | 1174 | if (preDate < dStart) |
1173 | return dStart; | 1175 | return dStart; |
1174 | QDate earliestDate = preDate.addDays(1); | 1176 | QDate earliestDate = preDate.addDays(1); |
1175 | QDate nextDate; | 1177 | QDate nextDate; |
1176 | 1178 | ||
1177 | switch (recurs) { | 1179 | switch (recurs) { |
1178 | case rDaily: | 1180 | case rDaily: |
1179 | nextDate = dStart.addDays((dStart.daysTo(preDate)/rFreq + 1) * rFreq); | 1181 | nextDate = dStart.addDays((dStart.daysTo(preDate)/rFreq + 1) * rFreq); |
1180 | break; | 1182 | break; |
1181 | 1183 | ||
1182 | case rWeekly: { | 1184 | case rWeekly: { |
1183 | QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart | 1185 | QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart |
1184 | int earliestDayOfWeek = earliestDate.dayOfWeek(); | 1186 | int earliestDayOfWeek = earliestDate.dayOfWeek(); |
1185 | int weeksAhead = start.daysTo(earliestDate) / 7; | 1187 | int weeksAhead = start.daysTo(earliestDate) / 7; |
1186 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week | 1188 | int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week |
1187 | weeksAhead -= notThisWeek; // latest week which recurred | 1189 | weeksAhead -= notThisWeek; // latest week which recurred |
1188 | int weekday = 0; | 1190 | int weekday = 0; |
1189 | // First check for any remaining day this week, if this week is a recurring week | 1191 | // First check for any remaining day this week, if this week is a recurring week |
1190 | if (!notThisWeek) | 1192 | if (!notThisWeek) |
1191 | weekday = getFirstDayInWeek(earliestDayOfWeek); | 1193 | weekday = getFirstDayInWeek(earliestDayOfWeek); |
1192 | // Check for a day in the next scheduled week | 1194 | // Check for a day in the next scheduled week |
1193 | if (!weekday && earliestDayOfWeek > 1) | 1195 | if (!weekday && earliestDayOfWeek > 1) |
1194 | weekday = getFirstDayInWeek(rWeekStart) + rFreq*7; | 1196 | weekday = getFirstDayInWeek(rWeekStart) + rFreq*7; |
1195 | if (weekday) | 1197 | if (weekday) |
1196 | nextDate = start.addDays(weeksAhead*7 + weekday - 1); | 1198 | nextDate = start.addDays(weeksAhead*7 + weekday - 1); |
1197 | break; | 1199 | break; |
1198 | } | 1200 | } |
1199 | case rMonthlyDay: | 1201 | case rMonthlyDay: |
1200 | case rMonthlyPos: { | 1202 | case rMonthlyPos: { |
1201 | int startYear = dStart.year(); | 1203 | int startYear = dStart.year(); |
1202 | int startMonth = dStart.month(); // 1..12 | 1204 | int startMonth = dStart.month(); // 1..12 |
1203 | int earliestYear = earliestDate.year(); | 1205 | int earliestYear = earliestDate.year(); |
1204 | int monthsAhead = (earliestYear - startYear)*12 + earliestDate.month() - startMonth; | 1206 | int monthsAhead = (earliestYear - startYear)*12 + earliestDate.month() - startMonth; |
1205 | int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month | 1207 | int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month |
1206 | monthsAhead -= notThisMonth; // latest month which recurred | 1208 | monthsAhead -= notThisMonth; // latest month which recurred |
1207 | // Check for the first later day in the current month | 1209 | // Check for the first later day in the current month |
1208 | if (!notThisMonth) | 1210 | if (!notThisMonth) |
1209 | nextDate = getFirstDateInMonth(earliestDate); | 1211 | nextDate = getFirstDateInMonth(earliestDate); |
1210 | if (!nextDate.isValid() && earliestDate.day() > 1) { | 1212 | if (!nextDate.isValid() && earliestDate.day() > 1) { |
1211 | // Check for a day in the next scheduled month | 1213 | // Check for a day in the next scheduled month |
1212 | int months = startMonth - 1 + monthsAhead + rFreq; | 1214 | int months = startMonth - 1 + monthsAhead + rFreq; |
1213 | nextDate = getFirstDateInMonth(QDate(startYear + months/12, months%12 + 1, 1)); | 1215 | nextDate = getFirstDateInMonth(QDate(startYear + months/12, months%12 + 1, 1)); |
1214 | } | 1216 | } |
1215 | break; | 1217 | break; |
1216 | } | 1218 | } |