本文整理汇总了C++中KDateTime::daysTo方法的典型用法代码示例。如果您正苦于以下问题:C++ KDateTime::daysTo方法的具体用法?C++ KDateTime::daysTo怎么用?C++ KDateTime::daysTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KDateTime
的用法示例。
在下文中一共展示了KDateTime::daysTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2:
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 ) );
}
}
示例3: kDebug
//@cond PRIVATE
void FreeBusy::Private::init( const Event::List &eventList,
const KDateTime &start, const KDateTime &end )
{
int extraDays, i, x, duration;
duration = start.daysTo( end );
QDate day;
KDateTime tmpStart;
KDateTime tmpEnd;
// Loops through every event in the calendar
Event::List::ConstIterator it;
for ( it = eventList.constBegin(); it != eventList.constEnd(); ++it ) {
Event::Ptr event = *it;
// If this event is transparent it shouldn't be in the freebusy list.
if ( event->transparency() == Event::Transparent ) {
continue;
}
// The code below can not handle all-day events. Fixing this resulted
// in a lot of duplicated code. Instead, make a copy of the event and
// set the period to the full day(s). This trick works for recurring,
// multiday, and single day all-day events.
Event::Ptr allDayEvent;
if ( event->allDay() ) {
// addDay event. Do the hack
kDebug() << "All-day event";
allDayEvent = Event::Ptr( new Event( *event ) );
// Set the start and end times to be on midnight
KDateTime st = allDayEvent->dtStart();
st.setTime( QTime( 0, 0 ) );
KDateTime nd = allDayEvent->dtEnd();
nd.setTime( QTime( 23, 59, 59, 999 ) );
allDayEvent->setAllDay( false );
allDayEvent->setDtStart( st );
allDayEvent->setDtEnd( nd );
kDebug() << "Use:" << st.toString() << "to" << nd.toString();
// Finally, use this event for the setting below
event = allDayEvent;
}
// This whole for loop is for recurring events, it loops through
// each of the days of the freebusy request
for ( i = 0; i <= duration; ++i ) {
day = start.addDays( i ).date();
tmpStart.setDate( day );
tmpEnd.setDate( day );
if ( event->recurs() ) {
if ( event->isMultiDay() ) {
// FIXME: This doesn't work for sub-daily recurrences or recurrences with
// a different time than the original event.
extraDays = event->dtStart().daysTo( event->dtEnd() );
for ( x = 0; x <= extraDays; ++x ) {
if ( event->recursOn( day.addDays( -x ), start.timeSpec() ) ) {
tmpStart.setDate( day.addDays( -x ) );
tmpStart.setTime( event->dtStart().time() );
tmpEnd = event->duration().end( tmpStart );
addLocalPeriod( q, tmpStart, tmpEnd );
break;
}
}
} else {
if ( event->recursOn( day, start.timeSpec() ) ) {
tmpStart.setTime( event->dtStart().time() );
tmpEnd.setTime( event->dtEnd().time() );
addLocalPeriod ( q, tmpStart, tmpEnd );
}
}
}
}
// Non-recurring events
addLocalPeriod( q, event->dtStart(), event->dtEnd() );
}
q->sortList();
}