本文整理汇总了C++中KDateTime类的典型用法代码示例。如果您正苦于以下问题:C++ KDateTime类的具体用法?C++ KDateTime怎么用?C++ KDateTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KDateTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setMaxMinTimeIf
/******************************************************************************
* 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);
}
示例2: recursAt
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;
}
示例3: openedString
//! @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();
}
示例4: while
//@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;
}
示例5: QLatin1String
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 ) );
}
示例6: getDateString
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");
}
示例7: setEndDate
void DateRangeFilterProxyModel::setEndDate( const KDateTime &date )
{
if ( date.isValid() ) {
d->mEnd = date.toUtc();
invalidateFilter();
}
}
示例8: testSetCompleted
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());
}
示例9: kDebug
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();
}
}
示例10: if
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();
}
}
示例11: decodeText
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 );
}
}
示例12: KDateTime
/** 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;
}
示例13: qCDebug
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();
}
示例14: KDateTime
/******************************************************************************
* 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);
}
示例15: mHandlersCount
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 ) );
}