本文整理汇总了C++中KDateTime::date方法的典型用法代码示例。如果您正苦于以下问题:C++ KDateTime::date方法的具体用法?C++ KDateTime::date怎么用?C++ KDateTime::date使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KDateTime
的用法示例。
在下文中一共展示了KDateTime::date方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getCurrentDate
QString UtilMethods::getCurrentDate(int format)
{
KDateTime now = KDateTime::currentLocalDateTime();
QString toTxt = "";
switch(format) {
case EDefault: {
toTxt = now.date().toString(Qt::TextDate);
}break;
case ESystemLocaleShortDate: {
toTxt = now.date().toString(Qt::SystemLocaleShortDate);
}break;
case ESystemLocaleLongDate: {
toTxt = now.date().toString(Qt::SystemLocaleLongDate);
}break;
case EDefaultLocaleShortDate: {
toTxt = now.date().toString(Qt::DefaultLocaleShortDate);
}break;
case EDefaultLocaleLongDate: {
toTxt = now.date().toString(Qt::DefaultLocaleLongDate);
}break;
}
return toTxt;
}
示例2: tst_alldayUtc
void tst_storage::tst_alldayUtc()
{
// test event saved with UTC time
auto event = KCalCore::Event::Ptr(new KCalCore::Event);
QDate startDate(2013, 12, 1);
event->setDtStart(KDateTime(startDate, QTime(), KDateTime::UTC));
event->setAllDay(true);
event->setSummary("test event utc");
QCOMPARE(event->allDay(), true);
m_calendar->addEvent(event, NotebookId);
m_storage->save();
QString uid = event->uid();
reloadDb();
auto fetchedEvent = m_calendar->event(uid);
QVERIFY(fetchedEvent.data());
QVERIFY(fetchedEvent->dtStart().isUtc());
KDateTime localStart = fetchedEvent->dtStart().toLocalZone();
QVERIFY(localStart.time() == QTime(2, 0));
KDateTime localEnd = fetchedEvent->dtEnd().toLocalZone();
QVERIFY(localEnd.time() == QTime(2, 0));
QCOMPARE(localEnd.date(), localStart.date().addDays(1));
}
示例3: 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");
}
示例4: 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);
}
示例5: 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;
}
示例6: loadSpecial
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();
}
示例7: setMinDateTimeIsCurrent
/******************************************************************************
* 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);
}
示例8: getGroupedDate
QString DateStringBuilder::getGroupedDate(const KDateTime &dateTime)
{
if (!dateTime.isValid() || dateTime.isNull()) {
return QString();
}
QDate currentDate = QDateTime::currentDateTime().date();
if (currentDate.weekNumber() == dateTime.date().weekNumber()) { //this week
return getDayName(dateTime);
}
if (currentDate.addDays(-7).weekNumber() == dateTime.date().weekNumber()) { //last week
return i18n("Last Week");
}
if (currentDate.year() == dateTime.date().year()) { //this year
return dateTime.toString("%B");
}
return dateTime.toString("%B %Y");
}
示例9: yearForDate
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 );
}
示例10: getDayName
QString getDayName(const KDateTime &dateTime)
{
if (!dateTime.isValid() || dateTime.isNull()) {
return QString();
}
QString day;
if (QDateTime().currentDateTime().date() == dateTime.date()) {
return i18n("Today" );
}
if (QDateTime().currentDateTime().date().addDays(1) == dateTime.date()) {
return i18n( "Tomorrow" );
}
if (QDateTime().currentDateTime().date() == dateTime.date().addDays(1)) {
return i18n("Yesterday" );
}
return dateTime.toString("%A");
}
示例11: dateEnd
QDate Event::dateEnd() const
{
KDateTime end = dtEnd().toTimeSpec( dtStart() );
if ( allDay() ) {
return end.date();
} else {
return end.addSecs(-1).date();
}
}
示例12: getShortDate
QString DateStringBuilder::getShortDate(const KDateTime &dateTime)
{
if (!dateTime.isValid() || dateTime.isNull()) {
return QString();
}
QDate currentDate = QDateTime().currentDateTime().date();
if (currentDate.weekNumber() == dateTime.date().weekNumber() || currentDate.addDays(1) == dateTime.date()) { //this week or tomorrow (i.e. on sunday)
return getDayName(dateTime);
}
if (currentDate.year() == dateTime.date().year()) { //this year
//Micro optimization because this function showed up as hotspot
static QCache<uint, QString> cache;
uint hash = dateTime.date().month() ^ dateTime.date().day();
if (!cache.contains(hash)) {
cache.insert(hash, new QString(dateTime.toString("%d.%m")));
}
return *cache[hash];
}
return dateTime.toString("%d.%m.%Y");
}
示例13: updateTimes
/******************************************************************************
* Called every minute to update the alarm time data entry fields.
* If the maximum date/time has been reached, a 'pastMax()' signal is emitted.
*/
void AlarmTimeWidget::updateTimes()
{
KDateTime now;
if (mMinDateTimeIsNow)
{
// Make sure that the minimum date is updated when the day changes
now = KDateTime::currentDateTime(mTimeSpec);
mDateEdit->setMinDate(now.date());
}
if (mMaxDateTime.isValid())
{
if (!now.isValid())
now = KDateTime::currentDateTime(mTimeSpec);
if (!mPastMax)
{
// Check whether the maximum date/time has now been reached
if (now.date() >= mMaxDateTime.date())
{
// The current date has reached or has passed the maximum date
if (now.date() > mMaxDateTime.date()
|| (!mAnyTime && now.time() > mTimeEdit->maxTime()))
{
mPastMax = true;
emit pastMax();
}
else if (mMinDateTimeIsNow && !mMinMaxTimeSet)
{
// The minimum date/time tracks the clock, so set the minimum
// and maximum times
setMaxMinTimeIf(now);
}
}
}
setMaxDelayTime(now);
}
if (mAtTimeRadio->isChecked())
dateTimeChanged();
else
delayTimeChanged(mDelayTimeEdit->value());
}
示例14: updateEvents
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 );
}
}
}
示例15: setMaxDelayTime
/******************************************************************************
* 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);
}