35
39
class KALARM_CAL_EXPORT Repetition
38
Repetition() : mInterval(0), mCount(0) {}
39
Repetition(const KCal::Duration& interval, int count)
40
: mInterval(interval), mCount(count)
42
if ((!count && interval) || (count && !interval))
49
void set(const KCal::Duration& interval, int count)
51
if (!count || !interval)
63
void set(const KCal::Duration& interval)
73
operator bool() const { return mCount; }
74
bool operator!() const { return !mCount; }
75
bool operator==(const Repetition& r) const { return mInterval == r.mInterval && mCount == r.mCount; }
76
bool operator!=(const Repetition& r) const { return mInterval != r.mInterval || mCount != r.mCount; }
78
/** Return the number of repetitions. */
79
int count() const { return mCount; }
81
/** Return the interval between repetitions. */
82
const KCal::Duration& interval() const { return mInterval; }
84
/** Return the overall duration of the repetition. */
85
KCal::Duration duration() const { return mInterval * mCount; }
87
/** Return the overall duration of a specified number of repetitions.
88
* @param count the number of repetitions to find the duration of.
90
KCal::Duration duration(int count) const { return mInterval * count; }
92
/** Check whether the repetition interval is in terms of days (as opposed to minutes). */
93
bool isDaily() const { return mInterval.isDaily(); }
95
/** Return the repetition interval in terms of days.
96
* If necessary, the interval is rounded down to a whole number of days.
98
int intervalDays() const { return mInterval.asDays(); }
100
/** Return the repetition interval in terms of minutes.
101
* If necessary, the interval is rounded down to a whole number of minutes.
103
int intervalMinutes() const { return mInterval.asSeconds() / 60; }
105
/** Return the repetition interval in terms of seconds. */
106
int intervalSeconds() const { return mInterval.asSeconds(); }
108
/** Find the repetition count for the next repetition after a specified time.
109
* @param from repetition start time, which should not be a date-only value
110
* @param preDateTime time after which the desired repetition occurs
112
int nextRepeatCount(const KDateTime& from, const KDateTime& preDateTime) const
114
return mInterval.isDaily()
115
? from.daysTo(preDateTime) / mInterval.asDays() + 1
116
: static_cast<int>(from.secsTo_long(preDateTime) / mInterval.asSeconds()) + 1;
119
/** Find the repetition count for the last repetition before a specified time.
120
* @param from repetition start time, which should not be a date-only value
121
* @param afterDateTime time after which the desired repetition occurs
123
int previousRepeatCount(const KDateTime& from, const KDateTime& afterDateTime) const
125
return mInterval.isDaily()
126
? from.daysTo(afterDateTime.addSecs(-1)) / mInterval.asDays()
127
: static_cast<int>((from.secsTo_long(afterDateTime) - 1) / mInterval.asSeconds());
42
Repetition() : mInterval(0), mCount(0) {}
44
Repetition(const KCalCore::Duration& interval, int count)
46
Repetition(const KCal::Duration& interval, int count)
48
: mInterval(interval), mCount(count)
50
if ((!count && interval) || (count && !interval))
58
void set(const KCalCore::Duration& interval, int count)
60
void set(const KCal::Duration& interval, int count)
63
if (!count || !interval)
76
void set(const KCalCore::Duration& interval)
78
void set(const KCal::Duration& interval)
89
operator bool() const { return mCount; }
90
bool operator!() const { return !mCount; }
91
bool operator==(const Repetition& r) const { return mInterval == r.mInterval && mCount == r.mCount; }
92
bool operator!=(const Repetition& r) const { return mInterval != r.mInterval || mCount != r.mCount; }
94
/** Return the number of repetitions. */
95
int count() const { return mCount; }
98
/** Return the interval between repetitions. */
99
const KCalCore::Duration& interval() const { return mInterval; }
101
/** Return the overall duration of the repetition. */
102
KCalCore::Duration duration() const { return mInterval * mCount; }
104
/** Return the overall duration of a specified number of repetitions.
105
* @param count the number of repetitions to find the duration of.
107
KCalCore::Duration duration(int count) const { return mInterval * count; }
109
/** Return the interval between repetitions. */
110
const KCal::Duration& interval() const { return mInterval; }
112
/** Return the overall duration of the repetition. */
113
KCal::Duration duration() const { return mInterval * mCount; }
115
/** Return the overall duration of a specified number of repetitions.
116
* @param count the number of repetitions to find the duration of.
118
KCal::Duration duration(int count) const { return mInterval * count; }
121
/** Check whether the repetition interval is in terms of days (as opposed to minutes). */
122
bool isDaily() const { return mInterval.isDaily(); }
124
/** Return the repetition interval in terms of days.
125
* If necessary, the interval is rounded down to a whole number of days.
127
int intervalDays() const { return mInterval.asDays(); }
129
/** Return the repetition interval in terms of minutes.
130
* If necessary, the interval is rounded down to a whole number of minutes.
132
int intervalMinutes() const { return mInterval.asSeconds() / 60; }
134
/** Return the repetition interval in terms of seconds. */
135
int intervalSeconds() const { return mInterval.asSeconds(); }
137
/** Find the repetition count for the next repetition after a specified time.
138
* @param from repetition start time, which should not be a date-only value
139
* @param preDateTime time after which the desired repetition occurs
141
int nextRepeatCount(const KDateTime& from, const KDateTime& preDateTime) const
143
return mInterval.isDaily()
144
? from.daysTo(preDateTime) / mInterval.asDays() + 1
145
: static_cast<int>(from.secsTo_long(preDateTime) / mInterval.asSeconds()) + 1;
148
/** Find the repetition count for the last repetition before a specified time.
149
* @param from repetition start time, which should not be a date-only value
150
* @param afterDateTime time after which the desired repetition occurs
152
int previousRepeatCount(const KDateTime& from, const KDateTime& afterDateTime) const
154
return mInterval.isDaily()
155
? from.daysTo(afterDateTime.addSecs(-1)) / mInterval.asDays()
156
: static_cast<int>((from.secsTo_long(afterDateTime) - 1) / mInterval.asSeconds());
131
KCal::Duration mInterval; // sub-repetition interval
132
int mCount; // sub-repetition count (excluding the first time)
161
KCalCore::Duration mInterval; // sub-repetition interval
163
KCal::Duration mInterval; // sub-repetition interval
165
int mCount; // sub-repetition count (excluding the first time)
135
168
#endif // REPETITION_H