diff options
| author | Edward Welbourne <edward.welbourne@qt.io> | 2023-08-11 16:29:24 +0200 |
|---|---|---|
| committer | Edward Welbourne <edward.welbourne@qt.io> | 2023-09-15 21:53:35 +0200 |
| commit | b6761d098b6bb7835710e71e7bb7b65a2bd388df (patch) | |
| tree | 1bdce28ee85235bf337428ff15ddeae0ecb4ff0d /src/corelib/time/qlocaltime.cpp | |
| parent | 644ad1fa1aa8850ce9855f1529d74a82a32790d6 (diff) | |
Don't assume time-zone offsets at epoch were multiples of five minutes
Africa/Monrovia violates that assumption. We can replace the tests
that relied on it with another, but only when we know the offset from
UTC (to come in later commits).
Change-Id: Iccc4f03f4e0e4087530cb5ca0c7d26ee4177d01e
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src/corelib/time/qlocaltime.cpp')
| -rw-r--r-- | src/corelib/time/qlocaltime.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/corelib/time/qlocaltime.cpp b/src/corelib/time/qlocaltime.cpp index 74759e71c1a..95514485db2 100644 --- a/src/corelib/time/qlocaltime.cpp +++ b/src/corelib/time/qlocaltime.cpp @@ -78,20 +78,19 @@ public: check errno, but we call mktime from within a qt_scoped_lock(QBasicMutex), whose unlocking and destruction of the locker might frob errno.) - We can assume the zone offset is a multiple of five minutes and less than a - day, so this can only arise for the last second of a minute that differs from - 59 by a multiple of 5 on the last day of 1969 or the first day of 1970. That - makes for a cheap pre-test; if it holds, we can ask mktime about the - preceding second; if it gives us -2, then the -1 we originally saw is not an - error (or was an error, but needn't have been). + We can assume time-zone offsets are less than a day, so this can only arise + if the struct tm describes either the last day of 1969 or the first day of + 1970. That makes for a cheap pre-test; if it holds, we can ask mktime about + the preceding second; if it gives us -2, then the -1 we originally saw is not + an error (or was an error, but needn't have been). We can then synthesize a + corrected value for local using the -2 result. */ inline bool MkTimeResult::meansEnd1969() { #ifdef Q_OS_WIN return false; #else - if (local.tm_sec < 59 || local.tm_year < 69 || local.tm_year > 70 - || local.tm_min % 5 != 4 // Assume zone offset is a multiple of 5 mins + if (local.tm_year < 69 || local.tm_year > 70 || (local.tm_year == 69 // ... and less than a day: ? local.tm_mon < 11 || local.tm_mday < 31 : local.tm_mon > 0 || local.tm_mday > 1)) { |
