24 #ifndef KCAL_RECURRENCERULE_H
25 #define KCAL_RECURRENCERULE_H
27 #include <tqdatetime.h>
28 #include <libkcal/listbase.h>
30 #include "libkcal_export.h"
33 TQ_INLINE_TEMPLATES
void qSortUnique( TQValueList<T> &lst )
36 if ( lst.isEmpty() )
return;
39 TQValueListIterator<T> it = lst.begin();
43 while ( it != lst.end() ) {
45 if ( newlast == last ) it = lst.remove( it );
54 TQ_INLINE_TEMPLATES
int findGE(
const TQValueList<T> &lst,
const T &value,
int start )
58 int end = lst.count();
59 while ( end - st > 1 ) {
60 int i = ( st + end ) / 2;
61 if ( value <= lst[i] ) {
68 return ( st ==
int( lst.count() ) ) ? -1 : st;
72 TQ_INLINE_TEMPLATES
int findGT(
const TQValueList<T> &lst,
const T &value,
int start )
76 int end = lst.count();
77 while ( end - st > 1 ) {
78 int i = ( st + end ) / 2;
79 if ( value < lst[i] ) {
86 return ( st ==
int( lst.count() ) ) ? -1 : st;
90 TQ_INLINE_TEMPLATES
int findLE(
const TQValueList<T> &lst,
const T &value,
int start )
94 int end = lst.count();
95 while ( end - st > 1 ) {
96 int i = ( st + end ) / 2;
97 if ( value < lst[i] ) {
103 return ( end > start ) ? st : -1;
107 TQ_INLINE_TEMPLATES
int findLT(
const TQValueList<T> &lst,
const T &value,
int start )
111 int end = lst.count();
112 while ( end - st > 1 ) {
113 int i = ( st + end ) / 2;
114 if ( value <= lst[i] ) {
120 return ( end > start ) ? st : -1;
124 TQ_INLINE_TEMPLATES
int findSorted(
const TQValueList<T> &lst,
const T &value,
int start )
128 int end = lst.count();
129 while ( end - st > 1 ) {
130 int i = ( st + end ) / 2;
131 if ( value < lst[i] ) {
137 return ( end > start && value == lst[st] ) ? st : -1;
141 TQ_INLINE_TEMPLATES
int removeSorted( TQValueList<T> &lst,
const T &value,
int start )
143 int i = findSorted( lst, value, start );
145 lst.remove( lst.at( i ) );
151 TQ_INLINE_TEMPLATES
bool containsSorted(
const TQValueList<T> &lst,
const T &value )
153 return findSorted( lst, value, 0 ) >= 0;
159 typedef TQValueList<TQDateTime> DateTimeList;
160 typedef TQValueList<TQDate> DateList;
161 typedef TQValueList<TQTime> TimeList;
174 virtual ~Observer() {}
181 rSecondly, rMinutely, rHourly,
182 rDaily, rWeekly, rMonthly, rYearly
187 WDayPos(
int ps = 0 ,
short dy = 0 ) : mDay(dy), mPos(ps) {}
188 short day()
const {
return mDay; }
189 int pos()
const {
return mPos; }
190 void setDay(
short dy ) { mDay = dy; }
191 void setPos(
int ps ) { mPos = ps; }
194 return ( mDay == pos2.mDay ) && ( mPos == pos2.mPos );
207 bool operator!=(
const RecurrenceRule& r )
const {
return !operator==(r); }
222 void setRecurrenceType( PeriodType period );
223 PeriodType recurrenceType()
const {
return mPeriod; }
231 void setFrequency(
int freq );
235 TQDateTime
startDt()
const {
return mDateStart; }
237 void setStartDt(
const TQDateTime &start);
243 void setFloats(
bool floats );
251 TQDateTime endDt(
bool* result = 0 )
const;
254 void setEndDt(
const TQDateTime &endDateTime);
264 void setDuration(
int duration);
268 int durationTo(
const TQDateTime &)
const;
276 bool recursOn(
const TQDate &qd )
const;
280 bool recursAt(
const TQDateTime & )
const;
285 bool dateMatchesRules(
const TQDateTime &qdt )
const;
292 TimeList recurTimesOn(
const TQDate &date )
const;
305 DateTimeList timesInInterval(
const TQDateTime &start,
const TQDateTime &end )
const;
312 TQDateTime getNextDate(
const TQDateTime& preDateTime )
const;
319 TQDateTime getPreviousDate(
const TQDateTime& afterDateTime )
const;
324 void setBySeconds(
const TQValueList<int> bySeconds );
325 void setByMinutes(
const TQValueList<int> byMinutes );
326 void setByHours(
const TQValueList<int> byHours );
328 void setByDays(
const TQValueList<WDayPos> byDays );
329 void setByMonthDays(
const TQValueList<int> byMonthDays );
330 void setByYearDays(
const TQValueList<int> byYearDays );
331 void setByWeekNumbers(
const TQValueList<int> byWeekNumbers );
332 void setByMonths(
const TQValueList<int> byMonths );
333 void setBySetPos(
const TQValueList<int> bySetPos );
334 void setWeekStart(
short weekStart );
336 const TQValueList<int> &bySeconds()
const {
return mBySeconds; }
337 const TQValueList<int> &byMinutes()
const {
return mByMinutes; }
338 const TQValueList<int> &byHours()
const {
return mByHours; }
340 const TQValueList<WDayPos> &byDays()
const {
return mByDays; }
341 const TQValueList<int> &byMonthDays()
const {
return mByMonthDays; }
342 const TQValueList<int> &byYearDays()
const {
return mByYearDays; }
343 const TQValueList<int> &byWeekNumbers()
const {
return mByWeekNumbers; }
344 const TQValueList<int> &byMonths()
const {
return mByMonths; }
345 const TQValueList<int> &bySetPos()
const {
return mBySetPos; }
346 short weekStart()
const {
return mWeekStart; }
357 void addObserver( Observer *observer );
364 void removeObserver( Observer *observer );
375 typedef TQValueList<Constraint> List;
377 Constraint(
int wkst = 1 );
383 Constraint(
const TQDateTime &preDate, PeriodType type,
int wkst );
398 bool readDateTime(
const TQDateTime &preDate, PeriodType type );
401 bool isConsistent()
const;
402 bool isConsistent( PeriodType period )
const;
403 bool increase( PeriodType type,
int freq );
404 TQDateTime intervalDateTime( PeriodType type )
const;
405 DateTimeList dateTimes( PeriodType type )
const;
409 Constraint getNextValidDateInterval(
const TQDateTime &preDate, PeriodType type )
const;
410 Constraint getPreviousValidDateInterval(
const TQDateTime &preDate, PeriodType type )
const;
411 DateTimeList datesForInterval(
const Constraint &interval, PeriodType type )
const;
412 bool mergeIntervalConstraint( Constraint *merged,
const Constraint &conit,
413 const Constraint &interval )
const;
414 bool buildCache()
const;
418 TQDateTime mDateStart;
430 TQValueList<int> mBySeconds;
431 TQValueList<int> mByMinutes;
432 TQValueList<int> mByHours;
434 TQValueList<WDayPos> mByDays;
435 TQValueList<int> mByMonthDays;
436 TQValueList<int> mByYearDays;
437 TQValueList<int> mByWeekNumbers;
438 TQValueList<int> mByMonths;
439 TQValueList<int> mBySetPos;
442 Constraint::List mConstraints;
443 void buildConstraints();
445 TQValueList<Observer*> mObservers;
448 mutable DateTimeList mCachedDates;
449 mutable TQDateTime mCachedDateEnd;
450 mutable TQDateTime mCachedLastDate;
451 mutable bool mCached;
454 uint mTimedRepetition;