/*! Finds a free slot in the future which has at least the same size as the initial slot. */ bool KOEditorFreeBusy::findFreeSlot( QDateTime &dtFrom, QDateTime &dtTo ) { if( tryDate( dtFrom, dtTo ) ) // Current time is acceptable return true; QDateTime tryFrom = dtFrom; QDateTime tryTo = dtTo; // Make sure that we never suggest a date in the past, even if the // user originally scheduled the meeting to be in the past. if( tryFrom < QDateTime::currentDateTime() ) { // The slot to look for is at least partially in the past. int secs = tryFrom.secsTo( tryTo ); tryFrom = QDateTime::currentDateTime(); tryTo = tryFrom.addSecs( secs ); } bool found = false; while( !found ) { found = tryDate( tryFrom, tryTo ); // PENDING(kalle) Make the interval configurable if( !found && dtFrom.daysTo( tryFrom ) > 365 ) break; // don't look more than one year in the future } dtFrom = tryFrom; dtTo = tryTo; return found; }
/*! Checks whether the slot specified by (tryFrom, tryTo) is available for the participant specified with attendee. If yes, return true. If not, return false and change (tryFrom, tryTo) to contain the next possible slot for this participant (not necessarily a slot that is available for all participants). */ bool KOEditorFreeBusy::tryDate( FreeBusyItem *attendee, QDateTime &tryFrom, QDateTime &tryTo ) { // If we don't have any free/busy information, assume the // participant is free. Otherwise a participant without available // information would block the whole allocation. KCal::FreeBusy *fb = attendee->freeBusy(); if( !fb ) return true; QValueList<KCal::Period> busyPeriods = fb->busyPeriods(); for( QValueList<KCal::Period>::Iterator it = busyPeriods.begin(); it != busyPeriods.end(); ++it ) { if( (*it).end() <= tryFrom || // busy period ends before try period (*it).start() >= tryTo ) // busy period starts after try period continue; else { // the current busy period blocks the try period, try // after the end of the current busy period int secsDuration = tryFrom.secsTo( tryTo ); tryFrom = (*it).end(); tryTo = tryFrom.addSecs( secsDuration ); // try again with the new try period tryDate( attendee, tryFrom, tryTo ); // we had to change the date at least once return false; } } return true; }
void IntlTestDateFormat::testFormat(/* char* par */) { if (fFormat == 0) { dataerrln("FAIL: DateFormat creation failed"); return; } describeTest(); UDate now = Calendar::getNow(); tryDate(0); tryDate(1278161801778.0); tryDate(5264498352317.0); // Sunday, October 28, 2136 8:39:12 AM PST tryDate(9516987689250.0); // In the year 2271 tryDate(now); // Shift 6 months into the future, AT THE SAME TIME OF DAY. // This will test the DST handling. tryDate(now + 6.0*30*ONEDAY); UDate limit = now * 10; // Arbitrary limit for (int32_t i=0; i<3; ++i) tryDate(uprv_floor(randDouble() * limit)); delete fFormat; }
/*! Checks whether the slot specified by (tryFrom, tryTo) is free for all participants. If yes, return true. If at least one participant is found for which this slot is occupied, this method returns false, and (tryFrom, tryTo) contain the next free slot for that participant. In other words, the returned slot does not have to be free for everybody else. */ bool KOEditorFreeBusy::tryDate( QDateTime& tryFrom, QDateTime& tryTo ) { FreeBusyItem* currentItem = static_cast<FreeBusyItem*>( mGanttView->firstChild() ); while( currentItem ) { if( !tryDate( currentItem, tryFrom, tryTo ) ) { // kdDebug(5850) << "++++date is not OK, new suggestion: " << tryFrom.toString() << " to " << tryTo.toString() << endl; return false; } currentItem = static_cast<FreeBusyItem*>( currentItem->nextSibling() ); } return true; }