path: root/src/corelib/tools/qdatetime_p.h
diff options
authorJohn Layt <>2013-08-19 16:50:54 +0200
committerThe Qt Project <>2013-09-20 23:45:06 +0200
commit7b07c3ff781c9fcdaf7a60aabed9b7aa57e25006 (patch)
tree6bcf141cb1d0e97234746a131fc1335a38eb43f4 /src/corelib/tools/qdatetime_p.h
parent18322bfabc3c349040bb370167e2642dc734bd50 (diff)
QDateTime - Fix Daylight Transition for "missing" hour
When Daylight Time transtion goes from Standard Time to Daylight Time there is a "missing" hour, i.e. at 2am CET the clock goes forward to 3am. Currently QDateTime ignores this gap and considers the time to be valid and able to be manipulated. This change respects the transition, so any time set in the missing hour is considered invalid, and any date maths returns valid results. The validity in the current time zone needs to be checked every time isValid() is called in case the system time zone has changed since the last time it was checked. This is done by calling mktime to check the returned result matches the expected result. This could be very inefficient, but the returned offset value is cached each time so mktime is not required to be called again within each method call, effectively meaning mktime is called the same number of times by each method. Note that this means any new methods added must be careful to ensure either isValid() or refreshLocalTime() is called first by any method needing to use the UTC value. [ChangeLog][QtCore][QDateTime] The Standard Time to Daylight Time transition for Qt::LocalTime is now handled correctly. Any date set in the "missing" hour is now considered invalid. All date math results that fall into the missing hour will be automatically adjusted to a valid time in the following hour. Change-Id: Ia652c8511b45df15f4917acf12403ec01a7f08e7 Reviewed-by: Thiago Macieira <>
Diffstat (limited to 'src/corelib/tools/qdatetime_p.h')
1 files changed, 10 insertions, 0 deletions
diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h
index 124bd98a31..7fd36bc4e0 100644
--- a/src/corelib/tools/qdatetime_p.h
+++ b/src/corelib/tools/qdatetime_p.h
@@ -86,6 +86,7 @@ public:
NullTime = 0x02,
ValidDate = 0x04,
ValidTime = 0x08,
+ ValidDateTime = 0x10
Q_DECLARE_FLAGS(StatusFlags, StatusFlag)
@@ -114,11 +115,20 @@ public:
void setDateTime(const QDate &date, const QTime &time);
void getDateTime(QDate *date, QTime *time) const;
+ // Returns msecs since epoch, assumes offset value is current
+ inline qint64 toMSecsSinceEpoch() const { return (m_msecs - (m_offsetFromUtc * 1000)); }
+ void checkValidDateTime();
+ void refreshDateTime();
// Get/set date and time status
inline bool isNullDate() const { return (m_status & NullDate) == NullDate; }
inline bool isNullTime() const { return (m_status & NullTime) == NullTime; }
inline bool isValidDate() const { return (m_status & ValidDate) == ValidDate; }
inline bool isValidTime() const { return (m_status & ValidTime) == ValidTime; }
+ inline bool isValidDateTime() const { return (m_status & ValidDateTime) == ValidDateTime; }
+ inline void setValidDateTime() { m_status = m_status | ValidDateTime; }
+ inline void clearValidDateTime() { m_status = m_status & ~ValidDateTime; }
static inline qint64 minJd() { return QDate::minJd(); }
static inline qint64 maxJd() { return QDate::maxJd(); }