diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2018-06-13 18:12:28 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2020-08-11 11:20:43 +0200 |
commit | 72d14fe32f8ea8f0a00f276aa37611bc9a2ae702 (patch) | |
tree | 36c16dc93b69db706d80dfed84c0b5f20a14a665 /src/corelib/time | |
parent | 1f96709fdb78045bf5ed895c318e48f55ec29bf2 (diff) |
Fix handling of last second in 1969
Due to a limitation of mktime(), we would have declared it invalid.
Tidied up qt_mktime() slightly in the process.
Change-Id: I25469e314afee6e0394e564bc69a98883005d4ec
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/time')
-rw-r--r-- | src/corelib/time/qdatetime.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 5e1e620ec2..6337557bc8 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -2441,24 +2441,26 @@ static qint64 qt_mktime(QDate *date, QTime *time, QDateTimePrivate::DaylightStat local.tm_isdst = 1; } #endif // Q_OS_WIN - if (local.tm_isdst >= 1) { + if (local.tm_isdst > 0) { if (daylightStatus) *daylightStatus = QDateTimePrivate::DaylightTime; if (abbreviation) *abbreviation = qt_tzname(QDateTimePrivate::DaylightTime); - } else if (local.tm_isdst == 0) { - if (daylightStatus) - *daylightStatus = QDateTimePrivate::StandardTime; - if (abbreviation) - *abbreviation = qt_tzname(QDateTimePrivate::StandardTime); } else { - if (daylightStatus) - *daylightStatus = QDateTimePrivate::UnknownDaylightTime; + if (daylightStatus) { + *daylightStatus = (local.tm_isdst == 0 + ? QDateTimePrivate::StandardTime + : QDateTimePrivate::UnknownDaylightTime); + } if (abbreviation) *abbreviation = qt_tzname(QDateTimePrivate::StandardTime); } - if (ok) - *ok = true; + } else if (yy == 1969 && mm == 12 && dd == 31 + && time->second() == MSECS_PER_DAY - 1) { + // There was, of course, a last second in 1969, at time_t(-1); we won't + // rescue it if it's not in normalised form, and we don't know its DST + // status (unless we did already), but let's not wantonly declare it + // invalid. } else { *date = QDate(); *time = QTime(); @@ -2468,9 +2470,12 @@ static qint64 qt_mktime(QDate *date, QTime *time, QDateTimePrivate::DaylightStat *abbreviation = QString(); if (ok) *ok = false; + return 0; } + if (ok) + *ok = true; - return ((qint64)secsSinceEpoch * 1000) + msec; + return qint64(secsSinceEpoch) * 1000 + msec; } // Calls the platform variant of localtime for the given msecs, and updates |