/****************************************************************************** * If the minimum and maximum date/times fall on the same date, set the minimum * and maximum times in the time edit box. */ void AlarmTimeWidget::setMaxMinTimeIf(const KDateTime& now) { int mint = 0; QTime maxt = time_23_59; mMinMaxTimeSet = false; if (mMaxDateTime.isValid()) { bool set = true; KDateTime minDT; if (mMinDateTimeIsNow) minDT = now.addSecs(60); else if (mMinDateTime.isValid()) minDT = mMinDateTime; else set = false; if (set && mMaxDateTime.date() == minDT.date()) { // The minimum and maximum times are on the same date, so // constrain the time value. mint = minDT.time().hour()*60 + minDT.time().minute(); maxt = mMaxDateTime.time(); mMinMaxTimeSet = true; } } mTimeEdit->setMinimum(mint); mTimeEdit->setMaximum(maxt); mTimeEdit->setWrapping(!mint && maxt == time_23_59); }
bool Recurrence::recursAt( const KDateTime &dt ) const { // Convert to recurrence's time zone for date comparisons, and for more efficient time comparisons KDateTime dtrecur = dt.toTimeSpec( d->mStartDateTime.timeSpec() ); // if it's excluded anyway, don't bother to check if it recurs at all. if ( d->mExDateTimes.containsSorted( dtrecur ) || d->mExDates.containsSorted( dtrecur.date() ) ) { return false; } int i, end; for ( i = 0, end = d->mExRules.count(); i < end; ++i ) { if ( d->mExRules[i]->recursAt( dtrecur ) ) { return false; } } // Check explicit recurrences, then rrules. if ( startDateTime() == dtrecur || d->mRDateTimes.containsSorted( dtrecur ) ) { return true; } for ( i = 0, end = d->mRRules.count(); i < end; ++i ) { if ( d->mRRules[i]->recursAt( dtrecur ) ) { return true; } } return false; }
//! @return "opened x minutes ago" string or similar static QString openedString(const QDateTime& _opened) { const KDateTime cur(KDateTime::currentUtcDateTime()); const KDateTime opened = KDateTime(_opened); if (!opened.isValid() || opened >= cur) return QString(); const int days = opened.daysTo(cur); if (days <= 1 && opened.secsTo(cur) < 24*60*60) { const int minutes = opened.secsTo(cur) / 60; const int hours = minutes / 60; if (hours < 1) { if (minutes == 0) return i18n("Opened less than minute ago"); else return i18np("Opened 1 minute ago", "Opened %1 minutes ago", minutes); } else { return i18np("Opened 1 hour ago", "Opened %1 hours ago", hours); } } else { if (days < 30) return i18np("Opened yesterday", "Opened %1 days ago", days); if (days < 365) return i18np("Opened over a month ago", "Opened %1 months ago", days / 30); return i18np("Opened one year ago", "Opened %1 years ago", days / 365); } return QString(); }
//@cond PRIVATE bool Todo::Private::recurTodo( Todo *todo ) { if ( todo->recurs() ) { Recurrence *r = todo->recurrence(); KDateTime endDateTime = r->endDateTime(); KDateTime nextDate = r->getNextDateTime( todo->dtDue() ); if ( ( r->duration() == -1 || ( nextDate.isValid() && endDateTime.isValid() && nextDate <= endDateTime ) ) ) { while ( !todo->recursAt( nextDate ) || nextDate <= KDateTime::currentUtcDateTime() ) { if ( !nextDate.isValid() || ( nextDate > endDateTime && r->duration() != -1 ) ) { return false; } nextDate = r->getNextDateTime( nextDate ); } todo->setDtDue( nextDate ); todo->setCompleted( false ); todo->setRevision( todo->revision() + 1 ); return true; } } return false; }
void ComparisonVisitorTest::testEventComparison() { const QString summary = QLatin1String( "Testing comparison" ); const QString desc = QLatin1String( "Testing ComparisonVisitor" ); const KDateTime now = KDateTime::currentUtcDateTime(); const KDateTime later = now.addSecs( 3600 ); Event reference; reference.setSummary( summary ); reference.setDescription( desc ); reference.setDtStart( now ); reference.setDtEnd( later ); // create a copy of the reference incidence Event event( reference ); IncidenceBase *baseReference = &reference; IncidenceBase *baseIncidence = &event; QVERIFY( mComparator.compare( baseIncidence, baseReference ) ); // change a property of Event (but not of IncidenceBase) event.setHasEndDate( !event.hasEndDate() ); QVERIFY( !mComparator.compare( baseIncidence, baseReference ) ); }
QString DateStringBuilder::getDateString(const KDateTime &dateTime, bool grouped) { if (!dateTime.isValid() || dateTime.isNull()) { return QString(); } QString day; if (QDateTime().currentDateTime().date() == dateTime.date()) { day = i18nc( "today", "Today" ); } if (QDateTime().currentDateTime().date().addDays(1) == dateTime.date()) { day = i18nc( "tomorrow", "Tomorrow" ); } if (QDateTime().currentDateTime().date() == dateTime.date().addDays(1)) { day = i18nc( "yesterday", "Yesterday" ); } if (!grouped && !day.isEmpty()) { return day.append("/t").append(dateTime.toString("%d.%m.%Y")); } if (!grouped && day.isEmpty()) { return dateTime.toString("%:a %d.%m.%Y"); } if (QDateTime().currentDateTime().date().weekNumber() == dateTime.date().weekNumber()) { return dateTime.toString("%A"); } //TODO last week return dateTime.toString("%B"); //KGlobal::locale()->formatDate(pimitem->getPrimaryDate().dateTime()); //return pimitem->getPrimaryDate().dateTime().toString("ddd dd.MM hh:mm"); //return dateTime.toString("%:a %d.%m.%Y"); }
void DateRangeFilterProxyModel::setEndDate( const KDateTime &date ) { if ( date.isValid() ) { d->mEnd = date.toUtc(); invalidateFilter(); } }
void TodoTest::testSetCompleted() { Todo todo1, todo2, todo3; todo1.setSummary(QStringLiteral("Todo Summary")); todo2.setSummary(QStringLiteral("Todo Summary")); todo3.setSummary(QStringLiteral("Todo Summary")); KDateTime today = KDateTime::currentUtcDateTime(); // due yesterday KDateTime originalDueDate = today.addDays(-1); todo1.setDtStart(originalDueDate); todo1.setDtDue(originalDueDate); todo1.recurrence()->setDaily(1); todo1.setCompleted(today); todo2.setCompleted(true); todo3.setStatus(Incidence::StatusCompleted); QVERIFY(originalDueDate != todo1.dtDue()); QVERIFY(!todo1.isCompleted()); QVERIFY(todo2.isCompleted()); QCOMPARE(todo2.status(), Incidence::StatusCompleted); QVERIFY(todo3.isCompleted()); todo2.setCompleted(false); QVERIFY(!todo2.isCompleted()); }
void KdeObservatory::engineError(const QString &source, const QString &error) { kDebug() << "Source:" << source << "Error:" << error; if (source == "fatal" && m_sourceCounter > 0) { m_viewTransitionTimer->stop(); foreach(QGraphicsWidget *widget, m_views) widget->hide(); m_views.clear(); graphicsWidget(); m_updateLabel->setStyleSheet(QString("QLabel{color:rgb(255, 0, 0);}")); m_updateLabel->setText(error); setBusy(false); return; } --m_sourceCounter; if (m_sourceCounter == 0) { KDateTime currentTime = KDateTime::currentLocalDateTime(); KLocale *locale = KGlobal::locale(); m_updateLabel->setStyleSheet(QString("QLabel{color:rgb(0, 0, 0);}")); m_updateLabel->setText(i18n("Last update: %1 %2", currentTime.toString(locale->dateFormatShort()), currentTime.toString(locale->timeFormat()))); setBusy(false); updateViews(); } }
void KdeObservatory::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data) { // Prevent for being updated from another instance update request if (data["appletId"].toUInt() != id()) return; QString project = data["project"].toString(); if (sourceName != "topActiveProjects" && !data.contains(project) && !data.contains("error")) return; if (sourceName == "topActiveProjects") m_viewProviders[i18n("Top Active Projects")]->updateViews(data); else if (sourceName == "topProjectDevelopers" && !project.isEmpty()) m_viewProviders[i18n("Top Developers")]->updateViews(data); else if (sourceName == "commitHistory" && !project.isEmpty()) m_viewProviders[i18n("Commit History")]->updateViews(data); else if (sourceName == "krazyReport" && !project.isEmpty()) m_viewProviders[i18n("Krazy Report")]->updateViews(data); --m_sourceCounter; m_collectorProgress->setValue(m_collectorProgress->maximum() - m_sourceCounter); if (m_sourceCounter == 0) { KDateTime currentTime = KDateTime::currentLocalDateTime(); KLocale *locale = KGlobal::locale(); m_updateLabel->setStyleSheet(QString("QLabel{color:rgb(0, 0, 0);}")); m_updateLabel->setText(i18n("Last update: %1 %2", currentTime.toString(locale->dateFormatShort()), currentTime.toString(locale->timeFormat()))); setBusy(false); updateViews(); } }
void KCalResourceSlox::parseEventAttribute( const QDomElement &e, Event *event ) { QString tag = e.tagName(); QString text = decodeText( e.text() ); if ( text.isEmpty() ) return; if ( tag == fieldName( EventBegin ) ) { KDateTime dt; if ( event->allDay() ) { if ( type() == "ox" ) dt = WebdavHandler::sloxToKDateTime( text, timeSpec() ); else dt = WebdavHandler::sloxToKDateTime( text ); // ### is this really correct for SLOX? dt.setDateOnly( true ); } else dt = WebdavHandler::sloxToKDateTime( text ); event->setDtStart( dt ); } else if ( tag == fieldName( EventEnd ) ) { KDateTime dt; if ( event->allDay() ) { dt = WebdavHandler::sloxToKDateTime( text ); dt = dt.addSecs( -1 ); } else dt = WebdavHandler::sloxToKDateTime( text ); event->setDtEnd( dt ); } else if ( tag == fieldName( Location ) ) { event->setLocation( text ); } }
/** static */ KDateTime AlarmDialog::triggerDateForIncidence( const Incidence::Ptr &incidence, const QDateTime &reminderAt, QString &displayStr ) { KDateTime result; if ( incidence->alarms().isEmpty() ) { return result; } Alarm::Ptr alarm = incidence->alarms().first(); if ( incidence->recurs() ) { result = incidence->recurrence()->getNextDateTime( KDateTime( reminderAt, KDateTime::Spec::LocalZone( ) ) ); displayStr = KGlobal::locale()->formatDateTime( result.toLocalZone() ); } if ( !result.isValid() ) { result = incidence->dateTime( Incidence::RoleAlarm ); displayStr = IncidenceFormatter::dateTimeToString( result, false, true, KDateTime::Spec::LocalZone() ); } return result; }
void CalSettings::loadSpecial(const QUrl& url, const QColor& color) { if (url.isEmpty()) { qCDebug(DIGIKAM_GENERAL_LOG) << "Loading calendar from file failed: No valid url provided!"; return; } KCalCore::MemoryCalendar::Ptr memCal(new KCalCore::MemoryCalendar(QString::fromLatin1("UTC"))); KCalCore::FileStorage::Ptr fileStorage(new KCalCore::FileStorage(memCal, url.toLocalFile(), new KCalCore::ICalFormat)); qCDebug(DIGIKAM_GENERAL_LOG) << "Loading calendar from file " << url.toLocalFile(); if (!fileStorage->load()) { qCDebug(DIGIKAM_GENERAL_LOG) << "Failed!"; } else { CalSystem calSys; QDate qFirst, qLast; qFirst = calSys.date(params.year, 1, 1); qLast = calSys.date(params.year + 1, 1, 1); qLast = qLast.addDays(-1); KDateTime dtFirst(qFirst); KDateTime dtLast(qLast); KDateTime dtCurrent; int counter = 0; KCalCore::Event::List list = memCal->rawEvents(qFirst, qLast); foreach(const KCalCore::Event::Ptr event, list) { qCDebug(DIGIKAM_GENERAL_LOG) << event->summary() << endl << "--------"; counter++; if (event->recurs()) { KCalCore::Recurrence* const recur = event->recurrence(); for (dtCurrent = recur->getNextDateTime(dtFirst.addDays(-1)); (dtCurrent <= dtLast) && dtCurrent.isValid(); dtCurrent = recur->getNextDateTime(dtCurrent)) { addSpecial(dtCurrent.date(), Day(color, event->summary())); } } else { addSpecial(event->dtStart().date(), Day(color, event->summary())); } } qCDebug(DIGIKAM_GENERAL_LOG) << "Loaded " << counter << " events"; memCal->close(); fileStorage->close(); }
/****************************************************************************** * Set the minimum date/time to track the current time. */ void AlarmTimeWidget::setMinDateTimeIsCurrent() { mMinDateTimeIsNow = true; mMinDateTime = KDateTime(); KDateTime now = KDateTime::currentDateTime(mTimeSpec); mDateEdit->setMinDate(now.date()); setMaxMinTimeIf(now); }
FreeBusyManagerPrivate::FreeBusyProvidersRequestsQueue::FreeBusyProvidersRequestsQueue( const KDateTime &start, const KDateTime &end ) : mHandlersCount( 0 ), mResultingFreeBusy( 0 ) { mStartTime = start.toString(); mEndTime = end.toString(); mResultingFreeBusy = KCalCore::FreeBusy::Ptr( new KCalCore::FreeBusy( start, end ) ); }
static QString yearForDate( const QString &upnpDate ) { KDateTime dateTime = KDateTime::fromString( upnpDate ); int year = dateTime.date().year(); if( !dateTime.isValid() ) { year = 0; } return QString::number( year ); }
QDate Event::dateEnd() const { KDateTime end = dtEnd().toTimeSpec( dtStart() ); if ( allDay() ) { return end.date(); } else { return end.addSecs(-1).date(); } }
QString DateStringBuilder::getFullDateTime(const KDateTime &dateTime) { if (!dateTime.isValid() || dateTime.isNull()) { return QString(); } QString date; date.append(getFullDate(dateTime)); date.append(" "); date.append(dateTime.toString("%k:%M:%S")); return date; }
// Have to define before use QDataStream& operator<< ( QDataStream &s, const MailSummary &d ) { s << d.serialNumber(); s << d.messageId(); s << d.subject(); s << d.from(); s << d.to(); KDateTime tempTime; tempTime.setTime_t( d.date() ); s << tempTime.dateTime(); return s; }
void TodoTest::testRoles() { const KDateTime today = KDateTime::currentUtcDateTime(); const KDateTime yesterday = today.addDays(-1); Todo todo; todo.setDtStart(today.addDays(-1)); todo.setDtDue(today); QCOMPARE(todo.dateTime(Incidence::RoleDisplayStart), today); QCOMPARE(todo.dateTime(Incidence::RoleDisplayEnd), today); todo.setDtDue(KDateTime()); QCOMPARE(todo.dateTime(Incidence::RoleDisplayStart), yesterday); QCOMPARE(todo.dateTime(Incidence::RoleDisplayEnd), yesterday); }
void UpcomingEventsWidget::setDate( const KDateTime &date ) { QLabel *dateLabel = static_cast<QLabel*>( m_date->widget() ); dateLabel->setText( KGlobal::locale()->formatDateTime( date, KLocale::FancyLongDate ) ); KDateTime currentDT = KDateTime::currentLocalDateTime(); if( currentDT.compare(date) == KDateTime::Before ) { int daysTo = currentDT.daysTo( date ); dateLabel->setToolTip( i18ncp( "@info:tooltip Number of days till an event", "Tomorrow", "In <strong>%1</strong> days", daysTo ) ); } }
KDateTime Todo::dtStart( bool first ) const { if ( !hasStartDate() ) { return KDateTime(); } if ( recurs() && !first ) { KDateTime dt = d->mDtRecurrence.addDays( dtDue( true ).daysTo( IncidenceBase::dtStart() ) ); dt.setTime( IncidenceBase::dtStart().time() ); return dt; } else { return IncidenceBase::dtStart(); } }
void ComingUpViewItemModel::updateEvents() { modelEventList->clear(); theData.clear(); QList<CalendarEvent*>& eventList = viewManager.GetEvents(); //int eventsLimitedTo = 3, comingUpEventCnt=0; int cntr = eventList.count(); QDate today = QDate::currentDate(); KDateTime daysLaterDate = KDateTime(today.addDays(7)); for ( int i=0;i<cntr;i++ ) { CalendarEvent* event = eventList.at(i); bool addEvent = false; //Bug#7244 Author: [email protected] //Fixed the issue with display of "coming up" "Later" event list if ( restrictEventCount == true ) { if ( today == event->StartDate().date() ) { addEvent = true; } } else { if(event->StartDate().date() > daysLaterDate.date()) { break; } else if ( event->StartDate().date() > today ) { addEvent = true; } } if ( addEvent ) { modelEventList->append(event); QString dateString; //Bug#7320 Author: [email protected] //This piece of code fixes the issue with display of event //If today: Display time followed by event //Else Display Date-time followed by event if(today == event->StartDate().date()) { dateString = event->StartDate().toString ( "hh:mm AP" ); } else { dateString = event->StartDate().toString ( "ddd dd hh:mm AP" ); } QString alarmsString("alarmOFF"); if ( event->Alarm() ) { alarmsString = "alarmON"; } theData.append( QStringList() << dateString << event->Description() << alarmsString ); } } }
QString Stringify::formatTime( const KDateTime &dt, bool shortfmt, const KDateTime::Spec &spec ) { if ( spec.isValid() ) { QString timeZone; if ( spec.timeZone() != KSystemTimeZones::local() ) { timeZone = ' ' + spec.timeZone().name(); } return KGlobal::locale()->formatTime( dt.toTimeSpec( spec ).time(), !shortfmt ) + timeZone; } else { return KGlobal::locale()->formatTime( dt.time(), !shortfmt ); } }
/****************************************************************************** * Set the maximum value for the delay time edit box, depending on the maximum * value for the date/time. */ void AlarmTimeWidget::setMaxDelayTime(const KDateTime& now) { int maxVal = maxDelayTime; if (mMaxDateTime.isValid()) { if (now.date().daysTo(mMaxDateTime.date()) < 100) // avoid possible 32-bit overflow on secsTo() { KDateTime dt(now); dt.setTime(QTime(now.time().hour(), now.time().minute(), 0)); // round down to nearest minute maxVal = dt.secsTo(mMaxDateTime) / 60; if (maxVal > maxDelayTime) maxVal = maxDelayTime; } } mDelayTimeEdit->setMaximum(maxVal); }
void KNFolder::DynData::getData( KNLocalArticle::Ptr a ) { a->setId(id); KDateTime dt; dt.setTime_t( ti ); a->date()->setDateTime( dt ); a->setStartOffset(so); a->setEndOffset(eo); a->setServerId(sId); a->setDoMail(flags[0]); a->setMailed(flags[1]); a->setDoPost(flags[2]); a->setPosted(flags[3]); a->setCanceled(flags[4]); a->setEditDisabled(flags[5]); }
QString UtilMethods::getCurrentTime(int format) { KDateTime now = KDateTime::currentLocalDateTime(); QString toTxt = ""; switch(format) { case ETimeDefault: { toTxt = now.time().toString(Qt::TextDate); }break; case ETimeSystemLocale: { toTxt = now.time().toString(Qt::SystemLocaleDate); }break; } return toTxt; }
void DateRangeFilterProxyModel::setStartDate( const KDateTime &date ) { if ( date.isValid() ) { d->mStart = date; invalidateFilter(); } }
/****************************************************************************** * Set the minimum date/time, adjusting the entered date/time if necessary. * If 'dt' is invalid, any current minimum date/time is cleared. */ void AlarmTimeWidget::setMinDateTime(const KDateTime& dt) { mMinDateTimeIsNow = false; mMinDateTime = dt.toTimeSpec(mTimeSpec); mDateEdit->setMinDate(mMinDateTime.date()); setMaxMinTimeIf(KDateTime::currentDateTime(mTimeSpec)); }
void shouldPopulateCommittedAtCorrectly() { QStringList rawData; rawData << "tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904"; rawData << "parent abffc0ae9ba476fe1e9a30fa2c8903113dbadb3d"; rawData << "author Me 1234567890 -0230"; rawData << "committer You 1234567890 -0230"; rawData << ""; rawData << "Some message."; rawData << ""; commit->fillFromString(rawData.join("\n")); KDateTime committedAt; committedAt.setTime_t(1234567890); committedAt.setTimeSpec(KDateTime::Spec(KDateTime::OffsetFromUTC, -9000/*==2,5h*/)); QCOMPARE(commit->committedAt().toString(), committedAt.toString()); QCOMPARE(commit->committedAt().utcOffset(), -9000); }