author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /libkcal/recurrence.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
-rw-r--r-- | libkcal/recurrence.cpp | 187 |
1 files changed, 95 insertions, 92 deletions
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp index 6ee5499..9a4e540 100644 --- a/libkcal/recurrence.cpp +++ b/libkcal/recurrence.cpp | |||
@@ -26,12 +26,15 @@ | |||
26 | #include <kglobal.h> | 26 | #include <kglobal.h> |
27 | #include <klocale.h> | 27 | #include <klocale.h> |
28 | 28 | ||
29 | #include "incidence.h" | 29 | #include "incidence.h" |
30 | 30 | ||
31 | #include "recurrence.h" | 31 | #include "recurrence.h" |
32 | //Added by qt3to4: | ||
33 | #include <Q3ValueList> | ||
34 | #include <Q3PtrList> | ||
32 | 35 | ||
33 | using namespace KCal; | 36 | using namespace KCal; |
34 | 37 | ||
35 | Recurrence::Feb29Type Recurrence::mFeb29YearlyDefaultType = Recurrence::rMar1; | 38 | Recurrence::Feb29Type Recurrence::mFeb29YearlyDefaultType = Recurrence::rMar1; |
36 | 39 | ||
37 | 40 | ||
@@ -53,13 +56,13 @@ Recurrence::Recurrence(Incidence *parent, int compatVersion) | |||
53 | rYearNums.setAutoDelete( true ); | 56 | rYearNums.setAutoDelete( true ); |
54 | } | 57 | } |
55 | 58 | ||
56 | Recurrence::Recurrence(const Recurrence &r, Incidence *parent) | 59 | Recurrence::Recurrence(const Recurrence &r, Incidence *parent) |
57 | : recurs(r.recurs), | 60 | : recurs(r.recurs), |
58 | rWeekStart(r.rWeekStart), | 61 | rWeekStart(r.rWeekStart), |
59 | rDays(r.rDays.copy()), | 62 | rDays(r.rDays), |
60 | rFreq(r.rFreq), | 63 | rFreq(r.rFreq), |
61 | rDuration(r.rDuration), | 64 | rDuration(r.rDuration), |
62 | rEndDateTime(r.rEndDateTime), | 65 | rEndDateTime(r.rEndDateTime), |
63 | mRecurStart(r.mRecurStart), | 66 | mRecurStart(r.mRecurStart), |
64 | mFloats(r.mFloats), | 67 | mFloats(r.mFloats), |
65 | mRecurReadOnly(r.mRecurReadOnly), | 68 | mRecurReadOnly(r.mRecurReadOnly), |
@@ -67,25 +70,25 @@ Recurrence::Recurrence(const Recurrence &r, Incidence *parent) | |||
67 | mFeb29YearlyType(r.mFeb29YearlyType), | 70 | mFeb29YearlyType(r.mFeb29YearlyType), |
68 | mCompatVersion(r.mCompatVersion), | 71 | mCompatVersion(r.mCompatVersion), |
69 | mCompatRecurs(r.mCompatRecurs), | 72 | mCompatRecurs(r.mCompatRecurs), |
70 | mCompatDuration(r.mCompatDuration), | 73 | mCompatDuration(r.mCompatDuration), |
71 | mParent(parent) | 74 | mParent(parent) |
72 | { | 75 | { |
73 | for (QPtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) { | 76 | for (Q3PtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) { |
74 | rMonthPos *tmp = new rMonthPos; | 77 | rMonthPos *tmp = new rMonthPos; |
75 | tmp->rPos = mp.current()->rPos; | 78 | tmp->rPos = mp.current()->rPos; |
76 | tmp->negative = mp.current()->negative; | 79 | tmp->negative = mp.current()->negative; |
77 | tmp->rDays = mp.current()->rDays.copy(); | 80 | tmp->rDays = mp.current()->rDays; |
78 | rMonthPositions.append(tmp); | 81 | rMonthPositions.append(tmp); |
79 | } | 82 | } |
80 | for (QPtrListIterator<int> md(r.rMonthDays); md.current(); ++md) { | 83 | for (Q3PtrListIterator<int> md(r.rMonthDays); md.current(); ++md) { |
81 | int *tmp = new int; | 84 | int *tmp = new int; |
82 | *tmp = *md.current(); | 85 | *tmp = *md.current(); |
83 | rMonthDays.append(tmp); | 86 | rMonthDays.append(tmp); |
84 | } | 87 | } |
85 | for (QPtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) { | 88 | for (Q3PtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) { |
86 | int *tmp = new int; | 89 | int *tmp = new int; |
87 | *tmp = *yn.current(); | 90 | *tmp = *yn.current(); |
88 | rYearNums.append(tmp); | 91 | rYearNums.append(tmp); |
89 | } | 92 | } |
90 | rMonthDays.setAutoDelete( true ); | 93 | rMonthDays.setAutoDelete( true ); |
91 | rMonthPositions.setAutoDelete( true ); | 94 | rMonthPositions.setAutoDelete( true ); |
@@ -121,52 +124,52 @@ bool Recurrence::operator==( const Recurrence& r2 ) const | |||
121 | switch ( recurs ) | 124 | switch ( recurs ) |
122 | { | 125 | { |
123 | case rWeekly: | 126 | case rWeekly: |
124 | return rDays == r2.rDays | 127 | return rDays == r2.rDays |
125 | && rWeekStart == r2.rWeekStart; | 128 | && rWeekStart == r2.rWeekStart; |
126 | case rMonthlyPos: { | 129 | case rMonthlyPos: { |
127 | QPtrList<rMonthPos> MonthPositions = rMonthPositions; | 130 | Q3PtrList<rMonthPos> MonthPositions = rMonthPositions; |
128 | QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions; | 131 | Q3PtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions; |
129 | if ( !MonthPositions.count() ) | 132 | if ( !MonthPositions.count() ) |
130 | return false; | 133 | return false; |
131 | if ( !MonthPositions2.count() ) | 134 | if ( !MonthPositions2.count() ) |
132 | return false; | 135 | return false; |
133 | return MonthPositions.first()->rPos == MonthPositions2.first()->rPos; | 136 | return MonthPositions.first()->rPos == MonthPositions2.first()->rPos; |
134 | } | 137 | } |
135 | case rMonthlyDay: { | 138 | case rMonthlyDay: { |
136 | QPtrList<int> MonthDays = rMonthDays ; | 139 | Q3PtrList<int> MonthDays = rMonthDays ; |
137 | QPtrList<int> MonthDays2 = r2.rMonthDays ; | 140 | Q3PtrList<int> MonthDays2 = r2.rMonthDays ; |
138 | if ( !MonthDays.count() ) | 141 | if ( !MonthDays.count() ) |
139 | return false; | 142 | return false; |
140 | if ( !MonthDays2.count() ) | 143 | if ( !MonthDays2.count() ) |
141 | return false; | 144 | return false; |
142 | return *MonthDays.first() == *MonthDays2.first() ; | 145 | return *MonthDays.first() == *MonthDays2.first() ; |
143 | } | 146 | } |
144 | case rYearlyPos: { | 147 | case rYearlyPos: { |
145 | 148 | ||
146 | QPtrList<int> YearNums = rYearNums; | 149 | Q3PtrList<int> YearNums = rYearNums; |
147 | QPtrList<int> YearNums2 = r2.rYearNums; | 150 | Q3PtrList<int> YearNums2 = r2.rYearNums; |
148 | if ( *YearNums.first() != *YearNums2.first() ) | 151 | if ( *YearNums.first() != *YearNums2.first() ) |
149 | return false; | 152 | return false; |
150 | QPtrList<rMonthPos> MonthPositions = rMonthPositions; | 153 | Q3PtrList<rMonthPos> MonthPositions = rMonthPositions; |
151 | QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions; | 154 | Q3PtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions; |
152 | if ( !MonthPositions.count() ) | 155 | if ( !MonthPositions.count() ) |
153 | return false; | 156 | return false; |
154 | if ( !MonthPositions2.count() ) | 157 | if ( !MonthPositions2.count() ) |
155 | return false; | 158 | return false; |
156 | return MonthPositions.first()->rPos == MonthPositions2.first()->rPos; | 159 | return MonthPositions.first()->rPos == MonthPositions2.first()->rPos; |
157 | 160 | ||
158 | } | 161 | } |
159 | case rYearlyMonth: { | 162 | case rYearlyMonth: { |
160 | QPtrList<int> YearNums = rYearNums; | 163 | Q3PtrList<int> YearNums = rYearNums; |
161 | QPtrList<int> YearNums2 = r2.rYearNums; | 164 | Q3PtrList<int> YearNums2 = r2.rYearNums; |
162 | return ( *YearNums.first() == *YearNums2.first() && mFeb29YearlyType == r2.mFeb29YearlyType); | 165 | return ( *YearNums.first() == *YearNums2.first() && mFeb29YearlyType == r2.mFeb29YearlyType); |
163 | } | 166 | } |
164 | case rYearlyDay: { | 167 | case rYearlyDay: { |
165 | QPtrList<int> YearNums = rYearNums; | 168 | Q3PtrList<int> YearNums = rYearNums; |
166 | QPtrList<int> YearNums2 = r2.rYearNums; | 169 | Q3PtrList<int> YearNums2 = r2.rYearNums; |
167 | return ( *YearNums.first() == *YearNums2.first() ); | 170 | return ( *YearNums.first() == *YearNums2.first() ); |
168 | } | 171 | } |
169 | case rNone: | 172 | case rNone: |
170 | case rMinutely: | 173 | case rMinutely: |
171 | case rHourly: | 174 | case rHourly: |
172 | case rDaily: | 175 | case rDaily: |
@@ -354,13 +357,13 @@ QDateTime Recurrence::endDateTime() const | |||
354 | { | 357 | { |
355 | case rMinutely: | 358 | case rMinutely: |
356 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60); | 359 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60); |
357 | case rHourly: | 360 | case rHourly: |
358 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600); | 361 | return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600); |
359 | case rDaily: | 362 | case rDaily: |
360 | return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); | 363 | return (QDateTime)dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); |
361 | 364 | ||
362 | case rWeekly: | 365 | case rWeekly: |
363 | count = weeklyCalc(END_DATE_AND_COUNT, end); | 366 | count = weeklyCalc(END_DATE_AND_COUNT, end); |
364 | break; | 367 | break; |
365 | case rMonthlyPos: | 368 | case rMonthlyPos: |
366 | case rMonthlyDay: | 369 | case rMonthlyDay: |
@@ -503,23 +506,23 @@ QString Recurrence::endDateStr(bool shortfmt) const | |||
503 | 506 | ||
504 | const QBitArray &Recurrence::days() const | 507 | const QBitArray &Recurrence::days() const |
505 | { | 508 | { |
506 | return rDays; | 509 | return rDays; |
507 | } | 510 | } |
508 | 511 | ||
509 | const QPtrList<Recurrence::rMonthPos> &Recurrence::monthPositions() const | 512 | const Q3PtrList<Recurrence::rMonthPos> &Recurrence::monthPositions() const |
510 | { | 513 | { |
511 | return rMonthPositions; | 514 | return rMonthPositions; |
512 | } | 515 | } |
513 | 516 | ||
514 | const QPtrList<Recurrence::rMonthPos> &Recurrence::yearMonthPositions() const | 517 | const Q3PtrList<Recurrence::rMonthPos> &Recurrence::yearMonthPositions() const |
515 | { | 518 | { |
516 | return rMonthPositions; | 519 | return rMonthPositions; |
517 | } | 520 | } |
518 | 521 | ||
519 | const QPtrList<int> &Recurrence::monthDays() const | 522 | const Q3PtrList<int> &Recurrence::monthDays() const |
520 | { | 523 | { |
521 | return rMonthDays; | 524 | return rMonthDays; |
522 | } | 525 | } |
523 | 526 | ||
524 | void Recurrence::setMinutely(int _rFreq, int _rDuration) | 527 | void Recurrence::setMinutely(int _rFreq, int _rDuration) |
525 | { | 528 | { |
@@ -756,13 +759,13 @@ void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndD | |||
756 | void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays) | 759 | void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays) |
757 | { | 760 | { |
758 | if (recurs == rYearlyPos) | 761 | if (recurs == rYearlyPos) |
759 | addMonthlyPos_(_rPos, _rDays); | 762 | addMonthlyPos_(_rPos, _rDays); |
760 | } | 763 | } |
761 | 764 | ||
762 | const QPtrList<int> &Recurrence::yearNums() const | 765 | const Q3PtrList<int> &Recurrence::yearNums() const |
763 | { | 766 | { |
764 | return rYearNums; | 767 | return rYearNums; |
765 | } | 768 | } |
766 | void Recurrence::addYearlyMonth(short _rPos ) | 769 | void Recurrence::addYearlyMonth(short _rPos ) |
767 | { | 770 | { |
768 | if (mRecurReadOnly || recurs != rYearlyMonth) // invalid day/month number | 771 | if (mRecurReadOnly || recurs != rYearlyMonth) // invalid day/month number |
@@ -1044,19 +1047,19 @@ bool Recurrence::recursMonthly(const QDate &qd) const | |||
1044 | // The date is in a month which recurs | 1047 | // The date is in a month which recurs |
1045 | if (qd >= dStart | 1048 | if (qd >= dStart |
1046 | && ((rDuration > 0 && qd <= endDate()) || | 1049 | && ((rDuration > 0 && qd <= endDate()) || |
1047 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1050 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1048 | rDuration == -1)) { | 1051 | rDuration == -1)) { |
1049 | // The date queried falls within the range of the event. | 1052 | // The date queried falls within the range of the event. |
1050 | QValueList<int> days; | 1053 | Q3ValueList<int> days; |
1051 | int daysInMonth = qd.daysInMonth(); | 1054 | int daysInMonth = qd.daysInMonth(); |
1052 | if (recurs == rMonthlyDay) | 1055 | if (recurs == rMonthlyDay) |
1053 | getMonthlyDayDays(days, daysInMonth); | 1056 | getMonthlyDayDays(days, daysInMonth); |
1054 | else if (recurs == rMonthlyPos) | 1057 | else if (recurs == rMonthlyPos) |
1055 | getMonthlyPosDays(days, daysInMonth, QDate(year, month, 1).dayOfWeek()); | 1058 | getMonthlyPosDays(days, daysInMonth, QDate(year, month, 1).dayOfWeek()); |
1056 | for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { | 1059 | for (Q3ValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { |
1057 | if (*it == day) | 1060 | if (*it == day) |
1058 | return true; | 1061 | return true; |
1059 | } | 1062 | } |
1060 | // no dates matched | 1063 | // no dates matched |
1061 | } | 1064 | } |
1062 | } | 1065 | } |
@@ -1098,13 +1101,13 @@ bool Recurrence::recursYearlyByMonth(const QDate &qd) const | |||
1098 | if (qd >= dStart | 1101 | if (qd >= dStart |
1099 | && ((rDuration > 0 && qd <= endDate()) || | 1102 | && ((rDuration > 0 && qd <= endDate()) || |
1100 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1103 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1101 | rDuration == -1)) { | 1104 | rDuration == -1)) { |
1102 | // The date queried falls within the range of the event. | 1105 | // The date queried falls within the range of the event. |
1103 | int i = qmonth; | 1106 | int i = qmonth; |
1104 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1107 | for (Q3PtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1105 | if (i == *qlin.current()) | 1108 | if (i == *qlin.current()) |
1106 | return true; | 1109 | return true; |
1107 | } | 1110 | } |
1108 | } | 1111 | } |
1109 | } | 1112 | } |
1110 | } | 1113 | } |
@@ -1124,18 +1127,18 @@ bool Recurrence::recursYearlyByPos(const QDate &qd) const | |||
1124 | // The date is in a year which recurs | 1127 | // The date is in a year which recurs |
1125 | if (qd >= dStart | 1128 | if (qd >= dStart |
1126 | && ((rDuration > 0 && qd <= endDate()) || | 1129 | && ((rDuration > 0 && qd <= endDate()) || |
1127 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1130 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1128 | rDuration == -1)) { | 1131 | rDuration == -1)) { |
1129 | // The date queried falls within the range of the event. | 1132 | // The date queried falls within the range of the event. |
1130 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1133 | for (Q3PtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1131 | if (month == *qlin.current()) { | 1134 | if (month == *qlin.current()) { |
1132 | // The month recurs | 1135 | // The month recurs |
1133 | QValueList<int> days; | 1136 | Q3ValueList<int> days; |
1134 | getMonthlyPosDays(days, qd.daysInMonth(), QDate(year, month, 1).dayOfWeek()); | 1137 | getMonthlyPosDays(days, qd.daysInMonth(), QDate(year, month, 1).dayOfWeek()); |
1135 | for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { | 1138 | for (Q3ValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { |
1136 | if (*it == day) | 1139 | if (*it == day) |
1137 | return true; | 1140 | return true; |
1138 | } | 1141 | } |
1139 | } | 1142 | } |
1140 | } | 1143 | } |
1141 | } | 1144 | } |
@@ -1154,13 +1157,13 @@ bool Recurrence::recursYearlyByDay(const QDate &qd) const | |||
1154 | if (qd >= dStart | 1157 | if (qd >= dStart |
1155 | && ((rDuration > 0 && qd <= endDate()) || | 1158 | && ((rDuration > 0 && qd <= endDate()) || |
1156 | (rDuration == 0 && qd <= rEndDateTime.date()) || | 1159 | (rDuration == 0 && qd <= rEndDateTime.date()) || |
1157 | rDuration == -1)) { | 1160 | rDuration == -1)) { |
1158 | // The date queried falls within the range of the event. | 1161 | // The date queried falls within the range of the event. |
1159 | int i = qd.dayOfYear(); | 1162 | int i = qd.dayOfYear(); |
1160 | for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { | 1163 | for (Q3PtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { |
1161 | if (i == *qlin.current()) | 1164 | if (i == *qlin.current()) |
1162 | return true; | 1165 | return true; |
1163 | } | 1166 | } |
1164 | } | 1167 | } |
1165 | } | 1168 | } |
1166 | return false; | 1169 | return false; |
@@ -1546,13 +1549,13 @@ int Recurrence::recurCalc(PeriodFunc func, QDate &enddate) const | |||
1546 | } | 1549 | } |
1547 | 1550 | ||
1548 | switch (func) { | 1551 | switch (func) { |
1549 | case END_DATE_AND_COUNT: | 1552 | case END_DATE_AND_COUNT: |
1550 | case NEXT_AFTER_DATE: | 1553 | case NEXT_AFTER_DATE: |
1551 | if (count == 0) | 1554 | if (count == 0) |
1552 | endtime = QDate(); | 1555 | endtime = QDateTime(); |
1553 | else if (timed) | 1556 | else if (timed) |
1554 | enddate = endtime.date(); | 1557 | enddate = endtime.date(); |
1555 | break; | 1558 | break; |
1556 | case COUNT_TO_DATE: | 1559 | case COUNT_TO_DATE: |
1557 | break; | 1560 | break; |
1558 | } | 1561 | } |
@@ -1790,30 +1793,30 @@ struct Recurrence::MonthlyData { | |||
1790 | const Recurrence *recurrence; | 1793 | const Recurrence *recurrence; |
1791 | int year; // current year | 1794 | int year; // current year |
1792 | int month; // current month 0..11 | 1795 | int month; // current month 0..11 |
1793 | int day; // current day of month 1..31 | 1796 | int day; // current day of month 1..31 |
1794 | bool varies; // true if recurring days vary between different months | 1797 | bool varies; // true if recurring days vary between different months |
1795 | private: | 1798 | private: |
1796 | QValueList<int> days28, days29, days30, days31; // recurring days in months of each length | 1799 | Q3ValueList<int> days28, days29, days30, days31; // recurring days in months of each length |
1797 | QValueList<int> *recurDays[4]; | 1800 | Q3ValueList<int> *recurDays[4]; |
1798 | public: | 1801 | public: |
1799 | MonthlyData(const Recurrence* r, const QDate &date) | 1802 | MonthlyData(const Recurrence* r, const QDate &date) |
1800 | : recurrence(r), year(date.year()), month(date.month()-1), day(date.day()) | 1803 | : recurrence(r), year(date.year()), month(date.month()-1), day(date.day()) |
1801 | { recurDays[0] = &days28; | 1804 | { recurDays[0] = &days28; |
1802 | recurDays[1] = &days29; | 1805 | recurDays[1] = &days29; |
1803 | recurDays[2] = &days30; | 1806 | recurDays[2] = &days30; |
1804 | recurDays[3] = &days31; | 1807 | recurDays[3] = &days31; |
1805 | varies = (recurrence->recurs == rMonthlyPos) | 1808 | varies = (recurrence->recurs == rMonthlyPos) |
1806 | ? true : recurrence->getMonthlyDayDays(days31, 31); | 1809 | ? true : recurrence->getMonthlyDayDays(days31, 31); |
1807 | } | 1810 | } |
1808 | const QValueList<int>* dayList() const { | 1811 | const Q3ValueList<int>* dayList() const { |
1809 | if (!varies) | 1812 | if (!varies) |
1810 | return &days31; | 1813 | return &days31; |
1811 | QDate startOfMonth(year, month + 1, 1); | 1814 | QDate startOfMonth(year, month + 1, 1); |
1812 | int daysInMonth = startOfMonth.daysInMonth(); | 1815 | int daysInMonth = startOfMonth.daysInMonth(); |
1813 | QValueList<int>* days = recurDays[daysInMonth - 28]; | 1816 | Q3ValueList<int>* days = recurDays[daysInMonth - 28]; |
1814 | if (recurrence->recurs == rMonthlyPos) | 1817 | if (recurrence->recurs == rMonthlyPos) |
1815 | recurrence->getMonthlyPosDays(*days, daysInMonth, startOfMonth.dayOfWeek()); | 1818 | recurrence->getMonthlyPosDays(*days, daysInMonth, startOfMonth.dayOfWeek()); |
1816 | else if (days->isEmpty()) | 1819 | else if (days->isEmpty()) |
1817 | recurrence->getMonthlyDayDays(*days, daysInMonth); | 1820 | recurrence->getMonthlyDayDays(*days, daysInMonth); |
1818 | return days; | 1821 | return days; |
1819 | } | 1822 | } |
@@ -1841,14 +1844,14 @@ int Recurrence::monthlyCalc(PeriodFunc func, QDate &enddate) const | |||
1841 | } | 1844 | } |
1842 | 1845 | ||
1843 | int Recurrence::monthlyCalcEndDate(QDate &enddate, MonthlyData &data) const | 1846 | int Recurrence::monthlyCalcEndDate(QDate &enddate, MonthlyData &data) const |
1844 | { | 1847 | { |
1845 | uint countTogo = rDuration + mRecurExDatesCount; | 1848 | uint countTogo = rDuration + mRecurExDatesCount; |
1846 | int countGone = 0; | 1849 | int countGone = 0; |
1847 | QValueList<int>::ConstIterator it; | 1850 | Q3ValueList<int>::ConstIterator it; |
1848 | const QValueList<int>* days = data.dayList(); | 1851 | const Q3ValueList<int>* days = data.dayList(); |
1849 | 1852 | ||
1850 | if (data.day > 1) { | 1853 | if (data.day > 1) { |
1851 | // Check what remains of the start month | 1854 | // Check what remains of the start month |
1852 | for (it = days->begin(); it != days->end(); ++it) { | 1855 | for (it = days->begin(); it != days->end(); ++it) { |
1853 | if (*it >= data.day) { | 1856 | if (*it >= data.day) { |
1854 | ++countGone; | 1857 | ++countGone; |
@@ -1907,14 +1910,14 @@ int Recurrence::monthlyCalcToDate(const QDate &enddate, MonthlyData &data) const | |||
1907 | int countGone = 0; | 1910 | int countGone = 0; |
1908 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; | 1911 | int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; |
1909 | int endYear = enddate.year(); | 1912 | int endYear = enddate.year(); |
1910 | int endMonth = enddate.month() - 1; // zero-based | 1913 | int endMonth = enddate.month() - 1; // zero-based |
1911 | int endDay = enddate.day(); | 1914 | int endDay = enddate.day(); |
1912 | int endYearMonth = endYear*12 + endMonth; | 1915 | int endYearMonth = endYear*12 + endMonth; |
1913 | QValueList<int>::ConstIterator it; | 1916 | Q3ValueList<int>::ConstIterator it; |
1914 | const QValueList<int>* days = data.dayList(); | 1917 | const Q3ValueList<int>* days = data.dayList(); |
1915 | 1918 | ||
1916 | if (data.day > 1) { | 1919 | if (data.day > 1) { |
1917 | // Check what remains of the start month | 1920 | // Check what remains of the start month |
1918 | for (it = days->begin(); it != days->end(); ++it) { | 1921 | for (it = days->begin(); it != days->end(); ++it) { |
1919 | if (*it >= data.day) { | 1922 | if (*it >= data.day) { |
1920 | if (data.yearMonth() == endYearMonth && *it > endDay) | 1923 | if (data.yearMonth() == endYearMonth && *it > endDay) |
@@ -1966,14 +1969,14 @@ int Recurrence::monthlyCalcNextAfter(QDate &enddate, MonthlyData &data) const | |||
1966 | { | 1969 | { |
1967 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; | 1970 | uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; |
1968 | int countGone = 0; | 1971 | int countGone = 0; |
1969 | int endYear = enddate.year(); | 1972 | int endYear = enddate.year(); |
1970 | int endDay = enddate.day(); | 1973 | int endDay = enddate.day(); |
1971 | int endYearMonth = endYear*12 + enddate.month() - 1; | 1974 | int endYearMonth = endYear*12 + enddate.month() - 1; |
1972 | QValueList<int>::ConstIterator it; | 1975 | Q3ValueList<int>::ConstIterator it; |
1973 | const QValueList<int>* days = data.dayList(); | 1976 | const Q3ValueList<int>* days = data.dayList(); |
1974 | 1977 | ||
1975 | if (data.day > 1) { | 1978 | if (data.day > 1) { |
1976 | // Check what remains of the start month | 1979 | // Check what remains of the start month |
1977 | for (it = days->begin(); it != days->end(); ++it) { | 1980 | for (it = days->begin(); it != days->end(); ++it) { |
1978 | if (*it >= data.day) { | 1981 | if (*it >= data.day) { |
1979 | ++countGone; | 1982 | ++countGone; |
@@ -2049,23 +2052,23 @@ struct Recurrence::YearlyMonthData { | |||
2049 | int year; // current year | 2052 | int year; // current year |
2050 | int month; // current month 1..12 | 2053 | int month; // current month 1..12 |
2051 | int day; // current day of month 1..31 | 2054 | int day; // current day of month 1..31 |
2052 | bool leapyear; // true if February 29th recurs and current year is a leap year | 2055 | bool leapyear; // true if February 29th recurs and current year is a leap year |
2053 | bool feb29; // true if February 29th recurs | 2056 | bool feb29; // true if February 29th recurs |
2054 | private: | 2057 | private: |
2055 | QValueList<int> months; // recurring months in non-leap years 1..12 | 2058 | Q3ValueList<int> months; // recurring months in non-leap years 1..12 |
2056 | QValueList<int> leapMonths; // recurring months in leap years 1..12 | 2059 | Q3ValueList<int> leapMonths; // recurring months in leap years 1..12 |
2057 | public: | 2060 | public: |
2058 | YearlyMonthData(const Recurrence* r, const QDate &date) | 2061 | YearlyMonthData(const Recurrence* r, const QDate &date) |
2059 | : recurrence(r), year(date.year()), month(date.month()), day(date.day()) | 2062 | : recurrence(r), year(date.year()), month(date.month()), day(date.day()) |
2060 | { feb29 = recurrence->getYearlyMonthMonths(day, months, leapMonths); | 2063 | { feb29 = recurrence->getYearlyMonthMonths(day, months, leapMonths); |
2061 | leapyear = feb29 && QDate::leapYear(year); | 2064 | leapyear = feb29 && QDate::leapYear(year); |
2062 | } | 2065 | } |
2063 | const QValueList<int>* monthList() const | 2066 | const Q3ValueList<int>* monthList() const |
2064 | { return leapyear ? &leapMonths : &months; } | 2067 | { return leapyear ? &leapMonths : &months; } |
2065 | const QValueList<int>* leapMonthList() const { return &leapMonths; } | 2068 | const Q3ValueList<int>* leapMonthList() const { return &leapMonths; } |
2066 | QDate date() const { return QDate(year, month, day); } | 2069 | QDate date() const { return QDate(year, month, day); } |
2067 | }; | 2070 | }; |
2068 | 2071 | ||
2069 | int Recurrence::yearlyMonthCalc(PeriodFunc func, QDate &enddate) const | 2072 | int Recurrence::yearlyMonthCalc(PeriodFunc func, QDate &enddate) const |
2070 | { | 2073 | { |
2071 | if (rYearNums.isEmpty()) | 2074 | if (rYearNums.isEmpty()) |
@@ -2085,14 +2088,14 @@ int Recurrence::yearlyMonthCalc(PeriodFunc func, QDate &enddate) const | |||
2085 | // Find total count and end date of an annual recurrence by date. | 2088 | // Find total count and end date of an annual recurrence by date. |
2086 | // Reply = total number of occurrences. | 2089 | // Reply = total number of occurrences. |
2087 | int Recurrence::yearlyMonthCalcEndDate(QDate &enddate, YearlyMonthData &data) const | 2090 | int Recurrence::yearlyMonthCalcEndDate(QDate &enddate, YearlyMonthData &data) const |
2088 | { | 2091 | { |
2089 | uint countTogo = rDuration + mRecurExDatesCount; | 2092 | uint countTogo = rDuration + mRecurExDatesCount; |
2090 | int countGone = 0; | 2093 | int countGone = 0; |
2091 | QValueList<int>::ConstIterator it; | 2094 | Q3ValueList<int>::ConstIterator it; |
2092 | const QValueList<int>* mons = data.monthList(); // get recurring months for this year | 2095 | const Q3ValueList<int>* mons = data.monthList(); // get recurring months for this year |
2093 | 2096 | ||
2094 | if (data.month > 1) { | 2097 | if (data.month > 1) { |
2095 | // Check what remains of the start year | 2098 | // Check what remains of the start year |
2096 | for (it = mons->begin(); it != mons->end(); ++it) { | 2099 | for (it = mons->begin(); it != mons->end(); ++it) { |
2097 | if (*it >= data.month) { | 2100 | if (*it >= data.month) { |
2098 | ++countGone; | 2101 | ++countGone; |
@@ -2196,14 +2199,14 @@ int Recurrence::yearlyMonthCalcToDate(const QDate &enddate, YearlyMonthData &dat | |||
2196 | } | 2199 | } |
2197 | else if (--endMonth == 0) { | 2200 | else if (--endMonth == 0) { |
2198 | endMonth = 12; | 2201 | endMonth = 12; |
2199 | --endYear; | 2202 | --endYear; |
2200 | } | 2203 | } |
2201 | } | 2204 | } |
2202 | QValueList<int>::ConstIterator it; | 2205 | Q3ValueList<int>::ConstIterator it; |
2203 | const QValueList<int>* mons = data.monthList(); | 2206 | const Q3ValueList<int>* mons = data.monthList(); |
2204 | 2207 | ||
2205 | if (data.month > 1) { | 2208 | if (data.month > 1) { |
2206 | // Check what remains of the start year | 2209 | // Check what remains of the start year |
2207 | for (it = mons->begin(); it != mons->end(); ++it) { | 2210 | for (it = mons->begin(); it != mons->end(); ++it) { |
2208 | if (*it >= data.month) { | 2211 | if (*it >= data.month) { |
2209 | if (data.year == endYear && *it > endMonth) | 2212 | if (data.year == endYear && *it > endMonth) |
@@ -2267,14 +2270,14 @@ int Recurrence::yearlyMonthCalcNextAfter(QDate &enddate, YearlyMonthData &data) | |||
2267 | feb28ok = true; | 2270 | feb28ok = true; |
2268 | else if (--endMonth == 0) { | 2271 | else if (--endMonth == 0) { |
2269 | endMonth = 12; | 2272 | endMonth = 12; |
2270 | --endYear; | 2273 | --endYear; |
2271 | } | 2274 | } |
2272 | } | 2275 | } |
2273 | QValueList<int>::ConstIterator it; | 2276 | Q3ValueList<int>::ConstIterator it; |
2274 | const QValueList<int>* mons = data.monthList(); | 2277 | const Q3ValueList<int>* mons = data.monthList(); |
2275 | 2278 | ||
2276 | if (data.month > 1) { | 2279 | if (data.month > 1) { |
2277 | // Check what remains of the start year | 2280 | // Check what remains of the start year |
2278 | for (it = mons->begin(); it != mons->end(); ++it) { | 2281 | for (it = mons->begin(); it != mons->end(); ++it) { |
2279 | if (*it >= data.month) { | 2282 | if (*it >= data.month) { |
2280 | ++countGone; | 2283 | ++countGone; |
@@ -2387,21 +2390,21 @@ struct Recurrence::YearlyPosData { | |||
2387 | int month; // current month 1..12 | 2390 | int month; // current month 1..12 |
2388 | int day; // current day of month 1..31 | 2391 | int day; // current day of month 1..31 |
2389 | int daysPerMonth; // number of days which recur each month, or -1 if variable | 2392 | int daysPerMonth; // number of days which recur each month, or -1 if variable |
2390 | int count; // number of days which recur each year, or -1 if variable | 2393 | int count; // number of days which recur each year, or -1 if variable |
2391 | bool varies; // true if number of days varies from year to year | 2394 | bool varies; // true if number of days varies from year to year |
2392 | private: | 2395 | private: |
2393 | mutable QValueList<int> days; | 2396 | mutable Q3ValueList<int> days; |
2394 | public: | 2397 | public: |
2395 | YearlyPosData(const Recurrence* r, const QDate &date) | 2398 | YearlyPosData(const Recurrence* r, const QDate &date) |
2396 | : recurrence(r), year(date.year()), month(date.month()), day(date.day()), count(-1) | 2399 | : recurrence(r), year(date.year()), month(date.month()), day(date.day()), count(-1) |
2397 | { if ((daysPerMonth = r->countMonthlyPosDays()) > 0) | 2400 | { if ((daysPerMonth = r->countMonthlyPosDays()) > 0) |
2398 | count = daysPerMonth * r->rYearNums.count(); | 2401 | count = daysPerMonth * r->rYearNums.count(); |
2399 | varies = (daysPerMonth < 0); | 2402 | varies = (daysPerMonth < 0); |
2400 | } | 2403 | } |
2401 | const QValueList<int>* dayList() const { | 2404 | const Q3ValueList<int>* dayList() const { |
2402 | QDate startOfMonth(year, month, 1); | 2405 | QDate startOfMonth(year, month, 1); |
2403 | recurrence->getMonthlyPosDays(days, startOfMonth.daysInMonth(), startOfMonth.dayOfWeek()); | 2406 | recurrence->getMonthlyPosDays(days, startOfMonth.daysInMonth(), startOfMonth.dayOfWeek()); |
2404 | return &days; | 2407 | return &days; |
2405 | } | 2408 | } |
2406 | int yearMonth() const { return year*12 + month - 1; } | 2409 | int yearMonth() const { return year*12 + month - 1; } |
2407 | void addMonths(int diff) { month += diff - 1; year += month / 12; month = month % 12 + 1; } | 2410 | void addMonths(int diff) { month += diff - 1; year += month / 12; month = month % 12 + 1; } |
@@ -2425,18 +2428,18 @@ int Recurrence::yearlyPosCalc(PeriodFunc func, QDate &enddate) const | |||
2425 | } | 2428 | } |
2426 | 2429 | ||
2427 | int Recurrence::yearlyPosCalcEndDate(QDate &enddate, YearlyPosData &data) const | 2430 | int Recurrence::yearlyPosCalcEndDate(QDate &enddate, YearlyPosData &data) const |
2428 | { | 2431 | { |
2429 | uint countTogo = rDuration + mRecurExDatesCount; | 2432 | uint countTogo = rDuration + mRecurExDatesCount; |
2430 | int countGone = 0; | 2433 | int countGone = 0; |
2431 | QValueList<int>::ConstIterator id; | 2434 | Q3ValueList<int>::ConstIterator id; |
2432 | const QValueList<int>* days; | 2435 | const Q3ValueList<int>* days; |
2433 | 2436 | ||
2434 | if (data.month > 1 || data.day > 1) { | 2437 | if (data.month > 1 || data.day > 1) { |
2435 | // Check what remains of the start year | 2438 | // Check what remains of the start year |
2436 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2439 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2437 | if (*im.current() >= data.month) { | 2440 | if (*im.current() >= data.month) { |
2438 | // Check what remains of the start month | 2441 | // Check what remains of the start month |
2439 | if (data.day > 1 || data.varies | 2442 | if (data.day > 1 || data.varies |
2440 | || static_cast<uint>(data.daysPerMonth) >= countTogo) { | 2443 | || static_cast<uint>(data.daysPerMonth) >= countTogo) { |
2441 | data.month = *im.current(); | 2444 | data.month = *im.current(); |
2442 | days = data.dayList(); | 2445 | days = data.dayList(); |
@@ -2463,13 +2466,13 @@ int Recurrence::yearlyPosCalcEndDate(QDate &enddate, YearlyPosData &data) const | |||
2463 | data.year += rFreq; | 2466 | data.year += rFreq; |
2464 | } | 2467 | } |
2465 | 2468 | ||
2466 | if (data.varies) { | 2469 | if (data.varies) { |
2467 | // The number of recurrences varies from year to year. | 2470 | // The number of recurrences varies from year to year. |
2468 | for ( ; ; ) { | 2471 | for ( ; ; ) { |
2469 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2472 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2470 | data.month = *im.current(); | 2473 | data.month = *im.current(); |
2471 | days = data.dayList(); | 2474 | days = data.dayList(); |
2472 | int n = days->count(); | 2475 | int n = days->count(); |
2473 | if (static_cast<uint>(n) >= countTogo) { | 2476 | if (static_cast<uint>(n) >= countTogo) { |
2474 | // Check the last month in the recurrence | 2477 | // Check the last month in the recurrence |
2475 | for (id = days->begin(); id != days->end(); ++id) { | 2478 | for (id = days->begin(); id != days->end(); ++id) { |
@@ -2493,13 +2496,13 @@ int Recurrence::yearlyPosCalcEndDate(QDate &enddate, YearlyPosData &data) const | |||
2493 | int wholeYears = (countTogo - 1) / data.count; | 2496 | int wholeYears = (countTogo - 1) / data.count; |
2494 | data.year += wholeYears * rFreq; | 2497 | data.year += wholeYears * rFreq; |
2495 | countGone += wholeYears * data.count; | 2498 | countGone += wholeYears * data.count; |
2496 | countTogo -= wholeYears * data.count; | 2499 | countTogo -= wholeYears * data.count; |
2497 | 2500 | ||
2498 | // Check the last year in the recurrence. | 2501 | // Check the last year in the recurrence. |
2499 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2502 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2500 | if (static_cast<uint>(data.daysPerMonth) >= countTogo) { | 2503 | if (static_cast<uint>(data.daysPerMonth) >= countTogo) { |
2501 | // Check the last month in the recurrence | 2504 | // Check the last month in the recurrence |
2502 | data.month = *im.current(); | 2505 | data.month = *im.current(); |
2503 | days = data.dayList(); | 2506 | days = data.dayList(); |
2504 | for (id = days->begin(); id != days->end(); ++id) { | 2507 | for (id = days->begin(); id != days->end(); ++id) { |
2505 | ++countGone; | 2508 | ++countGone; |
@@ -2528,18 +2531,18 @@ int Recurrence::yearlyPosCalcToDate(const QDate &enddate, YearlyPosData &data) c | |||
2528 | int endDay = enddate.day(); | 2531 | int endDay = enddate.day(); |
2529 | if (endDay < data.day && --endMonth == 0) { | 2532 | if (endDay < data.day && --endMonth == 0) { |
2530 | endMonth = 12; | 2533 | endMonth = 12; |
2531 | --endYear; | 2534 | --endYear; |
2532 | } | 2535 | } |
2533 | int endYearMonth = endYear*12 + endMonth; | 2536 | int endYearMonth = endYear*12 + endMonth; |
2534 | QValueList<int>::ConstIterator id; | 2537 | Q3ValueList<int>::ConstIterator id; |
2535 | const QValueList<int>* days; | 2538 | const Q3ValueList<int>* days; |
2536 | 2539 | ||
2537 | if (data.month > 1 || data.day > 1) { | 2540 | if (data.month > 1 || data.day > 1) { |
2538 | // Check what remains of the start year | 2541 | // Check what remains of the start year |
2539 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2542 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2540 | if (*im.current() >= data.month) { | 2543 | if (*im.current() >= data.month) { |
2541 | data.month = *im.current(); | 2544 | data.month = *im.current(); |
2542 | if (data.yearMonth() > endYearMonth) | 2545 | if (data.yearMonth() > endYearMonth) |
2543 | return countGone; | 2546 | return countGone; |
2544 | // Check what remains of the start month | 2547 | // Check what remains of the start month |
2545 | bool lastMonth = (data.yearMonth() == endYearMonth); | 2548 | bool lastMonth = (data.yearMonth() == endYearMonth); |
@@ -2573,13 +2576,13 @@ int Recurrence::yearlyPosCalcToDate(const QDate &enddate, YearlyPosData &data) c | |||
2573 | data.year += rFreq; | 2576 | data.year += rFreq; |
2574 | } | 2577 | } |
2575 | 2578 | ||
2576 | if (data.varies) { | 2579 | if (data.varies) { |
2577 | // The number of recurrences varies from year to year. | 2580 | // The number of recurrences varies from year to year. |
2578 | for ( ; ; ) { | 2581 | for ( ; ; ) { |
2579 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2582 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2580 | data.month = *im.current(); | 2583 | data.month = *im.current(); |
2581 | days = data.dayList(); | 2584 | days = data.dayList(); |
2582 | if (data.yearMonth() >= endYearMonth) { | 2585 | if (data.yearMonth() >= endYearMonth) { |
2583 | if (data.yearMonth() > endYearMonth) | 2586 | if (data.yearMonth() > endYearMonth) |
2584 | return countGone; | 2587 | return countGone; |
2585 | // Check the last month in the recurrence | 2588 | // Check the last month in the recurrence |
@@ -2608,13 +2611,13 @@ int Recurrence::yearlyPosCalcToDate(const QDate &enddate, YearlyPosData &data) c | |||
2608 | return countMax; | 2611 | return countMax; |
2609 | if (wholeYears % rFreq) | 2612 | if (wholeYears % rFreq) |
2610 | return countGone; // end year isn't a recurrence year | 2613 | return countGone; // end year isn't a recurrence year |
2611 | data.year = endYear; | 2614 | data.year = endYear; |
2612 | 2615 | ||
2613 | // Check the last year in the recurrence. | 2616 | // Check the last year in the recurrence. |
2614 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2617 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2615 | data.month = *im.current(); | 2618 | data.month = *im.current(); |
2616 | if (data.month >= endMonth) { | 2619 | if (data.month >= endMonth) { |
2617 | if (data.month > endMonth) | 2620 | if (data.month > endMonth) |
2618 | return countGone; | 2621 | return countGone; |
2619 | // Check the last month in the recurrence | 2622 | // Check the last month in the recurrence |
2620 | days = data.dayList(); | 2623 | days = data.dayList(); |
@@ -2643,20 +2646,20 @@ int Recurrence::yearlyPosCalcNextAfter(QDate &enddate, YearlyPosData &data) cons | |||
2643 | int endDay = enddate.day(); | 2646 | int endDay = enddate.day(); |
2644 | if (endDay < data.day && --endMonth == 0) { | 2647 | if (endDay < data.day && --endMonth == 0) { |
2645 | endMonth = 12; | 2648 | endMonth = 12; |
2646 | --endYear; | 2649 | --endYear; |
2647 | } | 2650 | } |
2648 | int endYearMonth = endYear*12 + endMonth; | 2651 | int endYearMonth = endYear*12 + endMonth; |
2649 | QValueList<int>::ConstIterator id; | 2652 | Q3ValueList<int>::ConstIterator id; |
2650 | const QValueList<int>* days; | 2653 | const Q3ValueList<int>* days; |
2651 | 2654 | ||
2652 | if (data.varies) { | 2655 | if (data.varies) { |
2653 | // The number of recurrences varies from year to year. | 2656 | // The number of recurrences varies from year to year. |
2654 | for ( ; ; ) { | 2657 | for ( ; ; ) { |
2655 | // Check the next year | 2658 | // Check the next year |
2656 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2659 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2657 | if (*im.current() >= data.month) { | 2660 | if (*im.current() >= data.month) { |
2658 | // Check the next month | 2661 | // Check the next month |
2659 | data.month = *im.current(); | 2662 | data.month = *im.current(); |
2660 | int ended = data.yearMonth() - endYearMonth; | 2663 | int ended = data.yearMonth() - endYearMonth; |
2661 | days = data.dayList(); | 2664 | days = data.dayList(); |
2662 | if (ended >= 0 || data.day > 1) { | 2665 | if (ended >= 0 || data.day > 1) { |
@@ -2686,13 +2689,13 @@ int Recurrence::yearlyPosCalcNextAfter(QDate &enddate, YearlyPosData &data) cons | |||
2686 | data.year += rFreq; | 2689 | data.year += rFreq; |
2687 | } | 2690 | } |
2688 | } else { | 2691 | } else { |
2689 | // The number of recurrences is the same every year. | 2692 | // The number of recurrences is the same every year. |
2690 | if (data.month > 1 || data.day > 1) { | 2693 | if (data.month > 1 || data.day > 1) { |
2691 | // Check what remains of the start year | 2694 | // Check what remains of the start year |
2692 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2695 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2693 | if (*im.current() >= data.month) { | 2696 | if (*im.current() >= data.month) { |
2694 | // Check what remains of the start month | 2697 | // Check what remains of the start month |
2695 | data.month = *im.current(); | 2698 | data.month = *im.current(); |
2696 | int ended = data.yearMonth() - endYearMonth; | 2699 | int ended = data.yearMonth() - endYearMonth; |
2697 | if (ended >= 0 || data.day > 1) { | 2700 | if (ended >= 0 || data.day > 1) { |
2698 | // This is the start or end month, so check each day | 2701 | // This is the start or end month, so check each day |
@@ -2731,13 +2734,13 @@ int Recurrence::yearlyPosCalcNextAfter(QDate &enddate, YearlyPosData &data) cons | |||
2731 | countTogo -= n; | 2734 | countTogo -= n; |
2732 | countGone += n; | 2735 | countGone += n; |
2733 | data.year += recurYears * rFreq; | 2736 | data.year += recurYears * rFreq; |
2734 | } | 2737 | } |
2735 | 2738 | ||
2736 | // Check the last year in the recurrence | 2739 | // Check the last year in the recurrence |
2737 | for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { | 2740 | for (Q3PtrListIterator<int> im(rYearNums); im.current(); ++im) { |
2738 | data.month = *im.current(); | 2741 | data.month = *im.current(); |
2739 | int ended = data.yearMonth() - endYearMonth; | 2742 | int ended = data.yearMonth() - endYearMonth; |
2740 | if (ended >= 0) { | 2743 | if (ended >= 0) { |
2741 | // This is the end month, so check each day | 2744 | // This is the end month, so check each day |
2742 | days = data.dayList(); | 2745 | days = data.dayList(); |
2743 | for (id = days->begin(); id != days->end(); ++id) { | 2746 | for (id = days->begin(); id != days->end(); ++id) { |
@@ -2805,13 +2808,13 @@ int Recurrence::yearlyDayCalcEndDate(QDate &enddate, YearlyDayData &data) const | |||
2805 | uint countTogo = rDuration + mRecurExDatesCount; | 2808 | uint countTogo = rDuration + mRecurExDatesCount; |
2806 | int countGone = 0; | 2809 | int countGone = 0; |
2807 | 2810 | ||
2808 | if (data.day > 1) { | 2811 | if (data.day > 1) { |
2809 | // Check what remains of the start year | 2812 | // Check what remains of the start year |
2810 | bool leapOK = data.isMaxDayCount(); | 2813 | bool leapOK = data.isMaxDayCount(); |
2811 | for (QPtrListIterator<int> it(rYearNums); it.current(); ++it) { | 2814 | for (Q3PtrListIterator<int> it(rYearNums); it.current(); ++it) { |
2812 | int d = *it.current(); | 2815 | int d = *it.current(); |
2813 | if (d >= data.day && (leapOK || d < 366)) { | 2816 | if (d >= data.day && (leapOK || d < 366)) { |
2814 | ++countGone; | 2817 | ++countGone; |
2815 | if (--countTogo == 0) { | 2818 | if (--countTogo == 0) { |
2816 | data.day = d; | 2819 | data.day = d; |
2817 | goto ex; | 2820 | goto ex; |
@@ -2843,13 +2846,13 @@ int Recurrence::yearlyDayCalcEndDate(QDate &enddate, YearlyDayData &data) const | |||
2843 | data.year += wholeYears * rFreq; | 2846 | data.year += wholeYears * rFreq; |
2844 | countGone += wholeYears * daysPerYear; | 2847 | countGone += wholeYears * daysPerYear; |
2845 | countTogo -= wholeYears * daysPerYear; | 2848 | countTogo -= wholeYears * daysPerYear; |
2846 | } | 2849 | } |
2847 | if (countTogo) { | 2850 | if (countTogo) { |
2848 | // Check the last year in the recurrence | 2851 | // Check the last year in the recurrence |
2849 | for (QPtrListIterator<int> it(rYearNums); it.current(); ++it) { | 2852 | for (Q3PtrListIterator<int> it(rYearNums); it.current(); ++it) { |
2850 | ++countGone; | 2853 | ++countGone; |
2851 | if (--countTogo == 0) { | 2854 | if (--countTogo == 0) { |
2852 | data.day = *it.current(); | 2855 | data.day = *it.current(); |
2853 | break; | 2856 | break; |
2854 | } | 2857 | } |
2855 | } | 2858 | } |
@@ -2866,13 +2869,13 @@ int Recurrence::yearlyDayCalcToDate(const QDate &enddate, YearlyDayData &data) c | |||
2866 | int endYear = enddate.year(); | 2869 | int endYear = enddate.year(); |
2867 | int endDay = enddate.dayOfYear(); | 2870 | int endDay = enddate.dayOfYear(); |
2868 | 2871 | ||
2869 | if (data.day > 1) { | 2872 | if (data.day > 1) { |
2870 | // Check what remains of the start year | 2873 | // Check what remains of the start year |
2871 | bool leapOK = data.isMaxDayCount(); | 2874 | bool leapOK = data.isMaxDayCount(); |
2872 | for (QPtrListIterator<int> it(rYearNums); it.current(); ++it) { | 2875 | for (Q3PtrListIterator<int> it(rYearNums); it.current(); ++it) { |
2873 | int d = *it.current(); | 2876 | int d = *it.current(); |
2874 | if (d >= data.day && (leapOK || d < 366)) { | 2877 | if (d >= data.day && (leapOK || d < 366)) { |
2875 | if (data.year == endYear && d > endDay) | 2878 | if (data.year == endYear && d > endDay) |
2876 | return countGone; | 2879 | return countGone; |
2877 | if (++countGone >= countMax) | 2880 | if (++countGone >= countMax) |
2878 | return countMax; | 2881 | return countMax; |
@@ -2905,13 +2908,13 @@ int Recurrence::yearlyDayCalcToDate(const QDate &enddate, YearlyDayData &data) c | |||
2905 | return countGone; // end year isn't a recurrence year | 2908 | return countGone; // end year isn't a recurrence year |
2906 | data.year = endYear; | 2909 | data.year = endYear; |
2907 | } | 2910 | } |
2908 | 2911 | ||
2909 | if (data.year <= endYear) { | 2912 | if (data.year <= endYear) { |
2910 | // Check the last year in the recurrence | 2913 | // Check the last year in the recurrence |
2911 | for (QPtrListIterator<int> it(rYearNums); it.current(); ++it) { | 2914 | for (Q3PtrListIterator<int> it(rYearNums); it.current(); ++it) { |
2912 | if (*it.current() > endDay) | 2915 | if (*it.current() > endDay) |
2913 | return countGone; | 2916 | return countGone; |
2914 | if (++countGone >= countMax) | 2917 | if (++countGone >= countMax) |
2915 | return countMax; | 2918 | return countMax; |
2916 | } | 2919 | } |
2917 | } | 2920 | } |
@@ -2925,13 +2928,13 @@ int Recurrence::yearlyDayCalcNextAfter(QDate &enddate, YearlyDayData &data) cons | |||
2925 | int endYear = enddate.year(); | 2928 | int endYear = enddate.year(); |
2926 | int endDay = enddate.dayOfYear(); | 2929 | int endDay = enddate.dayOfYear(); |
2927 | 2930 | ||
2928 | if (data.day > 1) { | 2931 | if (data.day > 1) { |
2929 | // Check what remains of the start year | 2932 | // Check what remains of the start year |
2930 | bool leapOK = data.isMaxDayCount(); | 2933 | bool leapOK = data.isMaxDayCount(); |
2931 | for (QPtrListIterator<int> it(rYearNums); it.current(); ++it) { | 2934 | for (Q3PtrListIterator<int> it(rYearNums); it.current(); ++it) { |
2932 | int d = *it.current(); | 2935 | int d = *it.current(); |
2933 | if (d >= data.day && (leapOK || d < 366)) { | 2936 | if (d >= data.day && (leapOK || d < 366)) { |
2934 | ++countGone; | 2937 | ++countGone; |
2935 | if (data.year == endYear && d > endDay) { | 2938 | if (data.year == endYear && d > endDay) { |
2936 | data.day = d; | 2939 | data.day = d; |
2937 | goto ex; | 2940 | goto ex; |
@@ -2974,13 +2977,13 @@ int Recurrence::yearlyDayCalcNextAfter(QDate &enddate, YearlyDayData &data) cons | |||
2974 | countGone += n; | 2977 | countGone += n; |
2975 | data.year += recurYears * rFreq; | 2978 | data.year += recurYears * rFreq; |
2976 | } | 2979 | } |
2977 | } | 2980 | } |
2978 | 2981 | ||
2979 | // Check the last year in the recurrence | 2982 | // Check the last year in the recurrence |
2980 | for (QPtrListIterator<int> it(rYearNums); it.current(); ++it) { | 2983 | for (Q3PtrListIterator<int> it(rYearNums); it.current(); ++it) { |
2981 | ++countGone; | 2984 | ++countGone; |
2982 | int d = *it.current(); | 2985 | int d = *it.current(); |
2983 | if (data.year > endYear || d > endDay) { | 2986 | if (data.year > endYear || d > endDay) { |
2984 | data.day = d; | 2987 | data.day = d; |
2985 | break; | 2988 | break; |
2986 | } | 2989 | } |
@@ -2992,19 +2995,19 @@ ex: | |||
2992 | return countGone; | 2995 | return countGone; |
2993 | } | 2996 | } |
2994 | 2997 | ||
2995 | // Get the days in this month which recur, in numerical order. | 2998 | // Get the days in this month which recur, in numerical order. |
2996 | // Parameters: daysInMonth = number of days in this month | 2999 | // Parameters: daysInMonth = number of days in this month |
2997 | // startDayOfWeek = day of week for first day of month. | 3000 | // startDayOfWeek = day of week for first day of month. |
2998 | void Recurrence::getMonthlyPosDays(QValueList<int> &list, int daysInMonth, int startDayOfWeek) const | 3001 | void Recurrence::getMonthlyPosDays(Q3ValueList<int> &list, int daysInMonth, int startDayOfWeek) const |
2999 | { | 3002 | { |
3000 | list.clear(); | 3003 | list.clear(); |
3001 | int endDayOfWeek = (startDayOfWeek + daysInMonth - 2) % 7 + 1; | 3004 | int endDayOfWeek = (startDayOfWeek + daysInMonth - 2) % 7 + 1; |
3002 | // Go through the list, compiling a bit list of actual day numbers | 3005 | // Go through the list, compiling a bit list of actual day numbers |
3003 | Q_UINT32 days = 0; | 3006 | Q_UINT32 days = 0; |
3004 | for (QPtrListIterator<rMonthPos> pos(rMonthPositions); pos.current(); ++pos) { | 3007 | for (Q3PtrListIterator<rMonthPos> pos(rMonthPositions); pos.current(); ++pos) { |
3005 | int weeknum = pos.current()->rPos - 1; // get 0-based week number | 3008 | int weeknum = pos.current()->rPos - 1; // get 0-based week number |
3006 | QBitArray &rdays = pos.current()->rDays; | 3009 | QBitArray &rdays = pos.current()->rDays; |
3007 | if (pos.current()->negative) { | 3010 | if (pos.current()->negative) { |
3008 | // nth days before the end of the month | 3011 | // nth days before the end of the month |
3009 | for (uint i = 1; i <= 7; ++i) { | 3012 | for (uint i = 1; i <= 7; ++i) { |
3010 | if (rdays.testBit(i - 1)) { | 3013 | if (rdays.testBit(i - 1)) { |
@@ -3036,13 +3039,13 @@ void Recurrence::getMonthlyPosDays(QValueList<int> &list, int daysInMonth, int s | |||
3036 | // Reply = -1 if the number varies from month to month. | 3039 | // Reply = -1 if the number varies from month to month. |
3037 | int Recurrence::countMonthlyPosDays() const | 3040 | int Recurrence::countMonthlyPosDays() const |
3038 | { | 3041 | { |
3039 | int count = 0; | 3042 | int count = 0; |
3040 | Q_UINT8 positive[5] = { 0, 0, 0, 0, 0 }; | 3043 | Q_UINT8 positive[5] = { 0, 0, 0, 0, 0 }; |
3041 | Q_UINT8 negative[4] = { 0, 0, 0, 0 }; | 3044 | Q_UINT8 negative[4] = { 0, 0, 0, 0 }; |
3042 | for (QPtrListIterator<rMonthPos> pos(rMonthPositions); pos.current(); ++pos) { | 3045 | for (Q3PtrListIterator<rMonthPos> pos(rMonthPositions); pos.current(); ++pos) { |
3043 | int weeknum = pos.current()->rPos; | 3046 | int weeknum = pos.current()->rPos; |
3044 | Q_UINT8* wk; | 3047 | Q_UINT8* wk; |
3045 | if (pos.current()->negative) { | 3048 | if (pos.current()->negative) { |
3046 | // nth days before the end of the month | 3049 | // nth days before the end of the month |
3047 | if (weeknum > 4) | 3050 | if (weeknum > 4) |
3048 | return -1; // days in 5th week are often missing | 3051 | return -1; // days in 5th week are often missing |
@@ -3069,18 +3072,18 @@ int Recurrence::countMonthlyPosDays() const | |||
3069 | } | 3072 | } |
3070 | return count; | 3073 | return count; |
3071 | } | 3074 | } |
3072 | 3075 | ||
3073 | // Get the days in this month which recur, in numerical order. | 3076 | // Get the days in this month which recur, in numerical order. |
3074 | // Reply = true if day numbers varies from month to month. | 3077 | // Reply = true if day numbers varies from month to month. |
3075 | bool Recurrence::getMonthlyDayDays(QValueList<int> &list, int daysInMonth) const | 3078 | bool Recurrence::getMonthlyDayDays(Q3ValueList<int> &list, int daysInMonth) const |
3076 | { | 3079 | { |
3077 | list.clear(); | 3080 | list.clear(); |
3078 | bool variable = false; | 3081 | bool variable = false; |
3079 | Q_UINT32 days = 0; | 3082 | Q_UINT32 days = 0; |
3080 | for (QPtrListIterator<int> it(rMonthDays); it.current(); ++it) { | 3083 | for (Q3PtrListIterator<int> it(rMonthDays); it.current(); ++it) { |
3081 | int day = *it.current(); | 3084 | int day = *it.current(); |
3082 | if (day > 0) { | 3085 | if (day > 0) { |
3083 | // date in the month | 3086 | // date in the month |
3084 | if (day <= daysInMonth) | 3087 | if (day <= daysInMonth) |
3085 | days |= 1 << (day - 1); | 3088 | days |= 1 << (day - 1); |
3086 | if (day > 28 && day <= 31) | 3089 | if (day > 28 && day <= 31) |
@@ -3103,18 +3106,18 @@ bool Recurrence::getMonthlyDayDays(QValueList<int> &list, int daysInMonth) const | |||
3103 | } | 3106 | } |
3104 | 3107 | ||
3105 | // Get the months which recur, in numerical order, for both leap years and non-leap years. | 3108 | // Get the months which recur, in numerical order, for both leap years and non-leap years. |
3106 | // N.B. If February 29th recurs on March 1st in non-leap years, February (not March) is | 3109 | // N.B. If February 29th recurs on March 1st in non-leap years, February (not March) is |
3107 | // included in the non-leap year month list. | 3110 | // included in the non-leap year month list. |
3108 | // Reply = true if February 29th also recurs. | 3111 | // Reply = true if February 29th also recurs. |
3109 | bool Recurrence::getYearlyMonthMonths(int day, QValueList<int> &list, QValueList<int> &leaplist) const | 3112 | bool Recurrence::getYearlyMonthMonths(int day, Q3ValueList<int> &list, Q3ValueList<int> &leaplist) const |
3110 | { | 3113 | { |
3111 | list.clear(); | 3114 | list.clear(); |
3112 | leaplist.clear(); | 3115 | leaplist.clear(); |
3113 | bool feb29 = false; | 3116 | bool feb29 = false; |
3114 | for (QPtrListIterator<int> it(rYearNums); it.current(); ++it) { | 3117 | for (Q3PtrListIterator<int> it(rYearNums); it.current(); ++it) { |
3115 | int month = *it.current(); | 3118 | int month = *it.current(); |
3116 | if (month == 2) { | 3119 | if (month == 2) { |
3117 | if (day <= 28) { | 3120 | if (day <= 28) { |
3118 | list.append(month); // date appears in February | 3121 | list.append(month); // date appears in February |
3119 | leaplist.append(month); | 3122 | leaplist.append(month); |
3120 | } | 3123 | } |
@@ -3184,13 +3187,13 @@ QDate Recurrence::getFirstDateInMonth(const QDate &earliestDate) const | |||
3184 | { | 3187 | { |
3185 | int earliestDay = earliestDate.day(); | 3188 | int earliestDay = earliestDate.day(); |
3186 | int daysInMonth = earliestDate.daysInMonth(); | 3189 | int daysInMonth = earliestDate.daysInMonth(); |
3187 | switch (recurs) { | 3190 | switch (recurs) { |
3188 | case rMonthlyDay: { | 3191 | case rMonthlyDay: { |
3189 | int minday = daysInMonth + 1; | 3192 | int minday = daysInMonth + 1; |
3190 | for (QPtrListIterator<int> it(rMonthDays); it.current(); ++it) { | 3193 | for (Q3PtrListIterator<int> it(rMonthDays); it.current(); ++it) { |
3191 | int day = *it.current(); | 3194 | int day = *it.current(); |
3192 | if (day < 0) | 3195 | if (day < 0) |
3193 | day = daysInMonth + day + 1; | 3196 | day = daysInMonth + day + 1; |
3194 | if (day >= earliestDay && day < minday) | 3197 | if (day >= earliestDay && day < minday) |
3195 | minday = day; | 3198 | minday = day; |
3196 | } | 3199 | } |
@@ -3198,15 +3201,15 @@ QDate Recurrence::getFirstDateInMonth(const QDate &earliestDate) const | |||
3198 | return earliestDate.addDays(minday - earliestDay); | 3201 | return earliestDate.addDays(minday - earliestDay); |
3199 | break; | 3202 | break; |
3200 | } | 3203 | } |
3201 | case rMonthlyPos: | 3204 | case rMonthlyPos: |
3202 | case rYearlyPos: { | 3205 | case rYearlyPos: { |
3203 | QDate monthBegin(earliestDate.addDays(1 - earliestDay)); | 3206 | QDate monthBegin(earliestDate.addDays(1 - earliestDay)); |
3204 | QValueList<int> dayList; | 3207 | Q3ValueList<int> dayList; |
3205 | getMonthlyPosDays(dayList, daysInMonth, monthBegin.dayOfWeek()); | 3208 | getMonthlyPosDays(dayList, daysInMonth, monthBegin.dayOfWeek()); |
3206 | for (QValueList<int>::ConstIterator id = dayList.begin(); id != dayList.end(); ++id) { | 3209 | for (Q3ValueList<int>::ConstIterator id = dayList.begin(); id != dayList.end(); ++id) { |
3207 | if (*id >= earliestDay) | 3210 | if (*id >= earliestDay) |
3208 | return monthBegin.addDays(*id - 1); | 3211 | return monthBegin.addDays(*id - 1); |
3209 | } | 3212 | } |
3210 | break; | 3213 | break; |
3211 | } | 3214 | } |
3212 | } | 3215 | } |
@@ -3221,13 +3224,13 @@ QDate Recurrence::getLastDateInMonth(const QDate &latestDate) const | |||
3221 | { | 3224 | { |
3222 | int latestDay = latestDate.day(); | 3225 | int latestDay = latestDate.day(); |
3223 | int daysInMonth = latestDate.daysInMonth(); | 3226 | int daysInMonth = latestDate.daysInMonth(); |
3224 | switch (recurs) { | 3227 | switch (recurs) { |
3225 | case rMonthlyDay: { | 3228 | case rMonthlyDay: { |
3226 | int maxday = -1; | 3229 | int maxday = -1; |
3227 | for (QPtrListIterator<int> it(rMonthDays); it.current(); ++it) { | 3230 | for (Q3PtrListIterator<int> it(rMonthDays); it.current(); ++it) { |
3228 | int day = *it.current(); | 3231 | int day = *it.current(); |
3229 | if (day < 0) | 3232 | if (day < 0) |
3230 | day = daysInMonth + day + 1; | 3233 | day = daysInMonth + day + 1; |
3231 | if (day <= latestDay && day > maxday) | 3234 | if (day <= latestDay && day > maxday) |
3232 | maxday = day; | 3235 | maxday = day; |
3233 | } | 3236 | } |
@@ -3235,15 +3238,15 @@ QDate Recurrence::getLastDateInMonth(const QDate &latestDate) const | |||
3235 | return QDate(latestDate.year(), latestDate.month(), maxday); | 3238 | return QDate(latestDate.year(), latestDate.month(), maxday); |
3236 | break; | 3239 | break; |
3237 | } | 3240 | } |
3238 | case rMonthlyPos: | 3241 | case rMonthlyPos: |
3239 | case rYearlyPos: { | 3242 | case rYearlyPos: { |
3240 | QDate monthBegin(latestDate.addDays(1 - latestDay)); | 3243 | QDate monthBegin(latestDate.addDays(1 - latestDay)); |
3241 | QValueList<int> dayList; | 3244 | Q3ValueList<int> dayList; |
3242 | getMonthlyPosDays(dayList, daysInMonth, monthBegin.dayOfWeek()); | 3245 | getMonthlyPosDays(dayList, daysInMonth, monthBegin.dayOfWeek()); |
3243 | for (QValueList<int>::ConstIterator id = dayList.fromLast(); id != dayList.end(); --id) { | 3246 | for (Q3ValueList<int>::ConstIterator id = dayList.fromLast(); id != dayList.end(); --id) { |
3244 | if (*id <= latestDay) | 3247 | if (*id <= latestDay) |
3245 | return monthBegin.addDays(*id - 1); | 3248 | return monthBegin.addDays(*id - 1); |
3246 | } | 3249 | } |
3247 | break; | 3250 | break; |
3248 | } | 3251 | } |
3249 | } | 3252 | } |
@@ -3253,13 +3256,13 @@ QDate Recurrence::getLastDateInMonth(const QDate &latestDate) const | |||
3253 | /* From the recurrence yearly month list or yearly day list, get the earliest | 3256 | /* From the recurrence yearly month list or yearly day list, get the earliest |
3254 | * month or day in the specified year which is >= the earliestDate. | 3257 | * month or day in the specified year which is >= the earliestDate. |
3255 | * Note that rYearNums is sorted in numerical order. | 3258 | * Note that rYearNums is sorted in numerical order. |
3256 | */ | 3259 | */ |
3257 | QDate Recurrence::getFirstDateInYear(const QDate &earliestDate) const | 3260 | QDate Recurrence::getFirstDateInYear(const QDate &earliestDate) const |
3258 | { | 3261 | { |
3259 | QPtrListIterator<int> it(rYearNums); | 3262 | Q3PtrListIterator<int> it(rYearNums); |
3260 | switch (recurs) { | 3263 | switch (recurs) { |
3261 | case rYearlyMonth: { | 3264 | case rYearlyMonth: { |
3262 | int day = recurStart().date().day(); | 3265 | int day = recurStart().date().day(); |
3263 | int earliestYear = earliestDate.year(); | 3266 | int earliestYear = earliestDate.year(); |
3264 | int earliestMonth = earliestDate.month(); | 3267 | int earliestMonth = earliestDate.month(); |
3265 | int earliestDay = earliestDate.day(); | 3268 | int earliestDay = earliestDate.day(); |
@@ -3289,22 +3292,22 @@ QDate Recurrence::getFirstDateInYear(const QDate &earliestDate) const | |||
3289 | } | 3292 | } |
3290 | } | 3293 | } |
3291 | } | 3294 | } |
3292 | break; | 3295 | break; |
3293 | } | 3296 | } |
3294 | case rYearlyPos: { | 3297 | case rYearlyPos: { |
3295 | QValueList<int> dayList; | 3298 | Q3ValueList<int> dayList; |
3296 | int earliestYear = earliestDate.year(); | 3299 | int earliestYear = earliestDate.year(); |
3297 | int earliestMonth = earliestDate.month(); | 3300 | int earliestMonth = earliestDate.month(); |
3298 | int earliestDay = earliestDate.day(); | 3301 | int earliestDay = earliestDate.day(); |
3299 | for ( ; it.current(); ++it) { | 3302 | for ( ; it.current(); ++it) { |
3300 | int month = *it.current(); | 3303 | int month = *it.current(); |
3301 | if (month >= earliestMonth) { | 3304 | if (month >= earliestMonth) { |
3302 | QDate monthBegin(earliestYear, month, 1); | 3305 | QDate monthBegin(earliestYear, month, 1); |
3303 | getMonthlyPosDays(dayList, monthBegin.daysInMonth(), monthBegin.dayOfWeek()); | 3306 | getMonthlyPosDays(dayList, monthBegin.daysInMonth(), monthBegin.dayOfWeek()); |
3304 | for (QValueList<int>::ConstIterator id = dayList.begin(); id != dayList.end(); ++id) { | 3307 | for (Q3ValueList<int>::ConstIterator id = dayList.begin(); id != dayList.end(); ++id) { |
3305 | if (*id >= earliestDay) | 3308 | if (*id >= earliestDay) |
3306 | return monthBegin.addDays(*id - 1); | 3309 | return monthBegin.addDays(*id - 1); |
3307 | } | 3310 | } |
3308 | earliestDay = 1; | 3311 | earliestDay = 1; |
3309 | } | 3312 | } |
3310 | } | 3313 | } |
@@ -3326,13 +3329,13 @@ QDate Recurrence::getFirstDateInYear(const QDate &earliestDate) const | |||
3326 | /* From the recurrence yearly month list or yearly day list, get the latest | 3329 | /* From the recurrence yearly month list or yearly day list, get the latest |
3327 | * month or day in the specified year which is <= the latestDate. | 3330 | * month or day in the specified year which is <= the latestDate. |
3328 | * Note that rYearNums is sorted in numerical order. | 3331 | * Note that rYearNums is sorted in numerical order. |
3329 | */ | 3332 | */ |
3330 | QDate Recurrence::getLastDateInYear(const QDate &latestDate) const | 3333 | QDate Recurrence::getLastDateInYear(const QDate &latestDate) const |
3331 | { | 3334 | { |
3332 | QPtrListIterator<int> it(rYearNums); | 3335 | Q3PtrListIterator<int> it(rYearNums); |
3333 | switch (recurs) { | 3336 | switch (recurs) { |
3334 | case rYearlyMonth: { | 3337 | case rYearlyMonth: { |
3335 | int day = recurStart().date().day(); | 3338 | int day = recurStart().date().day(); |
3336 | int latestYear = latestDate.year(); | 3339 | int latestYear = latestDate.year(); |
3337 | int latestMonth = latestDate.month(); | 3340 | int latestMonth = latestDate.month(); |
3338 | if (latestDate.day() > day) { | 3341 | if (latestDate.day() > day) { |
@@ -3361,22 +3364,22 @@ QDate Recurrence::getLastDateInYear(const QDate &latestDate) const | |||
3361 | } | 3364 | } |
3362 | } | 3365 | } |
3363 | } | 3366 | } |
3364 | break; | 3367 | break; |
3365 | } | 3368 | } |
3366 | case rYearlyPos: { | 3369 | case rYearlyPos: { |
3367 | QValueList<int> dayList; | 3370 | Q3ValueList<int> dayList; |
3368 | int latestYear = latestDate.year(); | 3371 | int latestYear = latestDate.year(); |
3369 | int latestMonth = latestDate.month(); | 3372 | int latestMonth = latestDate.month(); |
3370 | int latestDay = latestDate.day(); | 3373 | int latestDay = latestDate.day(); |
3371 | for (it.toLast(); it.current(); --it) { | 3374 | for (it.toLast(); it.current(); --it) { |
3372 | int month = *it.current(); | 3375 | int month = *it.current(); |
3373 | if (month <= latestMonth) { | 3376 | if (month <= latestMonth) { |
3374 | QDate monthBegin(latestYear, month, 1); | 3377 | QDate monthBegin(latestYear, month, 1); |
3375 | getMonthlyPosDays(dayList, monthBegin.daysInMonth(), monthBegin.dayOfWeek()); | 3378 | getMonthlyPosDays(dayList, monthBegin.daysInMonth(), monthBegin.dayOfWeek()); |
3376 | for (QValueList<int>::ConstIterator id = dayList.fromLast(); id != dayList.end(); --id) { | 3379 | for (Q3ValueList<int>::ConstIterator id = dayList.fromLast(); id != dayList.end(); --id) { |
3377 | if (*id <= latestDay) | 3380 | if (*id <= latestDay) |
3378 | return monthBegin.addDays(*id - 1); | 3381 | return monthBegin.addDays(*id - 1); |
3379 | } | 3382 | } |
3380 | latestDay = 31; | 3383 | latestDay = 31; |
3381 | } | 3384 | } |
3382 | } | 3385 | } |