RecurrenceRule *Recurrence::defaultRRule( bool create ) const { if ( d->mRRules.isEmpty() ) { if ( !create || d->mRecurReadOnly ) { return 0; } RecurrenceRule *rrule = new RecurrenceRule(); rrule->setStartDt( startDateTime() ); const_cast<KCalCore::Recurrence*>( this )->addRRule( rrule ); return rrule; } else { return d->mRRules[0]; } }
/****************************************************************************** * Return the date/time of the last recurrence. */ QDateTime KARecurrence::endDateTime() const { if(mFeb29Type == FEB29_FEB29 || duration() <= 1) { /* Either it doesn't have any special February 29th treatment, * it's infinite (count = -1), the end date is specified * (count = 0), or it ends on the start date (count = 1). * So just use the normal KCal end date calculation. */ return Recurrence::endDateTime(); } /* Create a temporary recurrence rule to find the end date. * In a standard KCal recurrence, the 29th February only occurs once every * 4 years. So shift the temporary recurrence date to the 28th to ensure * that it occurs every year, thus giving the correct occurrence count. */ RecurrenceRule *rrule = new RecurrenceRule(); rrule->setRecurrenceType(RecurrenceRule::rYearly); QDateTime dt = startDateTime(); QDate d = dt.date(); switch(d.day()) { case 29: // The start date is definitely a recurrence date, so shift // start date to the temporary recurrence date of the 28th d.setYMD(d.year(), d.month(), 28); break; case 28: if(d.month() != 2 || mFeb29Type != FEB29_FEB28 || QDate::leapYear(d.year())) { // Start date is not a recurrence date, so shift it to 27th d.setYMD(d.year(), d.month(), 27); } break; case 1: if(d.month() == 3 && mFeb29Type == FEB29_MAR1 && !QDate::leapYear(d.year())) { // Start date is a March 1st recurrence date, so shift // start date to the temporary recurrence date of the 28th d.setYMD(d.year(), 2, 28); } break; default: break; } dt.setDate(d); rrule->setStartDt(dt); rrule->setFloats(doesFloat()); rrule->setFrequency(frequency()); rrule->setDuration(duration()); QValueList<int> ds; ds.append(28); rrule->setByMonthDays(ds); rrule->setByMonths(defaultRRuleConst()->byMonths()); dt = rrule->endDt(); delete rrule; // We've found the end date for a recurrence on the 28th. Unless that date // is a real February 28th recurrence, adjust to the actual recurrence date. if(mFeb29Type == FEB29_FEB28 && dt.date().month() == 2 && !QDate::leapYear(dt.date().year())) return dt; return dt.addDays(1); }