Changeset View
Changeset View
Standalone View
Standalone View
src/recurrence.cpp
Show First 20 Lines • Show All 1141 Lines • ▼ Show 20 Line(s) | 1125 | while (loop < 1000) { | |||
---|---|---|---|---|---|
1142 | 1142 | | |||
1143 | // Assume that the rdatetime list is sorted | 1143 | // Assume that the rdatetime list is sorted | ||
1144 | const auto it = std::upper_bound(d->mRDateTimes.constBegin(), d->mRDateTimes.constEnd(), nextDT); | 1144 | const auto it = std::upper_bound(d->mRDateTimes.constBegin(), d->mRDateTimes.constEnd(), nextDT); | ||
1145 | if (it != d->mRDateTimes.constEnd()) { | 1145 | if (it != d->mRDateTimes.constEnd()) { | ||
1146 | dates << *it; | 1146 | dates << *it; | ||
1147 | } | 1147 | } | ||
1148 | 1148 | | |||
1149 | QDateTime kdt(startDateTime()); | 1149 | QDateTime kdt(startDateTime()); | ||
1150 | for (const auto &date : d->mRDates) { | 1150 | for (const auto &date : qAsConst(d->mRDates)) { | ||
1151 | kdt.setDate(date); | 1151 | kdt.setDate(date); | ||
1152 | if (kdt > nextDT) { | 1152 | if (kdt > nextDT) { | ||
1153 | dates << kdt; | 1153 | dates << kdt; | ||
1154 | break; | 1154 | break; | ||
1155 | } | 1155 | } | ||
1156 | } | 1156 | } | ||
1157 | 1157 | | |||
1158 | // Add the next occurrences from all RRULEs. | 1158 | // Add the next occurrences from all RRULEs. | ||
1159 | for (auto rule : d->mRRules) { | 1159 | for (const auto &rule : qAsConst(d->mRRules)) { | ||
1160 | QDateTime dt = rule->getNextDate(nextDT); | 1160 | QDateTime dt = rule->getNextDate(nextDT); | ||
1161 | if (dt.isValid()) { | 1161 | if (dt.isValid()) { | ||
1162 | dates << dt; | 1162 | dates << dt; | ||
1163 | } | 1163 | } | ||
1164 | } | 1164 | } | ||
1165 | 1165 | | |||
1166 | // 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) | ||
1167 | sortAndRemoveDuplicates(dates); | 1167 | sortAndRemoveDuplicates(dates); | ||
1168 | if (dates.isEmpty()) { | 1168 | if (dates.isEmpty()) { | ||
1169 | return QDateTime(); | 1169 | return QDateTime(); | ||
1170 | } | 1170 | } | ||
1171 | nextDT = dates.first(); | 1171 | nextDT = dates.first(); | ||
1172 | 1172 | | |||
1173 | // 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: | ||
1174 | 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()) && | ||
1175 | !std::binary_search(d->mExDateTimes.constBegin(), d->mExDateTimes.constEnd(), nextDT)) { | 1175 | !std::binary_search(d->mExDateTimes.constBegin(), d->mExDateTimes.constEnd(), nextDT)) { | ||
1176 | bool allowed = true; | 1176 | bool allowed = true; | ||
1177 | for (auto rule : d->mExRules) { | 1177 | for (const auto &rule : qAsConst(d->mExRules)) { | ||
1178 | allowed = allowed && !rule->recursAt(nextDT); | 1178 | allowed = allowed && !rule->recursAt(nextDT); | ||
1179 | } | 1179 | } | ||
1180 | if (allowed) { | 1180 | if (allowed) { | ||
1181 | return nextDT; | 1181 | return nextDT; | ||
1182 | } | 1182 | } | ||
1183 | } | 1183 | } | ||
1184 | } | 1184 | } | ||
1185 | 1185 | | |||
Show All 26 Lines | 1197 | while (loop < 1000) { | |||
1212 | } | 1212 | } | ||
1213 | 1213 | | |||
1214 | const auto it = strictLowerBound(d->mRDateTimes.constBegin(), d->mRDateTimes.constEnd(), prevDT); | 1214 | const auto it = strictLowerBound(d->mRDateTimes.constBegin(), d->mRDateTimes.constEnd(), prevDT); | ||
1215 | if (it != d->mRDateTimes.constEnd()) { | 1215 | if (it != d->mRDateTimes.constEnd()) { | ||
1216 | dates << *it; | 1216 | dates << *it; | ||
1217 | } | 1217 | } | ||
1218 | 1218 | | |||
1219 | QDateTime kdt(startDateTime()); | 1219 | QDateTime kdt(startDateTime()); | ||
1220 | for (const auto &date : d->mRDates) { | 1220 | for (const auto &date : qAsConst(d->mRDates)) { | ||
1221 | kdt.setDate(date); | 1221 | kdt.setDate(date); | ||
1222 | if (kdt < prevDT) { | 1222 | if (kdt < prevDT) { | ||
1223 | dates << kdt; | 1223 | dates << kdt; | ||
1224 | break; | 1224 | break; | ||
1225 | } | 1225 | } | ||
1226 | } | 1226 | } | ||
1227 | 1227 | | |||
1228 | // Add the previous occurrences from all RRULEs. | 1228 | // Add the previous occurrences from all RRULEs. | ||
1229 | for (auto rule : d->mRRules) { | 1229 | for (const auto &rule : qAsConst(d->mRRules)) { | ||
1230 | QDateTime dt = rule->getPreviousDate(prevDT); | 1230 | QDateTime dt = rule->getPreviousDate(prevDT); | ||
1231 | if (dt.isValid()) { | 1231 | if (dt.isValid()) { | ||
1232 | dates << dt; | 1232 | dates << dt; | ||
1233 | } | 1233 | } | ||
1234 | } | 1234 | } | ||
1235 | 1235 | | |||
1236 | // 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) | ||
1237 | sortAndRemoveDuplicates(dates); | 1237 | sortAndRemoveDuplicates(dates); | ||
1238 | if (dates.isEmpty()) { | 1238 | if (dates.isEmpty()) { | ||
1239 | return QDateTime(); | 1239 | return QDateTime(); | ||
1240 | } | 1240 | } | ||
1241 | prevDT = dates.last(); | 1241 | prevDT = dates.last(); | ||
1242 | 1242 | | |||
1243 | // 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: | ||
1244 | 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()) && | ||
1245 | !std::binary_search(d->mExDateTimes.constBegin(), d->mExDateTimes.constEnd(), prevDT)) { | 1245 | !std::binary_search(d->mExDateTimes.constBegin(), d->mExDateTimes.constEnd(), prevDT)) { | ||
1246 | bool allowed = true; | 1246 | bool allowed = true; | ||
1247 | for (auto rule : d->mExRules) { | 1247 | for (const auto &rule : qAsConst(d->mExRules)) { | ||
1248 | allowed = allowed && !rule->recursAt(prevDT); | 1248 | allowed = allowed && !rule->recursAt(prevDT); | ||
1249 | } | 1249 | } | ||
1250 | if (allowed) { | 1250 | if (allowed) { | ||
1251 | return prevDT; | 1251 | return prevDT; | ||
1252 | } | 1252 | } | ||
1253 | } | 1253 | } | ||
1254 | } | 1254 | } | ||
1255 | 1255 | | |||
▲ Show 20 Lines • Show All 300 Lines • Show Last 20 Lines |