本文整理汇总了C++中KDateTime::time方法的典型用法代码示例。如果您正苦于以下问题:C++ KDateTime::time方法的具体用法?C++ KDateTime::time怎么用?C++ KDateTime::time使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KDateTime
的用法示例。
在下文中一共展示了KDateTime::time方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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: getCurrentTime
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;
}
示例4: 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);
}
示例5: formatTime
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 );
}
}
示例6: 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());
}
示例7: recurTimesOn
TimeList Recurrence::recurTimesOn( const QDate &date, const KDateTime::Spec &timeSpec ) const
{
// kDebug() << "recurTimesOn(" << date << ")";
int i, end;
TimeList times;
// The whole day is excepted
if ( d->mExDates.containsSorted( date ) ) {
return times;
}
// EXRULE takes precedence over RDATE entries, so for all-day events,
// a matching excule also excludes the whole day automatically
if ( allDay() ) {
for ( i = 0, end = d->mExRules.count(); i < end; ++i ) {
if ( d->mExRules[i]->recursOn( date, timeSpec ) ) {
return times;
}
}
}
KDateTime dt = startDateTime().toTimeSpec( timeSpec );
if ( dt.date() == date ) {
times << dt.time();
}
bool foundDate = false;
for ( i = 0, end = d->mRDateTimes.count(); i < end; ++i ) {
dt = d->mRDateTimes[i].toTimeSpec( timeSpec );
if ( dt.date() == date ) {
times << dt.time();
foundDate = true;
} else if ( foundDate ) {
break; // <= Assume that the rdatetime list is sorted
}
}
for ( i = 0, end = d->mRRules.count(); i < end; ++i ) {
times += d->mRRules[i]->recurTimesOn( date, timeSpec );
}
times.sortUnique();
foundDate = false;
TimeList extimes;
for ( i = 0, end = d->mExDateTimes.count(); i < end; ++i ) {
dt = d->mExDateTimes[i].toTimeSpec( timeSpec );
if ( dt.date() == date ) {
extimes << dt.time();
foundDate = true;
} else if ( foundDate ) {
break;
}
}
if ( !allDay() ) { // we have already checked all-day times above
for ( i = 0, end = d->mExRules.count(); i < end; ++i ) {
extimes += d->mExRules[i]->recurTimesOn( date, timeSpec );
}
}
extimes.sortUnique();
int st = 0;
for ( i = 0, end = extimes.count(); i < end; ++i ) {
int j = times.removeSorted( extimes[i], st );
if ( j >= 0 ) {
st = j;
}
}
return times;
}
示例8: addHMToCurrentTime
QTime UtilMethods::addHMToCurrentTime(int hr,int min) {
int val = (hr*60*60)+(min*60);
KDateTime now = KDateTime::currentLocalDateTime().addSecs(val);
return now.time();
}
示例9: getDateTime
/******************************************************************************
* Fetch the entered date/time.
* If 'checkExpired' is true and the entered value <= current time, an error occurs.
* If 'minsFromNow' is non-null, it is set to the number of minutes' delay selected,
* or to zero if a date/time was entered.
* In this case, if 'showErrorMessage' is true, output an error message.
* 'errorWidget' if non-null, is set to point to the widget containing the error.
* Reply = invalid date/time if error.
*/
KDateTime AlarmTimeWidget::getDateTime(int* minsFromNow, bool checkExpired, bool showErrorMessage, QWidget** errorWidget) const
{
if (minsFromNow)
*minsFromNow = 0;
if (errorWidget)
*errorWidget = 0;
KDateTime now = KDateTime::currentUtcDateTime();
now.setTime(QTime(now.time().hour(), now.time().minute(), 0));
if (!mAtTimeRadio->isChecked())
{
if (!mDelayTimeEdit->isValid())
{
if (showErrorMessage)
KMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Invalid time"));
if (errorWidget)
*errorWidget = mDelayTimeEdit;
return KDateTime();
}
int delayMins = mDelayTimeEdit->value();
if (minsFromNow)
*minsFromNow = delayMins;
return now.addSecs(delayMins * 60).toTimeSpec(mTimeSpec);
}
else
{
bool dateOnly = mAnyTimeAllowed && mAnyTimeCheckBox && mAnyTimeCheckBox->isChecked();
if (!mDateEdit->isValid() || !mTimeEdit->isValid())
{
// The date and/or time is invalid
if (!mDateEdit->isValid())
{
if (showErrorMessage)
KMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Invalid date"));
if (errorWidget)
*errorWidget = mDateEdit;
}
else
{
if (showErrorMessage)
KMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Invalid time"));
if (errorWidget)
*errorWidget = mTimeEdit;
}
return KDateTime();
}
KDateTime result;
if (dateOnly)
{
result = KDateTime(mDateEdit->date(), mTimeSpec);
if (checkExpired && result.date() < now.date())
{
if (showErrorMessage)
KMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Alarm date has already expired"));
if (errorWidget)
*errorWidget = mDateEdit;
return KDateTime();
}
}
else
{
result = KDateTime(mDateEdit->date(), mTimeEdit->time(), mTimeSpec);
if (checkExpired && result <= now.addSecs(1))
{
if (showErrorMessage)
KMessageBox::sorry(const_cast<AlarmTimeWidget*>(this), i18nc("@info", "Alarm time has already expired"));
if (errorWidget)
*errorWidget = mTimeEdit;
return KDateTime();
}
}
return result;
}
}