当前位置: 首页>>代码示例>>C++>>正文


C++ QDateTime::daysTo方法代码示例

本文整理汇总了C++中QDateTime::daysTo方法的典型用法代码示例。如果您正苦于以下问题:C++ QDateTime::daysTo方法的具体用法?C++ QDateTime::daysTo怎么用?C++ QDateTime::daysTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QDateTime的用法示例。


在下文中一共展示了QDateTime::daysTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: formatLastUsedDateRelative

QString UiUtils::formatLastUsedDateRelative(const QDateTime & lastUsed)
{
    QString lastUsedText;
    if (lastUsed.isValid()) {
        const QDateTime now = QDateTime::currentDateTime();
        if (lastUsed.daysTo(now) == 0 ) {
            const int secondsAgo = lastUsed.secsTo(now);
            if (secondsAgo < (60 * 60 )) {
                const int minutesAgo = secondsAgo / 60;
                /*: Label for last used time for a network connection used in the last hour, as the number of minutes since usage */
                lastUsedText = QObject::tr("Last used %n minute(s) ago", "", minutesAgo);
            } else {
                const int hoursAgo = secondsAgo / (60 * 60);
                /*: Label for last used time for a network connection used in the last day, as the number of hours since usage */
                lastUsedText = QObject::tr("Last used %n hour(s) ago", "", hoursAgo);
            }
        } else if (lastUsed.daysTo(now) == 1) {
            /*: Label for last used time for a network connection used the previous day */
            lastUsedText = QObject::tr("Last used yesterday");
        } else {
            lastUsedText = QObject::tr("Last used on %1").arg(QLocale().toString(lastUsed.date(), QLocale::ShortFormat));
        }
    } else {
        /*: Label for last used time for a network connection that has never been used */
        lastUsedText =  QObject::tr("Never used");
    }
    return lastUsedText;
}
开发者ID:JosephMillsAtWork,项目名称:u2t,代码行数:28,代码来源:uiutils.cpp

示例2: timeAgoInWords

QString Utility::timeAgoInWords(const QDateTime& dt, const QDateTime& from)
{
    QDateTime now = QDateTime::currentDateTimeUtc();

    if( from.isValid() ) {
        now = from;
    }

    if( dt.daysTo(now)>0 ) {
        int dtn = dt.daysTo(now);
        return QObject::tr("%n day(s) ago", "", dtn);
    } else {
        qint64 secs = dt.secsTo(now);
        if( secs < 0 ) {
            return QObject::tr("in the future");
        }
        if( floor(secs / 3600.0) > 0 ) {
            int hours = floor(secs/3600.0);
            return( QObject::tr("%n hour(s) ago", "", hours) );
        } else {
            int minutes = qRound(secs/60.0);
            if( minutes == 0 ) {
                if(secs < 5) {
                    return QObject::tr("now");
                } else {
                    return QObject::tr("Less than a minute ago");
                }
            }
            return( QObject::tr("%n minute(s) ago", "", minutes) );
        }
    }
    return QObject::tr("Some time ago");
}
开发者ID:Hopebaytech,项目名称:client,代码行数:33,代码来源:utility.cpp

示例3: qwtIntervalWidth

static double qwtIntervalWidth( const QDateTime &minDate,
    const QDateTime &maxDate, QwtDate::IntervalType intervalType ) 
{
    switch( intervalType )
    {
        case QwtDate::Millisecond:
        {
            const double secsTo = minDate.secsTo( maxDate );
            const double msecs = maxDate.time().msec() -
                minDate.time().msec();

            return secsTo * 1000 + msecs;
        }
        case QwtDate::Second:
        {
            return minDate.secsTo( maxDate );
        }
        case QwtDate::Minute:
        {
            const double secsTo = minDate.secsTo( maxDate );
            return ::floor( secsTo / 60 );
        }
        case QwtDate::Hour:
        {
            const double secsTo = minDate.secsTo( maxDate );
            return ::floor( secsTo / 3600 );
        }
        case QwtDate::Day:
        {
            return minDate.daysTo( maxDate );
        }
        case QwtDate::Week:
        {
            return ::floor( minDate.daysTo( maxDate ) / 7.0 );
        }
        case QwtDate::Month:
        {
            const double years = 
                double( maxDate.date().year() ) - minDate.date().year();

            int months = maxDate.date().month() - minDate.date().month();
            if ( maxDate.date().day() < minDate.date().day() )
                months--;

            return years * 12 + months;
        }
        case QwtDate::Year:
        {
            double years = 
                double( maxDate.date().year() ) - minDate.date().year();

            if ( maxDate.date().month() < minDate.date().month() )
                years -= 1.0;

            return years;
        }
    }

    return 0.0;
}
开发者ID:151706061,项目名称:sofa,代码行数:60,代码来源:qwt_date_scale_engine.cpp

示例4: QObject

AppSettings::AppSettings(QObject *parent)
    : QObject(parent)
    , m_lastClosed(QString("") )
    , m_showTutorial(false)
{

    qDebug() << "[AppSettings::AppSettings]";

    // Set the application organization and name, which is used by QSettings
    // when saving values to the persistent store.
    QCoreApplication::setOrganizationName("Will Thrill");
    QCoreApplication::setApplicationName("Wappy");

    // Get the date and time of last time user closed the application
    m_lastClosed = this->getValueFor( AppSettings::APP_LAST_CLOSED, QString(""));

    // Determine if the long-press tutorial image should be displayed
    // rule: always show if it's been more than 1 week since user last used the app
    if( m_lastClosed.length() == 0) {
        m_showTutorial = true;
    }
    else {
        QDateTime lastClosed = QDateTime::fromString(m_lastClosed, AppSettings::APP_DATE_FORMAT);
        QDateTime now = QDateTime::currentDateTime();
        qDebug() << "[AppSettings::AppSettings] days: " << lastClosed.daysTo(now);
        setShowTutorial( lastClosed.daysTo(now) > AppSettings::APP_MAX_DAYS );
    }
}
开发者ID:williamrjribeiro,项目名称:wallpaper-ruler-bb10,代码行数:28,代码来源:AppSettings.cpp

示例5: checkForExpired

void HistoryManager::checkForExpired()
{
    if (m_historyLimit < 0 || m_history.isEmpty())
        return;

    QDateTime now = QDateTime::currentDateTime();
    int nextTimeout = 0;

    while (!m_history.isEmpty()) {
        QDateTime checkForExpired = m_history.last().dateTime;
        checkForExpired.setDate(checkForExpired.date().addDays(m_historyLimit));
        if (now.daysTo(checkForExpired) > 7) {
            // check at most in a week to prevent int overflows on the timer
            nextTimeout = 7 * 86400;
        } else {
            nextTimeout = now.secsTo(checkForExpired);
        }
        if (nextTimeout > 0)
            break;
        HistoryItem item = m_history.takeLast();
        // remove from saved file also
        m_lastSavedUrl = QString();
        emit entryRemoved(item);
    }

    if (nextTimeout > 0)
        m_expiredTimer.start(nextTimeout * 1000);
}
开发者ID:Metrological,项目名称:qtwebengine,代码行数:28,代码来源:history.cpp

示例6: minutesBetween

int TidalCurrentPredictor::minutesBetween(QDateTime first, QDateTime second)
{
    int days_passed = first.daysTo(second);
    int hours_passed = second.time().hour() - first.time().hour();
    int minutes_passed = second.time().minute() - first.time().minute();
    return days_passed * 1440 + hours_passed * 60 + minutes_passed;
}
开发者ID:dulton,项目名称:53_hero,代码行数:7,代码来源:TidesCurrents.cpp

示例7: displayText

QString ConnectionDelegate::displayText(const QVariant &value, const QLocale& locale) const
{
    if (value.type() == QVariant::DateTime) {
        QDateTime lastConnected = QDateTime(value.toDateTime());
        QDateTime currentTime = QDateTime::currentDateTimeUtc();

        int daysAgo = lastConnected.daysTo(currentTime);
        if (daysAgo <= 1 && lastConnected.secsTo(currentTime) < 86400) {
            int minutesAgo = lastConnected.secsTo(currentTime) / 60;
            int hoursAgo = minutesAgo / 60;
            if (hoursAgo < 1) {
                if (minutesAgo < 1)
                    return i18n("Less than a minute ago");
                return i18np("A minute ago", "%1 minutes ago", minutesAgo);
            } else {
                return i18np("An hour ago", "%1 hours ago", hoursAgo);
            }
        } else { // 1 day or more
            if (daysAgo < 30)
                return i18np("Yesterday", "%1 days ago", daysAgo);
            if (daysAgo < 365)
                return i18np("Over a month ago", "%1 months ago", daysAgo / 30);
            return i18np("A year ago", "%1 years ago", daysAgo / 365);
        }

    }
    // These aren't the strings you're looking for, move along.
    return QStyledItemDelegate::displayText(value, locale);
}
开发者ID:KDE,项目名称:krdc,代码行数:29,代码来源:connectiondelegate.cpp

示例8: load

void HistoryManager::load(void) {
  QString path = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/";
  QDir dir;
  if(!dir.mkpath(path)) {
    return;
  }
  QFile file(path + "history");
  if(!file.open(QIODevice::ReadOnly)) {
    return;
  }
  QByteArray array;
  while(!(array = file.readLine()).isEmpty()) {
    QString title = QString::fromUtf8(array.data()).trimmed();
    array = file.readLine();
    QString urlString = QString::fromUtf8(array.data()).trimmed();
    array = file.readLine();
    QString dateString = QString::fromUtf8(array.data()).trimmed();
    QDateTime date = QDateTime::fromString(dateString, "dd.MM.yyyy hh:mm");
    int days = SettingsManager::settingsManager()->historyExpirationDays();
    if(date.daysTo(QDateTime::currentDateTime()) < days) {
      addItem(QUrl(urlString), title, date);
    }
  }
  file.close();
}
开发者ID:Allanis,项目名称:SaraWeb,代码行数:25,代码来源:HistoryManager.cpp

示例9: endDate

StressCalculator::StressCalculator (
    QString cyclist,
	QDateTime startDate,
	QDateTime endDate,
	int shortTermDays = 7,
	int longTermDays = 42) :
	startDate(startDate), endDate(endDate), shortTermDays(shortTermDays),
	longTermDays(longTermDays),
	lastDaysIndex(-1)
{
    // calc SB for today or tomorrow?
    showSBToday = appsettings->cvalue(cyclist, GC_SB_TODAY).toInt();

    days = startDate.daysTo(endDate);

    // make vectors 1 larger in case there is a ride for today.
    // see calculateStress()
    stsvalues.resize(days+2);
    ltsvalues.resize(days+2);
    sbvalues.resize(days+2);
    xdays.resize(days+2);
    list.resize(days+2);
    ltsramp.resize(days+2);
    stsramp.resize(days+2);

    lte = (double)exp(-1.0/longTermDays);
    ste = (double)exp(-1.0/shortTermDays);
}
开发者ID:deanjunk,项目名称:GoldenCheetah,代码行数:28,代码来源:StressCalculator.cpp

示例10: makeTimeStr

QString CurrentMgr::makeTimeStr(int b)
{
    QDateTime dt;
    dt.setTime_t(b);
    return (dt.daysTo(QDateTime::currentDateTime()) > 31) ? KGlobal::locale()->formatDate(dt.date(), false)
                                                          : KGlobal::locale()->formatDateTime(dt, false);
}
开发者ID:serghei,项目名称:kde3-kdebase,代码行数:7,代码来源:toplevel.cpp

示例11: makeTimeStr

QString GlobalBookmarkManager::makeTimeStr(int b)
{
    QDateTime dt;
    dt.setTime_t(b);
    return (dt.daysTo(QDateTime::currentDateTime()) > 31)
        ? KGlobal::locale()->formatDate(dt.date(), KLocale::LongDate)
        : KGlobal::locale()->formatDateTime(dt, KLocale::LongDate);
}
开发者ID:blue-shell,项目名称:folderview,代码行数:8,代码来源:globalbookmarkmanager.cpp

示例12: QfsModDateText

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
QString QfsModDateText (QFileInfo Qi)
{
  QDateTime dt = Qi.lastModified();
  if (!dt.isValid()) return QString("Jan 06, 1965");
  if (dt.daysTo(QDateTime::currentDateTime()) > 300)
       return dt.toString("MMM dd, yyyy");
  else return dt.toString("MMM dd hh:mm");
}
开发者ID:epiktetov,项目名称:microMup07,代码行数:9,代码来源:qfs.cpp

示例13: prettyTime

QString DocumentListModel::prettyTime(QDateTime theTime)
{
    if( theTime.date().day() == QDateTime::currentDateTime().date().day() )
        return KGlobal::locale()->formatDateTime( theTime, KLocale::FancyShortDate );
    else if( theTime.daysTo( QDateTime::currentDateTime() ) < 7 )
        return KGlobal::locale()->formatDate( theTime.date(), KLocale::FancyShortDate );
    else
        return KGlobal::locale()->formatDate( theTime.date(), KLocale::ShortDate );
}
开发者ID:TheTypoMaster,项目名称:calligra,代码行数:9,代码来源:documentlistmodel.cpp

示例14: FormatDateForChat

QString FormatDateForChat(time_t time) {
    QDateTime now(QDateTime::currentDateTime());

    QDateTime *dateTime = new QDateTime();
    dateTime->setTime_t(time);

    int daysTo = dateTime->daysTo(now);
    if (daysTo == 0) {
        return "";
    } else {
        return dateTime->toString(" dd/MM");
    }
}
开发者ID:Gui13,项目名称:linphone-bb10,代码行数:13,代码来源:Misc.cpp

示例15: printDateTime

QString printDateTime(const QDateTime &datetime)
{
	QString ret;
	QDateTime current_date;
	unsigned int delta;

	current_date.setTime_t(time(NULL));
//	current_date.setTime(QTime(0, 0));

	delta = datetime.daysTo(current_date);
	ret = datetime.toString("hh:mm:ss");

	if (delta != 0)
	{
		if (config_file.readBoolEntry("Look", "NiceDateFormat"))
		{
			if (delta == 1) // 1 day ago
				ret.prepend(qApp->translate("@default", "Yesterday at "));
			else if (delta < 7) // less than week ago
			{
				ret.prepend(datetime.toString(qApp->translate("@default", "dddd at ")));
				ret[0] = ret[0].toUpper(); // looks ugly lowercase ;)
			}
			else if ((delta > 7) && (delta < 14))
			{
				int tmp = delta % 7;
				if (tmp == 0)
					ret.prepend(qApp->translate("@default", "week ago at "));
				else if (tmp == 1)
					ret.prepend(qApp->translate("@default", "week and day ago at "));
				else
					ret.prepend(qApp->translate("@default", "week and %2 days ago at ").arg(delta%7));
			}
			else if (delta < 6*7)
			{
				int tmp = delta % 7;
				if (tmp == 0)
					ret.prepend(qApp->translate("@default", "%1 weeks ago at ").arg(delta/7));
				else if (tmp == 1)
					ret.prepend(qApp->translate("@default", "%1 weeks and day ago at ").arg(delta/7));
				else
					ret.prepend(qApp->translate("@default", "%1 weeks and %2 days ago at ").arg(delta/7).arg(delta%7));
			}
			else
				ret.prepend(datetime.toString(qApp->translate("@default", "d MMMM yyyy at ")));
		}
		else
			ret.append(datetime.toString(" (dd.MM.yyyy)"));
	}
	return ret;
}
开发者ID:ziemniak,项目名称:kadu,代码行数:51,代码来源:date-time.cpp


注:本文中的QDateTime::daysTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。