summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-02-22 16:35:44 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2021-03-01 16:45:07 +0100
commit83421e320b8b0b2ddd528a280609cbb7f2cb7781 (patch)
treed855d1f98e3c63a6a18d258008c7f852a16ea2d9 /src
parent4a07947375ec3a6f353f1ed04024b1d6eb17177c (diff)
Try again if mktime() fails when we thought we knew DST-ness
When refreshing a QDateTime(,, Qt::LocalTime) we call mktime on data obtained from it, passing in the DST status (when known; this keeps two otherwise identical times in a fall-back distinct). One of the tests relies on changing zone under the feet of such a date-time, created in Hawaiian standard time; it serializes it, the reads it back in Western Australian Daylight-saving time and expects the results to be equal. However, the two differ in DST-ness, which leads to mktime() failing for the Hawaiian original, with unwelcome results. Notice this case, failure with DST-ness claimed known, and retry without the claim, so as to correct the DST-ness. Change-Id: Id0278df53130f76fc587769efe946ca9af1adc26 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/time/qdatetime.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp
index ea09120e30..26e25afd38 100644
--- a/src/corelib/time/qdatetime.cpp
+++ b/src/corelib/time/qdatetime.cpp
@@ -2457,6 +2457,12 @@ static qint64 qt_mktime(QDate *date, QTime *time, QDateTimePrivate::DaylightStat
int hh = local.tm_hour;
#endif // Q_OS_WIN
time_t secsSinceEpoch = qMkTime(&local);
+ // That can fail if we thought we knew DST-ness, but were wrong:
+ if (secsSinceEpoch == time_t(-1) && local.tm_isdst >= 0) {
+ local.tm_isdst = -1;
+ secsSinceEpoch = qMkTime(&local);
+ }
+
if (secsSinceEpoch != time_t(-1)) {
*date = QDate(local.tm_year + 1900, local.tm_mon + 1, local.tm_mday);
*time = QTime(local.tm_hour, local.tm_min, local.tm_sec, msec);