Commit 26926867 authored by David Jarvie's avatar David Jarvie
Browse files

Add KADateTime::msecsTo()

parent d9651915
......@@ -1240,6 +1240,20 @@ KADateTime KADateTime::addYears(int years) const
return result;
}
qint64 KADateTime::msecsTo(const KADateTime &t2) const
{
if (!isValid() || !t2.isValid())
return 0;
if (d->dateOnly()) {
const QDate dat = t2.d->dateOnly() ? t2.d->date() : t2.toTimeSpec(d->spec()).d->date();
return d->date().daysTo(dat) * 86400*1000;
}
if (t2.d->dateOnly())
return toTimeSpec(t2.d->spec()).d->date().daysTo(t2.d->date()) * 86400*1000;
QTimeZone local;
return d->toUtc(local).msecsTo(t2.d->toUtc(local));
}
qint64 KADateTime::secsTo(const KADateTime &t2) const
{
if (!isValid() || !t2.isValid())
......
......@@ -921,6 +921,27 @@ public:
*/
KADateTime addYears(int years) const;
/**
* Returns the number of milliseconds from this date/time to the @p other date/time.
*
* Before performing the comparison, the two date/times are converted to UTC
* to ensure that the result is correct if one of the two date/times has
* daylight saving time (DST) and the other doesn't.
*
* If one instance is date-only and the other is date-time, the date-time
* value is first converted to the same time specification as the date-only
* value, and the result is the difference in days between the resultant
* date and the date-only date.
*
* If both instances are date-only, the result is the difference in days
* between the two dates, ignoring time zones.
*
* @param other other date/time
* @return number of milliseconds difference
* @see addSecs(), daysTo()
*/
qint64 msecsTo(const KADateTime &other) const;
/**
* Returns the number of seconds from this date/time to the @p other date/time.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment