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>
This commit is contained in:
parent
4a07947375
commit
83421e320b
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user