summaryrefslogtreecommitdiffstats
path: root/src/corelib/time/qtimezoneprivate_tz.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Make POSIX transition rule parser more robustEdward Welbourne2021-04-141-14/+29
| | | | | | | | | | | | | | | | | | | | | | | | | The POSIX rule parser used by QTzTimeZonePrivate recklessly assumed that, if splitting the rule on a dot produced more than one part, it necessarily produced at least three. That's true for well-formed POSIX rules, but we should catch the case of malformed rules. Likewise, when calculating the dates of transitions, splitting the date rule on dots might produce too few fragments; and the fragments might not parse as valid numbers, or might be out of range for their respective fields in a date. Check all these cases, too. Added a test that crashed previously. Changed QTimeZone::offsetFromUtc() so that its "return zero on invalid" applies also to the case where the backend returns invalid, in support of this. Fixes: QTBUG-92808 Change-Id: Ica383a7a987465483341bdef8dcfd42edb6b43d6 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Robert Löhning <robert.loehning@qt.io> (cherry picked from commit 964f91fd25a59654905c5a68d3cbccedab9ebb5a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Restore support for reading /etc/timezone for system zone nameEdward Welbourne2021-04-121-7/+15
| | | | | | | | | | | | This restores one of the two mechanisms removed in commit b0383cbd388336f698ceeac11a4f50cdff931dd9, transformed to fit in with the new cached system-zone determination. Fixes: QTBUG-87326 Change-Id: Ic270acb0d958e17dbc74a0ff93a5a1843c939678 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 824d963700a91294ba4a543ebb486aedbd650284) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QTzTimeZonePrivate::init(): fix handling of empty IDEdward Welbourne2021-02-021-7/+13
| | | | | | | | | | | | | | | | | We were using the first abbreviation in the list, where the current time's one is probably more apt. We look up displayName() using ICU, when in use, but that abbreviatio may be unknown to it. So ensure, when using abbreviation in place of empty id, that we get the system zone for ICU, for use if we're asked for the display name. This is a follow up to b12d6c6a8ab5f7b01bdd2cb862a66a409700faa1. Change-Id: I177db55de1ffbc763def8a0423642f2b3da74fa6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 3c9013b76a6f4214f469613baf7ae5225b649660) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Fix handling of Sunday in POSIX time-zone rulesEdward Welbourne2021-02-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | Dating from the origins of our support for the zoneinfo file format, the mapping of POSIX's day-numbering (0 = Sunday through 6 = Saturday, see [*]) to Qt's (1 = Monday through 7 = Sunday) was done by mapping 0 to 1, when it should have been 7. [*] http://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html Corrected a QTimeZone test that trusted the results it got without checking which day of the week those were: they were all Mondays. Verified that the corrected dates are in fact Sundays. Checked the zone abbreviations, too. Fixes: QTBUG-90553 Change-Id: I84b4b14f9892ff687918cd3c42c7c9807e45313c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> (cherry picked from commit 38a72af4fd311219779f89b2b78cd56d879f61db) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Fix QTzTimeZonePrivate::displayName()'s fallbackEdward Welbourne2021-01-201-1/+2
| | | | | | | | | | It previously fell back on abbreviation, a very poor choice. The base class does better than that, so use its implementation instead. Change-Id: I47cbfce815cd8b2b533d9c6aeebcf398e5852d02 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit f9fff26b2db8152dcae26c92054f031bdebd7bc1) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Bounds-check time-zone offsets when parsingEdward Welbourne2020-11-271-11/+16
| | | | | | | | | | | | | | | | Parsing of time-zone offsets should check the offset string conforms to the expected format and has valid values in its fields. The QDateTime parser, fromOffsetString(), neglected the bounds check on hours; the QTzTimeZonePrivate parser, parsePosixTime(), neglected all upper bounds checks, only checking against negative valus. Drive-by - refined phrasing of a comment. Fixes: QTBUG-88656 Change-Id: If04cdbe65064108eaa87c42310527783ad21b4c0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 380d97e1bd15e753907c378a070bdf7f1c1cf06e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Prevent time zone lookup from using infinite amounts of memoryAndreas Buhr2020-11-191-6/+6
| | | | | | | | | | | | The QTzTimeZoneCache created one cache entry for every time zone which was looked up, even if the code was invalid. This uses some memory for each time zone code queried and thus allows DOS attacks if user supplied time zone codes are parsed. This patch changes the cache to use QCache instead of QHash and thus only store up to 100 zones in the cache. Change-Id: Ia87fe500b8b9cf23dced5448a33b047702515f19 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Don't guess UTC when we can't find a system zone nameEdward Welbourne2020-09-281-8/+10
| | | | | | | | | | | | | | | | | | | | | | | | | If we're able to load a system zone without knowing its name, we shouldn't claim that its name is UTC. Instead, use the system zone information's name for the zone. Let the backend return an empty string if it can't determine the system zone ID, provided it has some way to get system zone info despite not knowing its name. This can happen on Windows if the system zone is one of Microsoft's idiosyncratic names that we don't recognize; or on Linux if /etc/timezone is a copy of a zoneinfo file, instead of a symlink. In support of that, handle empty ID as a request for system zone info, so that the backend constructors taking an IANA ID never get passed an empty ID; that gets routed to the default constructor instead. This incidentally restores QTzTimeZonePrivate's behavior, for empty ID, of reading the content of /etc/timezone if we are unable to determine the name of its zone any other way. Fixes: QTBUG-86306 Pick-to: 5.15 5.15.1 Change-Id: Iad57c18199124f651ebc3d32c3deffca6eaab512 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Move QStringRef and remains to Qt5CompatKarsten Heimrich2020-08-201-1/+1
| | | | | | | | | Export some private functions from QUtf8 to resolve undefined symbols in Qt5Compat after moving QStringRef. Task-number: QTBUG-84437 Change-Id: I9046dcb14ed520d8868a511d79da6e721e26f72b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Add ; to Q_UNUSEDLars Schmertmann2020-07-071-5/+5
| | | | | | | | This is required to remove the ; from the macro with Qt 6. Task-number: QTBUG-82978 Change-Id: I3f0b6717956ca8fa486bed9817b89dfa19f5e0e1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Use QList instead of QVector in corelib implementationJarek Kobus2020-06-291-18/+18
| | | | | | | | Omitting state machine and docs for now. Task-number: QTBUG-84469 Change-Id: Ibfa5e7035515773461f6cdbff35299315ef65737 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Port qdatetime away from QStringRefLars Knoll2020-06-121-1/+1
| | | | | | | | Task-number: QTBUG-84319 Change-Id: Ieeb25933a8062bdf0d2835f4d78e86daac1e8720 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Cache system zone ID when fetched from the file-systemEdward Welbourne2020-05-281-64/+141
| | | | | | | | | | | | | | Record the device and inode numbers when found and assume we can safely re-use the name if those have not changed. Tidy up some preprocessor trivia in the process and moved zone-availability check functions to before the system name lookup. Pick-to: 5.15 Task-number: QTBUG-75585 Change-Id: I3660922ef3c94b553a20f887a676e8921693b30f Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QtCore: fix a few more char/int/uint -> QChar conversionsMarc Mutz2020-04-301-1/+1
| | | | | | | | They were masked by all QChar ctors being made explicit, except the char16_t one, which was left as the only viable choice. Change-Id: I5632795f3c7dd1de3830285d5446d9b994613466 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge remote-tracking branch 'origin/5.14' into 5.15Qt Forward Merge Bot2020-04-081-25/+5
|\ | | | | | | Change-Id: I34a71ddbc6afb1f12a0a044d0d3876e1af58d60c
| * Purge two old time-zone lookup fallbacksEdward Welbourne2020-04-071-23/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We used to need to consult /etc/timezone for the zone name back when Debian, up to Jessie, used a copy of the zoneinfo file as /etc/localtime, instead of a symlink. Jessie's end of life is this May, but Thiago reports that its gcc can't build Qt 5.14, so we may as well remove this fall-back. Newer versions of Debian use a symlink. We used to need to consult /etc/sysconfig/clock for this information back when ancient Red Hat distros copied zoneinfo to /etc/localtime instead of symlinking, but Thiago believes that's now ancient history. So, again, remove this old fallback. Change-Id: I73cb40b926186b311dac6f00fe8743d37a9dfce5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
| * Ensure QTzTimeZonePrivate always tries a non-empty IANA IDEdward Welbourne2020-04-071-2/+5
| | | | | | | | | | | | | | | | | | | | | | QTzTimeZonePrivate::init() was coping with empty and then saving the system ID if the ID it looked up was empty. Better to have its caller ensure it's passed the system ID in place of empty. The system ID is always non-empty, as it falls back to "UTC" if it would otherwise have been empty. Change-Id: I5c74e23f01ef578de0dc1f6d558e9c8c7e65ff53 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | Merge remote-tracking branch 'origin/5.14' into 5.15Qt Forward Merge Bot2020-04-031-20/+13
|\| | | | | | | | | | | | | Conflicts: tests/benchmarks/corelib/text/qstringlist/qstringlist.pro Change-Id: Ie9b97bd83c2df00fd9b556b5f09d405f71970169
| * Clean up QTzTimeZonePrivate::systemTimeZoneId()Edward Welbourne2020-04-021-20/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The special handling of ":/etc/localtime" should only apply if that's the exact value of $TZ; the old code would have treated "/etc/localtime" the same, due to stripping a leading ':' before checking for it. We can also test whether to do that stripping using startsWith(). When reading the content of files, avoid QTextStream's trip via QString and back to QByteArray by using the QFile's readLine() directly, or by using readAll(). Task-number: QTBUG-75585 Change-Id: I1524529a2c34d83a9fbd00d41c11f2d994dfc49d Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | Merge remote-tracking branch 'origin/5.14' into 5.15Liang Qi2020-03-241-53/+88
|\| | | | | | | | | | | | | Conflicts: src/plugins/platforms/xcb/qxcbdrag.cpp Change-Id: I0b47324b70b0b4894e54b21aa3e7a5041f9bd5e3
| * qtimezoneprivate_tz: Apply a cache over the top of timezone dataRobin Burchell2020-03-201-53/+88
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Constantly re-reading the timezone information only to be told the exact same thing is wildly expensive, which can hurt in operations that cause a lot of QTimeZone creation, for example, V4's DateObject - which creates them a lot (in DaylightSavingTA). This performance problem was identified when I noticed that a QDateTime binding updated once per frame was causing >100% CPU usage (on a desktop!) thanks to a QtQuickControls 1 Calendar (which has a number of bindings to the date's properties like getMonth() and so on). The newly added tst_QTimeZone::systemTimeZone benchmark gets a ~90% decrease in instruction count: --- before +++ after PASS : tst_QTimeZone::systemTimeZone() RESULT : tst_QTimeZone::systemTimeZone(): - 0.024 msecs per iteration (total: 51, iterations: 2048) + 0.0036 msecs per iteration (total: 59, iterations: 16384) Also impacted (over in QDateTime) is tst_QDateTime::setMSecsSinceEpochTz(). The results here are - on the surface - less impressive (~0.17% drop), however, it isn't even creating QTimeZone on a hot path to begin with, so a large drop would have been a surprise. Added several further benchmarks to cover non-system zones and traverse transitions. Done-With: Edward Welbourne <edward.welbourne@qt.io> Task-number: QTBUG-75585 Change-Id: I044a84fc2d3a2dc965f63cd3a3299fc509750bf7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Tidy nullptr usageAllan Sandfeld Jensen2019-12-061-1/+1
|/ | | | | | | | | | | Move away from using 0 as pointer literal. Done using clang-tidy. This is not complete as run-clang-tidy can't handle all of qtbase in one go. Change-Id: I1076a21f32aac0dab078af6f175f7508145eece0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Move YearRange to QDateTime from its PrivateEdward Welbourne2019-07-011-3/+2
| | | | | | | | | | | | | | | | | As planned when adding YearRange: now that it's merged up to dev, move it to QDateTime, since we can add to the API at 5.14.0. This follows up on commit 82ad4be4a2e0c2bccb6cd8ea2440aefee4ec48ec. Change-Id: I81b6c2331121a71e2592514781c02c5756e70c52 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTimeZone: avoid needless QString instancesRolf Eike Beer2019-06-191-3/+3
| | | | | | | | | | | | Change-Id: I250bfb58c04b2c013285c8ebd6db1f964f0b7b29 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge remote-tracking branch 'origin/5.13' into devLiang Qi2019-06-141-5/+38
| | | | | | | | | | Conflicts: qmake/generators/makefile.cpp qmake/generators/unix/unixmake2.cpp src/corelib/thread/qthread_unix.cpp tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp Change-Id: I1df0d4ba20685de7f9300bf07458c13376493408
* Separate out the time, zone, date code from corelib/tools/Edward Welbourne2019-06-061-0/+1154
We'll be adding calendar code here as well, and tools/ was getting rather crowded, so it looks like time to move out a reasonably coherent sub-bundle of it all. Change-Id: I7e8030f38c31aa307f519dd918a43fc44baa6aa1 Reviewed-by: Lars Knoll <lars.knoll@qt.io>