Changeset View
Changeset View
Standalone View
Standalone View
src/recurrence.cpp
Show First 20 Lines • Show All 1134 Lines • ▼ Show 20 Line(s) | 1125 | while (loop < 1000) { | |||
---|---|---|---|---|---|
1135 | // of preDateTime). Loop at most 1000 times. | 1135 | // of preDateTime). Loop at most 1000 times. | ||
1136 | ++loop; | 1136 | ++loop; | ||
1137 | // First, get the next recurrence from the RDate lists | 1137 | // First, get the next recurrence from the RDate lists | ||
1138 | SortableList<QDateTime> dates; | 1138 | SortableList<QDateTime> dates; | ||
1139 | if (nextDT < startDateTime()) { | 1139 | if (nextDT < startDateTime()) { | ||
1140 | dates << startDateTime(); | 1140 | dates << startDateTime(); | ||
1141 | } | 1141 | } | ||
1142 | 1142 | | |||
1143 | int end; | | |||
1144 | // Assume that the rdatetime list is sorted | 1143 | // Assume that the rdatetime list is sorted | ||
1145 | int i = d->mRDateTimes.findGT(nextDT); | 1144 | int i = d->mRDateTimes.findGT(nextDT); | ||
1146 | if (i >= 0) { | 1145 | if (i >= 0) { | ||
1147 | dates << d->mRDateTimes[i]; | 1146 | dates << d->mRDateTimes[i]; | ||
1148 | } | 1147 | } | ||
1149 | 1148 | | |||
1150 | QDateTime kdt(startDateTime()); | 1149 | QDateTime kdt(startDateTime()); | ||
1151 | for (i = 0, end = d->mRDates.count(); i < end; ++i) { | 1150 | for (const auto &date : d->mRDates) { | ||
1152 | kdt.setDate(d->mRDates[i]); | 1151 | kdt.setDate(date); | ||
1153 | if (kdt > nextDT) { | 1152 | if (kdt > nextDT) { | ||
1154 | dates << kdt; | 1153 | dates << kdt; | ||
1155 | break; | 1154 | break; | ||
1156 | } | 1155 | } | ||
1157 | } | 1156 | } | ||
1158 | 1157 | | |||
1159 | // Add the next occurrences from all RRULEs. | 1158 | // Add the next occurrences from all RRULEs. | ||
1160 | for (i = 0, end = d->mRRules.count(); i < end; ++i) { | 1159 | for (auto rule : d->mRRules) { | ||
1161 | QDateTime dt = d->mRRules[i]->getNextDate(nextDT); | 1160 | QDateTime dt = rule->getNextDate(nextDT); | ||
1162 | if (dt.isValid()) { | 1161 | if (dt.isValid()) { | ||
1163 | dates << dt; | 1162 | dates << dt; | ||
1164 | } | 1163 | } | ||
1165 | } | 1164 | } | ||
1166 | 1165 | | |||
1167 | // Take the first of these (all others can't be used later on) | 1166 | // Take the first of these (all others can't be used later on) | ||
1168 | sortAndRemoveDuplicates(dates); | 1167 | sortAndRemoveDuplicates(dates); | ||
1169 | if (dates.isEmpty()) { | 1168 | if (dates.isEmpty()) { | ||
1170 | return QDateTime(); | 1169 | return QDateTime(); | ||
1171 | } | 1170 | } | ||
1172 | nextDT = dates.first(); | 1171 | nextDT = dates.first(); | ||
1173 | 1172 | | |||
1174 | // Check if that date/time is excluded explicitly or by an exrule: | 1173 | // Check if that date/time is excluded explicitly or by an exrule: | ||
1175 | if (!std::binary_search(d->mExDates.constBegin(), d->mExDates.constEnd(), nextDT.date()) && | 1174 | if (!std::binary_search(d->mExDates.constBegin(), d->mExDates.constEnd(), nextDT.date()) && | ||
1176 | !std::binary_search(d->mExDateTimes.constBegin(), d->mExDateTimes.constEnd(), nextDT)) { | 1175 | !std::binary_search(d->mExDateTimes.constBegin(), d->mExDateTimes.constEnd(), nextDT)) { | ||
1177 | bool allowed = true; | 1176 | bool allowed = true; | ||
1178 | for (i = 0, end = d->mExRules.count(); i < end; ++i) { | 1177 | for (auto rule : d->mExRules) { | ||
1179 | allowed = allowed && !(d->mExRules[i]->recursAt(nextDT)); | 1178 | allowed = allowed && !rule->recursAt(nextDT); | ||
1180 | } | 1179 | } | ||
1181 | if (allowed) { | 1180 | if (allowed) { | ||
1182 | return nextDT; | 1181 | return nextDT; | ||
1183 | } | 1182 | } | ||
1184 | } | 1183 | } | ||
1185 | } | 1184 | } | ||
1186 | 1185 | | |||
1187 | // Couldn't find a valid occurrences in 1000 loops, something is wrong! | 1186 | // Couldn't find a valid occurrences in 1000 loops, something is wrong! | ||
Show All 25 Lines | 1197 | while (loop < 1000) { | |||
1213 | } | 1212 | } | ||
1214 | 1213 | | |||
1215 | int i = d->mRDateTimes.findLT(prevDT); | 1214 | int i = d->mRDateTimes.findLT(prevDT); | ||
1216 | if (i >= 0) { | 1215 | if (i >= 0) { | ||
1217 | dates << d->mRDateTimes[i]; | 1216 | dates << d->mRDateTimes[i]; | ||
1218 | } | 1217 | } | ||
1219 | 1218 | | |||
1220 | QDateTime kdt(startDateTime()); | 1219 | QDateTime kdt(startDateTime()); | ||
1221 | for (i = d->mRDates.count(); --i >= 0;) { | 1220 | for (const auto &date : d->mRDates) { | ||
1222 | kdt.setDate(d->mRDates[i]); | 1221 | kdt.setDate(date); | ||
1223 | if (kdt < prevDT) { | 1222 | if (kdt < prevDT) { | ||
1224 | dates << kdt; | 1223 | dates << kdt; | ||
1225 | break; | 1224 | break; | ||
1226 | } | 1225 | } | ||
1227 | } | 1226 | } | ||
1228 | 1227 | | |||
1229 | // Add the previous occurrences from all RRULEs. | 1228 | // Add the previous occurrences from all RRULEs. | ||
1230 | int end; | 1229 | for (auto rule : d->mRRules) { | ||
1231 | for (i = 0, end = d->mRRules.count(); i < end; ++i) { | 1230 | QDateTime dt = rule->getPreviousDate(prevDT); | ||
1232 | QDateTime dt = d->mRRules[i]->getPreviousDate(prevDT); | | |||
1233 | if (dt.isValid()) { | 1231 | if (dt.isValid()) { | ||
1234 | dates << dt; | 1232 | dates << dt; | ||
1235 | } | 1233 | } | ||
1236 | } | 1234 | } | ||
1237 | 1235 | | |||
1238 | // Take the last of these (all others can't be used later on) | 1236 | // Take the last of these (all others can't be used later on) | ||
1239 | sortAndRemoveDuplicates(dates); | 1237 | sortAndRemoveDuplicates(dates); | ||
1240 | if (dates.isEmpty()) { | 1238 | if (dates.isEmpty()) { | ||
1241 | return QDateTime(); | 1239 | return QDateTime(); | ||
1242 | } | 1240 | } | ||
1243 | prevDT = dates.last(); | 1241 | prevDT = dates.last(); | ||
1244 | 1242 | | |||
1245 | // Check if that date/time is excluded explicitly or by an exrule: | 1243 | // Check if that date/time is excluded explicitly or by an exrule: | ||
1246 | if (!std::binary_search(d->mExDates.constBegin(), d->mExDates.constEnd(), prevDT.date()) && | 1244 | if (!std::binary_search(d->mExDates.constBegin(), d->mExDates.constEnd(), prevDT.date()) && | ||
1247 | !std::binary_search(d->mExDateTimes.constBegin(), d->mExDateTimes.constEnd(), prevDT)) { | 1245 | !std::binary_search(d->mExDateTimes.constBegin(), d->mExDateTimes.constEnd(), prevDT)) { | ||
1248 | bool allowed = true; | 1246 | bool allowed = true; | ||
1249 | for (i = 0, end = d->mExRules.count(); i < end; ++i) { | 1247 | for (auto rule : d->mExRules) { | ||
1250 | allowed = allowed && !(d->mExRules[i]->recursAt(prevDT)); | 1248 | allowed = allowed && !rule->recursAt(prevDT); | ||
1251 | } | 1249 | } | ||
1252 | if (allowed) { | 1250 | if (allowed) { | ||
1253 | return prevDT; | 1251 | return prevDT; | ||
1254 | } | 1252 | } | ||
1255 | } | 1253 | } | ||
1256 | } | 1254 | } | ||
1257 | 1255 | | |||
1258 | // Couldn't find a valid occurrences in 1000 loops, something is wrong! | 1256 | // Couldn't find a valid occurrences in 1000 loops, something is wrong! | ||
▲ Show 20 Lines • Show All 299 Lines • Show Last 20 Lines |