Commit 4c63977c authored by David Jarvie's avatar David Jarvie
Browse files

Deprecate methods analogous to QDateTime deprecated methods

KADateTime and DateTime toTime_t() and setTime_t() are deprecated,
in favour of toSecsSinceEpoch() and setSecsSinceEpoch().
parent 00831829
......@@ -1655,13 +1655,13 @@ void KADateTimeTest::set()
// time_t
utcd = KADateTime(QDate(2005, 6, 6), QTime(12, 15, 20), KADateTime::UTC);
QDateTime qtt = utcd.qDateTime();
uint secs = qtt.toSecsSinceEpoch();
qint64 secs = qtt.toSecsSinceEpoch();
KADateTime tt;
tt.setTime_t(static_cast<qint64>(secs));
tt.setSecsSinceEpoch(secs);
QVERIFY(tt.isUtc());
QCOMPARE(tt.date(), utcd.date());
QCOMPARE(tt.time(), utcd.time());
QCOMPARE(tt.toTime_t(), secs);
QCOMPARE(tt.toSecsSinceEpoch(), secs);
// Restore the original local time zone
if (originalZone.isEmpty()) {
......
......@@ -2,7 +2,7 @@
* datetime.cpp - date/time with start-of-day time for date-only values
* This file is part of kalarmcal library, which provides access to KAlarm
* calendar data.
* Copyright © 2003,2005-2007,2009-2011,2016,2018 by David Jarvie <djarvie@kde.org>
* Copyright © 2003-2019 David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published
......@@ -267,11 +267,21 @@ DateTime DateTime::toTimeSpec(const KADateTime::Spec &spec) const
return DateTime(d->mDateTime.toTimeSpec(spec));
}
qint64 DateTime::toSecsSinceEpoch() const
{
return d->mDateTime.toSecsSinceEpoch();
}
uint DateTime::toTime_t() const
{
return d->mDateTime.toTime_t();
}
void DateTime::setSecsSinceEpoch(qint64 secs)
{
d->mDateTime.setSecsSinceEpoch(secs);
}
void DateTime::setTime_t(uint secs)
{
d->mDateTime.setTime_t(secs);
......
......@@ -2,7 +2,7 @@
* datetime.h - date/time with start-of-day time for date-only values
* This file is part of kalarmcal library, which provides access to KAlarm
* calendar data.
* Copyright © 2003,2005-2007,2009,2011,2018 by David Jarvie <djarvie@kde.org>
* Copyright © 2003-2019 David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published
......@@ -187,13 +187,23 @@ public:
/** Converts the time to a UTC time, measured in seconds since 00:00:00 UTC
* 1st January 1970 (as returned by time(2)). */
uint toTime_t() const;
qint64 toSecsSinceEpoch() const;
/** Converts the time to a UTC time, measured in seconds since 00:00:00 UTC
* 1st January 1970 (as returned by time(2)). */
KALARMCAL_DEPRECATED uint toTime_t() const;
/** Sets the value to a specified date-time value.
* @param secs The date-time value expressed as the number of seconds elapsed
* since 1970-01-01 00:00:00 UTC.
*/
void setSecsSinceEpoch(qint64 secs);
/** Sets the value to a specified date-time value.
* @param secs The time_t date-time value, expressed as the number of seconds elapsed
* since 1970-01-01 00:00:00 UTC.
*/
void setTime_t(uint secs);
KALARMCAL_DEPRECATED void setTime_t(uint secs);
/** Returns a DateTime value @p secs seconds later than the value of this object. */
DateTime addSecs(qint64 n) const;
......
......@@ -3,7 +3,7 @@
This file is part of kalarmcal library, which provides access to KAlarm
calendar data. Qt5 version of KDE 4 kdelibs/kdecore/date/kdatetime.cpp.
Copyright (c) 2005-2011,2018 David Jarvie <djarvie@kde.org>
Copyright © 2005-2019 David Jarvie <djarvie@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
......@@ -1140,16 +1140,24 @@ KADateTime KADateTime::toTimeSpec(const Spec &spec) const
return KADateTime(d->toUtc(local), spec);
}
uint KADateTime::toTime_t() const
qint64 KADateTime::toSecsSinceEpoch() const
{
QTimeZone local;
const QDateTime qdt = d->toUtc(local);
if (!qdt.isValid())
return uint(-1);
return LLONG_MIN;
return qdt.toSecsSinceEpoch();
}
void KADateTime::setTime_t(qint64 seconds)
uint KADateTime::toTime_t() const
{
qint64 t = toSecsSinceEpoch();
if (static_cast<quint64>(t) >= uint(-1))
return uint(-1);
return static_cast<uint>(t);
}
void KADateTime::setSecsSinceEpoch(qint64 seconds)
{
QDateTime dt;
dt.setTimeSpec(Qt::UTC); // prevent QDateTime::setMSecsSinceEpoch() converting to local time
......@@ -1159,6 +1167,11 @@ void KADateTime::setTime_t(qint64 seconds)
d->setDtWithSpec(dt);
}
void KADateTime::setTime_t(qint64 seconds)
{
setSecsSinceEpoch(seconds);
}
void KADateTime::setDateOnly(bool dateOnly)
{
d->setDateOnly(dateOnly);
......
......@@ -2,7 +2,7 @@
This file is part of kalarmcal library, which provides access to KAlarm
calendar data. Qt5 version of KDE 4 kdelibs/kdecore/date/kdatetime.h.
Copyright (c) 2005-2011,2018 David Jarvie <djarvie@kde.org>
Copyright © 2005-2019 David Jarvie <djarvie@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
......@@ -100,9 +100,10 @@ class KADateTimeSpecPrivate;
* A KADateTime object can be converted to a different time specification by
* using toUtc() or toLocalZone(). It can be converted to a specific time zone
* by toZone(). To return the time as an elapsed time since 1 January 1970 (as
* used by time(2)), use toTime_t(). The results of time zone conversions are
* cached to minimize the need for recalculation. Each KADateTime object caches
* its UTC equivalent and the last time zone conversion performed.
* used by time(2)), use toSecsSinceEpoch(). The results of time zone
* conversions are cached to minimize the need for recalculation. Each
* KADateTime object caches its UTC equivalent and the last time zone
* conversion performed.
*
* The date and time can be set either in the constructor, or afterwards by
* calling setDate() or setTime(). To return the date and/or time components of
......@@ -701,7 +702,7 @@ public:
* with the date unchanged.
*
* @return converted time
* @see toOffsetFromUtc(), toLocalZone(), toZone(), toTimeSpec(), toTime_t(), QTimeZone::convert()
* @see toOffsetFromUtc(), toLocalZone(), toZone(), toTimeSpec(), toSecsSinceEpoch(), QTimeZone::convert()
*/
KADateTime toUtc() const;
......@@ -716,7 +717,7 @@ public:
* start of the day.
*
* @return converted time
* @see toUtc(), toOffsetFromUtc(int), toLocalZone(), toZone(), toTimeSpec(), toTime_t(), QTimeZone::convert()
* @see toUtc(), toOffsetFromUtc(int), toLocalZone(), toZone(), toTimeSpec(), toSecsSinceEpoch(), QTimeZone::convert()
*/
KADateTime toOffsetFromUtc() const;
......@@ -728,7 +729,7 @@ public:
*
* @param utcOffset number of seconds to add to UTC to get the local time.
* @return converted time
* @see toUtc(), toOffsetFromUtc(), toLocalZone(), toZone(), toTimeSpec(), toTime_t(), QTimeZone::convert()
* @see toUtc(), toOffsetFromUtc(), toLocalZone(), toZone(), toTimeSpec(), toSecsSinceEpoch(), QTimeZone::convert()
*/
KADateTime toOffsetFromUtc(int utcOffset) const;
......@@ -775,14 +776,33 @@ public:
*/
KADateTime toTimeSpec(const KADateTime &dt) const;
/**
* Converts the time to a UTC time, measured in seconds since 00:00:00 UTC
* 1st January 1970 (as returned by time(2)).
*
* @return converted time, or @c LLONG_MIN if the date is out of range or invalid
* @see setSecsSinceEpoch()
*/
qint64 toSecsSinceEpoch() const;
/**
* Converts the time to a UTC time, measured in seconds since 00:00:00 UTC
* 1st January 1970 (as returned by time(2)).
*
* @return converted time, or @c uint(-1) if the date is out of range or invalid
* @see setTime_t()
* @deprecated Use toSecsSinceEpoch()
*/
KALARMCAL_DEPRECATED uint toTime_t() const;
/**
* Sets the time to a UTC time, specified as seconds since 00:00:00 UTC
* 1st January 1970 (as returned by time(2)).
*
* @param seconds number of seconds since 00:00:00 UTC 1st January 1970
* @see toSecsSinceEpoch()
*/
uint toTime_t() const;
void setSecsSinceEpoch(qint64 seconds);
/**
* Sets the time to a UTC time, specified as seconds since 00:00:00 UTC
......@@ -790,8 +810,9 @@ public:
*
* @param seconds number of seconds since 00:00:00 UTC 1st January 1970
* @see toTime_t()
* @deprecated Use setSecsSinceEpoch()
*/
void setTime_t(qint64 seconds);
KALARMCAL_DEPRECATED void setTime_t(qint64 seconds);
/**
* Sets the instance either to being a date and time value, or a date-only
......@@ -808,7 +829,7 @@ public:
* Sets the date part of the date/time.
*
* @param date new date value
* @see date(), setTime(), setTimeSpec(), setTime_t(), setDateOnly()
* @see date(), setTime(), setTimeSpec(), setSecsSinceEpoch(), setDateOnly()
*/
void setDate(const QDate &date);
......@@ -817,7 +838,7 @@ public:
* is changed to being a date and time value.
*
* @param time new time value
* @see time(), setDate(), setTimeSpec(), setTime_t()
* @see time(), setDate(), setTimeSpec(), setSecsSinceEpoch()
*/
void setTime(const QTime &time);
......
......@@ -2526,9 +2526,7 @@ DateTime KAEvent::mainEndRepeatTime() const
void KAEvent::setStartOfDay(const QTime &startOfDay)
{
DateTime::setStartOfDay(startOfDay);
#ifdef __GNUC__
#warning Does this need all trigger times for date-only alarms to be recalculated?
#endif
#pragma message("Does this need all trigger times for date-only alarms to be recalculated?")
}
/******************************************************************************
......@@ -4186,9 +4184,7 @@ void KAEventPrivate::calcTriggerTimes() const
if (mChangeCount) {
return;
}
#ifdef __GNUC__
#warning May need to set date-only alarms to after start-of-day time in working-time checks
#endif
#pragma message("May need to set date-only alarms to after start-of-day time in working-time checks")
holidays(); // initialise mHolidays if necessary
bool recurs = (checkRecur() != KARecurrence::NO_RECUR);
if ((recurs && mWorkTimeOnly && mWorkTimeOnly != mWorkTimeIndex)
......@@ -5097,7 +5093,8 @@ bool KAEvent::convertKCalEvents(const Calendar::Ptr &calendar, int calendarVersi
// The calendar file was written by the KDE 3.0.0 version of KAlarm 0.5.7.
// Summer time was ignored when converting to UTC.
KADateTime dt(alarm->time());
const time_t t = dt.toTime_t();
const qint64 t64 = dt.toSecsSinceEpoch();
const time_t t = (static_cast<quint64>(t64) >= uint(-1)) ? uint(-1) : static_cast<uint>(t64);
const struct tm *dtm = localtime(&t);
if (dtm->tm_isdst) {
dt = dt.addSecs(-3600);
......
Supports Markdown
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