示例#1
0
QDateTime TimeZone::convert(const QDateTime& dateTime) const
{
    Q_ASSERT(isValid());
    QOrganizerManager* manager = getManager();
    int offset = 100000; // impossible value
    QDateTime latestPhase;
    foreach(const TimeZonePhase& phase, mPhases) {
        QOrganizerEvent event;
        event.setStartDateTime(phase.startDateTime());
        event.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << phase.recurrenceRule());
        event.setRecurrenceDates(phase.recurrenceDates());
        QList<QOrganizerItem> occurrences =
            manager->itemOccurrences(event, phase.startDateTime(), dateTime, 500);
        if (!occurrences.isEmpty()) {
            QDateTime phaseStart(static_cast<QOrganizerEventOccurrence>(occurrences.last()).startDateTime());
            if (phaseStart > latestPhase) {
                latestPhase = phaseStart;
                offset = phase.utcOffset();
            }
        }
    }
void snippets()
{
    //! [Instantiating the default manager for the platform]
    QOrganizerManager defaultManager;
    //! [Instantiating the default manager for the platform]

    //! [Instantiating a specific manager]
    QOrganizerManager specificManager("KCal");
    //! [Instantiating a specific manager]

    // XXX TODO: use rrule instead of rdates.
    QDateTime startDateTime = QDateTime::currentDateTime();
    QDate firstOccDate = startDateTime.date().addDays(7);
    QDate secondOccDate = startDateTime.date().addDays(14);
    QDate thirdOccDate = startDateTime.date().addDays(21);
    QDateTime endDateTime = startDateTime.addDays(28);
    QSet<QDate> rDates;
    rDates << firstOccDate << secondOccDate << thirdOccDate;

    //! [Creating a recurrent event]
    QOrganizerEvent marshmallowMeeting;
    marshmallowMeeting.setRecurrenceDates(rDates);
    marshmallowMeeting.setPriority(QOrganizerItemPriority::HighPriority);
    marshmallowMeeting.setLocation("Meeting Room 8");
    marshmallowMeeting.setDescription("A meeting every wednesday to discuss the vitally important topic of marshmallows");
    marshmallowMeeting.setDisplayLabel("Marshmallow Conference");
    if (!defaultManager.saveItem(&marshmallowMeeting))
        qDebug() << "Failed to save the recurrent event; error:" << defaultManager.error();
    //! [Creating a recurrent event]

    //! [Retrieving occurrences of a particular recurrent event within a time period]
    QList<QOrganizerItem> instances = defaultManager.itemOccurrences(marshmallowMeeting, startDateTime, endDateTime);
    //! [Retrieving occurrences of a particular recurrent event within a time period]
    qDebug() << "dumping retrieved instances:";
    foreach(const QOrganizerItem& currInst, instances)
    {
        dumpItem(currInst);
        qDebug() << "....................";
    }