summaryrefslogtreecommitdiffstats
path: root/src/corelib/time
Commit message (Collapse)AuthorAgeFilesLines
* Remove a redundant checkEdward Welbourne2021-09-021-1/+1
| | | | | | | | | | Missed in a recent fix to QTimeZonePrivate::dataForLocalTime(), but noticed during picking back to 5.12 Change-Id: I63964952150fedf857b7aef12dfc866097d2e2d1 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 7403561f2101556828b584c3af37cff028ee0969) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Fix corner case in QTimeZonePrivate::dataForLocalTime()Edward Welbourne2021-09-011-14/+18
| | | | | | | | | | | | | | | | If the local time for which we want data is after the last known transition, the two transitions we get to bracket it are the last known and an invalid one. The code checked the former was valid, but neglected to check the latter, leading to nonsense arithmetic later in the function. In this situation we unequivocally want the last known transition, so the problem is easily solved. Fixes: QTBUG-96152 Change-Id: I6fc830ce538e8a572093cd8dfe832e10689bf904 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit b656cea5deccab352b7c4c56d7023f5108578654) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Doc: Fix documentation issues for Qt CoreTopi Reinio2021-08-241-14/+14
| | | | | | | | | | | | | | | * Tag deprecated Q(Multi)Map operators in the header to correctly match them with documentation \fn commands. * Add documentation for QByteArrayView comparison operators. * Add a dummy typedef 'jfieldID' for generating docs correctly on non-Android platforms * Fix other minor issues Task-number: QTBUG-95860 Change-Id: I141d2f75d6aa10557aa374201f09ad74b4cd6e81 Reviewed-by: Paul Wicking <paul.wicking@qt.io> (cherry picked from commit 145940e1ef8fc8334ff4603a44f7896886e646cb) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QCalendarRegistry: Explicitly disable moving and copyingIevgenii Meshcheriakov2021-08-101-0/+2
| | | | | | | | | | | | | | | | | | | | Add Q_DISABLE_COPY_MOVE to QCalendarRegistry to silence the following warning produced by QtStaticAnalysisBot: class 'QCalendarRegistry' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator QCalendarRegistry is a singleton so it does not need to be moved or copied. The warning was introduced by d0ae1ef33a6eed02acde7304298794f4f0119e16. Task-number: QTBUG-93004 Change-Id: I5e018346415b9d0a1ebc3bbde2ab7c3ad5e6d9d0 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit f636a1efa5a103b63db34c97ff664e6ac8ee0502) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QCalendar: Delete registered calendar backends on program exitIevgenii Meshcheriakov2021-08-062-17/+76
| | | | | | | | | | Add code to check if the calendar registry is destroyed to all QCalendar methods that dereference QCalendarBackend pointer. Change-Id: I9b562355e2e0579396b52968f6065c6927cc9ca8 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit 84a93d94ac8dfa3c962c0dda0ab19bbd80ac50ed) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QCalendar: Thread-safe calendar backend registrationIevgenii Meshcheriakov2021-08-0615-416/+499
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | All calendar backend accounting was moved into QCalendarRegistry class (renamed from Registry). Calendar backends are no longer registered inside constructors, because in multithreaded environment this may lead to incompletely initialized instances becoming visible via QCalendar API in multithreaded environment. All system backends are registered by QCalendarRegistry itself when they are needed. New method QCalendarBackend::registerCustomBackend() is provided to register any 3rd-party calendar backends. Registration by names was also simplified. The list of names is now passed to QCalendarBackend::registerCustomBackend(). The checks are provided to ensure that all system backends have non-conflicting names. Name conflicts for custom backends are resolved in favor of earlier registered backends, as it is already the case in the existing code. The documentation was updated to reflect that. Method QCalendarBackend::names() was added to query the list of names associated with a backend after it is registered. Calendar backend deregistration was completely removed because it is not possible to perform it safely without reference counting. Fixes: QTBUG-93004 Change-Id: I0ab1eccc02fdd1e1c66b5e5dd076c93de32d5a49 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit d0ae1ef33a6eed02acde7304298794f4f0119e16) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* time: Rerun cldr2qtimezone.pyIevgenii Meshcheriakov2021-07-271-33/+33
| | | | | | | | | | | | | | | This updates qtimezoneprivate_data_p.h changing any mention of Country to Territory in it. The change was introduced by the following commit: e51831260a759b58cb089cac089c202a795fc584 There are no code changes. This reduces number of changes visible after rerunning cldr2qtimezone.py. Change-Id: I0898ecf224108604b7178e31fa7e76b4cb13a965 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit 5597e26256f37168b1da2bf8b6c1a9ab7ab2618c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QCalendar: Make SystemId constructors with one argument explicitIevgenii Meshcheriakov2021-07-271-2/+3
| | | | | | | | | This avoids unwanted type conversions. Change-Id: Ie57e80da615c6bc162224fa3816fc21a47ab4b00 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit 4679209120f02f2d2dc6a4e7a3129f3501c6024a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QCalendarBackend: Use QAnyStringView to create backends by nameIevgenii Meshcheriakov2021-07-273-17/+5
| | | | | | | | | | | | | | | Combine two implementations of QCalendarBackend::byName() accepting QStringView and QLatin1String arguments into one accepting QAnyStringView to reduce code duplication. Add a note to QCalendar constructors accepting strings to do the same for Qt 7. Change-Id: Idfc3b9c61e22712543c723bd94fcd788da52780a Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit 25170b324b7db872be2a2bde5c04eb0c1e3972e5) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Doc: Ensure deprecated APIs in Qt Core are documented as suchNico Vertriest2021-07-231-1/+1
| | | | | | | | | | | Added \deprecated [version_since] when needed Remove references to deprecated functions in \sa statements Fixes: QTBUG-94534 Change-Id: I3b3d4277d63fc5d6d207c28ff2484aed30b83247 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit a2c8184b6b241b063e9af005edf082e653dfd8a6) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Make QCalendarBackend's ID an opaque typeEdward Welbourne2021-07-198-60/+107
| | | | | | | | | | | As Giuseppe pointed out in API change review, an opaque type should be used. Task-number: QTBUG-94407 Change-Id: I862a6f52d284317e1243fd91f45bb0af130d154a Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> (cherry picked from commit 1c547698ac3ff25e7581f033886318ee98eacc0a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Make locale ordering transitiveEdward Welbourne2021-07-143-24/+24
| | | | | | | | | | | | | | | | | | | | | | | | The ordering function used to sort the locale data generated for QLocale attempted to sort the default territory for a given language and script before other territories, but was too tangled for it to be obvious this is what it was doing. The result turned out to be non-transitive. Replace with code that implements the same preference but only applies it where the result is compatible with transitivity. This leads to a shuffling of the order of the Serbian-language locales, which sorts the Cyrillic ones before the Latin ones. This is consistent with my reading of the CLDR data, which fills in Cyrillic and Serbia for Serbian; Serbian/Cyrillic/Serbia did previously sort before all other Serbian variants. Thanks to Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io> for discovering the non-transitivity. Change-Id: I0ce9f78e620e714f980f32b85b7100ed0f92ad74 Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> (cherry picked from commit 7dec56c6a5ee985f91dd2197225131c028b33650) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Fix date parsing when local time lacks the start of the dayEdward Welbourne2021-06-141-13/+26
| | | | | | | | | | | | | | | | | | | | The case where a parsed date-time fell in a transition, but only because the default value for some field lead it there, only dealt with the case of parsing a date-time, which is the only time it should be relevant. However, since the date and time do get combined as a date-time (even when only one of them is relevant) the same problem could arise when parsing a date (on which the current time-zone happened to make a transition at the start of the day) or a time (if the default date happens to be one on which the current zone had a transition). So handle both of those cases, as well as the date-time case. Fixes: QTBUG-91120 Change-Id: I565d115eb85cd2ee69fa500fcd40b05bcf8f6fff Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit f9469990d0fb1ae9444d415390ec8be483ec4ab3) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* QTimeZonePrivate: make windowsId return a QByteArrayViewMårten Nordheim2021-06-071-2/+2
| | | | | | | | In debug this cuts off about 4 seconds off of the qtimezone test on my machine. In release it's about 300-400 milliseconds. Change-Id: I92ec18794247e3846704a7c8e87a8c34fdae5e3c Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Simplify QDate::weekNumber()Edward Welbourne2021-06-071-7/+5
| | | | | | | | | Eliminate two local variables and don't even compute the year if we don't need it. Change-Id: If968c619750cead317641885a0fb9b9974954782 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QDateTime{Parser,EditPrivate}: clean up initializationEdward Welbourne2021-06-031-6/+5
| | | | | | | | Initialize members by assigning them where declared, where possible, rather than duplicating initializations in constructors. Change-Id: I35c398581ad649210aaec979ea7c6c2fc2cb0bca Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Check for overflow in QDateTime::setMSecsSinceEpoch()Edward Welbourne2021-05-261-7/+11
| | | | | | | | | | | | | | | When adding an offset from UTC, arithmetic may overflow. Likewise when combining a date and time (that have been offset for UTC). Also check the return from epochMSecsToLocalTime(), as it can fail; and pay attention to the status stored by setDateTime(), to notice when it hits an overflow. Fixed some tests that only passed because we neglected these checks. Extended a test to check we detect overflow in a couple of cases close to the extremes. Change-Id: I127a670302f94a07bb9b087b1b9c608b7c08785c Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Øystein Heskestad <oystein.heskestad@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Harmonize zoneMSecsToEpochMSecs() and localMSecsToEpochMSecs()Edward Welbourne2021-05-262-26/+27
| | | | | | | | | | | Now that the latter calls the former in its fall-back, this saves that call the need to follow up with determining DST and abbreviation. This also lets refreshZonedDateTime() update its DST guess for timezones as well as for local time. Change-Id: I820b65c1d6db78619defe2af5e947cb98ae336f0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Use time-zone transition data before 1970 as well as afterEdward Welbourne2021-05-263-165/+195
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QDateTime has long followed a convention of ignoring what it knows about time-zone transitions before the epoch. This produces unhelpful artefacts (such as an ahistorical spring-forward skipping the first hour of 1970 in Europe/London, which was in permanent DST at the time) and complicates the code. It documented that DST transitions were ignored, but in fact ignored all transitions prior to 1970 and simply assumed that the current time-zone properties (half a century later) applied to all times before 1970. This appears to be based on the fact that the MS APIs using time_t all limit their range to after 1970. Given that we have to resort to "other means" to deal with times after the end of time_t, when it's only 32-bit (and after year 3000, on MS systems), we have the means in place to handle times outside the range supported by the system APIs, so have no need to mimic this restriction. (Those means are not as robust as we might want, but they are less bad than assuming that the present zone properites were always in effect prior to 1970.) On macOS, the time_t functions only reach back to the start of 1900; it reaches to the end of its time_t range and Linux covers the whole range. Given this variety, the range is now auto-detected the first time it is needed (based on some quick and dirty heuristics). Various CET-specific tests now need adjustments in tests of times before the introduction of time-zones (when they are in fact on LMT, not CET). The systemZone() test of QTimeZone can now restore its pre-zone test cases. Various comments on tests needed updates. [ChangeLog][QtCore][QDateTime] Available time-zone information is now used to its full extent, where previously QDateTime used LocalTime's current standard time for all dates before 1970. Where we have time-zone information, it is considered reliable, so we use it. This changes the "best efforts" used for times outside the range supported by the system APIs, in most cases giving less misleading results. Fixes: QTBUG-80421 Change-Id: I7b1df7622dd9be244b0238ed9c08845fb5b32215 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Use \deprecated instead of \obsoletePaul Wicking2021-05-261-1/+1
| | | | | | Task-number: QTBUG-93990 Change-Id: I4e512354a49dde6678ca89cabc56bc76ba666bb3 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Initialize SYSTEMTIME to {} instead of memset()ingEdward Welbourne2021-05-251-12/+6
| | | | | | | Change-Id: Ic17b90d10d6b5b7f4610e904e18979fc1d658a0a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDateTime(Parser): code tidiesGiuseppe D'Angelo2021-05-252-22/+23
| | | | | | | | | | | | | Fixup a bunch of QFlags usage that ended up triggering implicit conversions. These conversions happen because QDateTime tries to save some space and shove a QFlags value in a bitfield, so there's no way around them; use explicit conversions instead. In other places: fix QFlags->bool conversions by using testAnyFlag. Change-Id: I50e8d92ed829b64ac46097c09e547e1c89cc2e35 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDateTime: fix our oversight in Qt 6.0 not changing the ShortDataThiago Macieira2021-05-152-3/+11
| | | | | | | | For 32-bit systems. They're not important (to me), but might as well fix this oversight. Change-Id: I755911ae7d0341f49039fffd167b26617db93354 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QDateTime: code tidiesGiuseppe D'Angelo2021-05-131-3/+5
| | | | | | | | | | | | Move the ValidityMask / DaylightMask enumerators in the right enumeration. This allows to use them in a type-safe way through the StatusFlags flag type. Also, define the flag operators for StatusFlags. Change-Id: Icdba7c3f49f18ffb4aff9921d8012ddc3f7cbed7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Use templated QJniObject::object() instead of static_castAssam Boudjelthia2021-05-061-9/+9
| | | | | | | Change-Id: I3bf366967d7995621aba1a7c1bec6732f3ef957d Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Ensure setDateTime clears status also when shortEdward Welbourne2021-05-041-1/+3
| | | | | | | | | | | Previously, if multiplication overflowed when trying to set the date and time of a formerly short-form QDateTime, its status didn't get set to reflect the failed validity check. Added a test that now correctly detects that it's produced an invalid date-time on overflow, where previously it produced a wrong valid date-time. Change-Id: Id46ca34d1e32e9b9b0630f3723cefd1c13b5761e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Revert early return from QTimeZone on invalid IDEdward Welbourne2021-04-291-3/+0
| | | | | | | | | | | | | | This reverts commit ec8808c3020abbc436f1a2d90fecf3245fd6417b but retains its test, as the problem it fixed is now solved by having the TZ backend validate the ID it's passed, so that it now only accepts valid POSIX zone-descriptions and valid IANA IDs. The former were being excluded by this check. Amended a POSIX test to fail with the check in place; it passes now. Change-Id: I0d5e8c6e0a315ac2509f3d23bebb52aede8f79d0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Robert Löhning <robert.loehning@qt.io>
* Handle invalid system zone case when falling back from time_t functionsEdward Welbourne2021-04-291-26/+30
| | | | | | | | | | | | | | Ammends commit 530e0bd469e6859269c2d1a792b8ce819fbff389, in which I added a QTimeZone-based fall-back for handling of conversions between local time and UTC when outside the range supported by time_t-based functions. That replaced prior kludges, when feature timezone is enabled; however, even with feature timezone, it's possible for the system zone to be invalid. So retain the old kludges also as fall-back for when the system zone is invalid, as well as when we have no timezones to fall back on. Change-Id: Ie2b8af7f1a87d7b0e39cc5ac0c04b04d574f84b5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix mix-guided use of const reference variableEdward Welbourne2021-04-291-1/+1
| | | | | | | | It needs to be a mutable value variable to be std::move()d. Pick-to: 6.1 5.15 Change-Id: I9d78b2975f8964e7a7eb06771b0069d9b9e6661e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Check POSIX rules during QTzTimeZone creationEdward Welbourne2021-04-272-15/+65
| | | | | | | | | | | | | | | | | | | | | Previously, an apparent POSIX rule would be saved and any defects in it would only be discovered when trying to use it to generate transitions. Instead, check that it has the right form during the initial parsing of its data. In the process, since checking for DST in the process is trivial, implement a long-standing TODO to cache hasDaylightTime()'s answer. The array it scanned was in any case being scanned during construction, so detecting DST in init()'s scan is trivial; and its failure to check the POSIX rule mean it failed to notice when zones entirely specified by a POSIX rule have DST. Adapt a test using a POSIX-only rule to verify it does know the zone has DST; it did not, before this change. Change-Id: I690c013d3331600f7348dae61c35d41e5599da70 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix handling of a POSIX zone rule describing permanent DSTEdward Welbourne2021-04-271-17/+44
| | | | | | | | | | | | | | | | | | | | | | | | | The description necessarily has fake transitions at start and end of the year, potentially outside the year. These transitions should not be reported by QTzTimeZonePrivate as transitions, although its data() must find a "transition" whose data it can use (as in the permanent standard time case, which could potentially be represented the same way, although there's a saner way to do so, that the code already handles) to report the zone's properties. In the process, fix (and make more straightforward) the convoluted decision-making code that was deciding which transitions to include in the returned list. It was assuming invalidMSecs() would be set as the atMSecsSinceEpoch of a transition, although this is computed in a way that makes that value most unlikely, even when the result is invalid. It also rather confusingly mixed < 0 tests as tests for overflow with the one < 0 test that's about ignoring DST before 1970. Also added comments to clarify some of what's going on there. Expanded a recently-added test of a permanent DST zone to verify this now works correctly. Change-Id: Ia8d98f433fb1e479dba5479220a62196c30f0244 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Correct the parsing of POSIX rule day-of-year fieldsEdward Welbourne2021-04-271-8/+11
| | | | | | | | | | | | | | | | | There are two formats for such fields: one with a J prefix on a number in the range 1 to 365, the other with no prefix and a range from 0 to 365. The code mistakenly treated the latter as if its range were from 1 to 366. The J-form doesn't count Feb 29th, so March always starts on day 60; the code tried to take that into account, but adjusted in the wrong direction (and this mislead me, in a recent partial fix, into a fence-post error). Add a test-case based on the Africa/Casablanca POSIX rule seen on RHEL 8.2, which tripped over the off-by-one error without a J prefix. This incidentally also tests the J case. Change-Id: I692ca511e5c960f91a6c21073d3b2f037f5e445f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Update CLDR-derived data to newly-released v39Edward Welbourne2021-04-263-631/+632
| | | | | | | | | | | | | Routine update with minor changes to locale data, no new languages, territories or scripts. Various Spanish locales change m_grouping_top from 1 to 2, reversing a change to a test of Costa Rica's currency formatting made in commit bb6a73260ec8272647265f42180963604ad0f755. Includes updates to time-zone IDs. Fixes: QTBUG-91478 Pick-to: 6.1 6.0 5.15 Change-Id: I78ee161275b3c456c5800a7317a96947c932cf8e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make zone-name part of date-time parsing a little fasterEdward Welbourne2021-04-231-2/+2
| | | | | | | | | | QDateTimeParser::findTimeZoneName()'s invalidZoneNameCharacter() check was using QLatin1String::contains(QChar), which converts the Latin-1 string to UTF-16 on each call, despite having pre-checked that the QChar is ASCII. So use memchr() instead. Change-Id: I011e2b4ba3be20711fc5005f62e4f9f6a392dd16 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDateTime: Avoid compiler warning about issue impossible at runtimeRobert Löhning2021-04-211-1/+1
| | | | | Change-Id: I6e5f76582c4caff31c56bfb4badfcc318f299f51 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* In the POSIX zone parser, handle no-DST zones the same as name-onlyEdward Welbourne2021-04-201-3/+3
| | | | | | | | | | | | If parsing the standard time data brings us to the end of the zone info, there is no DST information to use later and it makes sense to record the zone as simply a fixed-offset zone. At the same time, handle the case of empty name in the standard time data; use the zone info as name rather than an empty string. Change-Id: I34d4ea25d93d821a937949730adee89d82105bc9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Correct the range of allowed hours for a POSIX rule's transitionEdward Welbourne2021-04-201-27/+14
| | | | | | | | | | | | | | | | | | | | A POSIX rule's transition time is allowed an hour in the range from -137 to 137; in particular, a negative hour is allowed, and used by some Greenland zones using Europe's time-of-transition which, as they are more than two hours west of Greenwich, happens before midnight. This means the time of transition can't be represented by a QTime(), so propagate the int that represents it to the code that consumes it; and treat parsing failure as an error rather than "correcting" it - if the transition time is given, it must be valid. Changed tst_QTimeZone::isTimeZoneIdAvailable()'s verification of validity to report the name of the zone it thought was invalid. (A later change, validating POSIX rules, caued this to fail for America/Nuuk without the present fix.) Change-Id: I5c9127ac34d878554dd0aca1c1c7338c7e0e1c28 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make deserialization of QTimeZone less promiscuousEdward Welbourne2021-04-201-3/+6
| | | | | | | | | | | When asked to read an OffsetFromUtc record, it was trying the IANA ID it read in as a possible zone name. If the backend accepted the given ID as a zone name, however, the result might not be an offset-from-UTC zone. So extend the isValid() check it was doing on the result to at least check the zone has no DST and matches the record's offset. Change-Id: I46a95aeb2a4d66887fd56a58fa72fe5d3b568a00 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Return early from QTimeZone constructor if alleged IANA ID is invalidEdward Welbourne2021-04-201-0/+3
| | | | | | | | | | | | If the ID isn't even valid, don't waste cycles trying to make sense of it as identifying a time-zone. Add test of an invalid ID that provoked an integer overflow on trying to parse it as a POSIX zone specification. Fixes: QTBUG-92842 Change-Id: Ib80bbb88c11c0484ce0358acabbdc25c5bd8e0b3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix bug in QDateTimeParser::findTimeZoneName()'s length-limitingEdward Welbourne2021-04-201-1/+1
| | | | | | | | | | | The recent commit 0c9fc20e7ff7b4ff0f15e0b2c071ea834625dce9 missed the case of a slash after some invalid character. That could lead it to reinclude the invalid after previously working out it should ignore it. Change-Id: I3e29d2bf4d8df3878b581a969348ff5087b5d847 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Robert Löhning <robert.loehning@qt.io>
* Handle overflow in QTimeZonePrivate::dataForLocalTime() and its callerEdward Welbourne2021-04-202-19/+27
| | | | | | | | | If the final result is outside the representable range, we can only declare the given date-time invalid. Change-Id: Ibce09462048bf351199657a5da2c55bb3ce5b934 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix another compilation error in QDateTimeEirik Aavitsland2021-04-201-1/+3
| | | | | | | | | | Similar fix as 538e9fa5689a1afe0d821b84cdfeaa1656973083 : gcc 7.5, used e.g. on Jetson, is not able to resolve the add_overflow overload without help. Change-Id: I4d497480bb8dc82d7b1cbd13fda8e291935c8752 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge integration refs/builds/qtci/dev/1618564901Qt CI Bot2021-04-162-115/+162
|\
| * Use QTimeZone to determine offsets outside the system-function rangeEdward Welbourne2021-04-162-21/+61
| | | | | | | | | | | | | | | | | | | | | | | | Follow up on some comments saying "TODO Use QTimeZone when available" in converting times, outside the range supported by the system's time_t functions, between local or zone time and UTC. Since this required two formerly static functions in qdatetime.cpp to access QTimeZone's d-ptr, turn those into methods of QTZ's friend QDTPrivate. Change-Id: I27fe03d8eff9f4e98661263b1a1d4d830f4e7459 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
| * Extend time_t-based handling all the way to the end of time_tEdward Welbourne2021-04-161-100/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | At least some modern 64-bit systems have widened time_t to 64 bits fixing the "Unix time" problem. (This is even the default on MS-Win, although the system functions artificially limit the accepted range to 1970 through 3000.) Even the 32-bit range extends into January 2038 but the code was artificially cutting this off at the end of 2037. This is a preparation for using the same also all the way back to the start of time_t. In the process, simplify and tidy up the logic of the existing code, update the docs (this includes correcting some misinformation) and revise some tests. Fixes: QTBUG-73225 Change-Id: Ib8001b5a982386c747eda3dea2b5a26eedd499ad Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Catch invalid offset returns from QTimeZone backendsEdward Welbourne2021-04-162-10/+19
|/ | | | | | | | | | If the backends run into an error in computing the offset, they return INT_MIN; but they are valled via the front-end, which returns zero when the zone is invalid. So treat INT_MIN returns from the backend the same as the case of being invalid. Change-Id: Ic3c4dfe964dbfba4030c770213eca8a63e84736d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add the "Territory" enumerated type for QLocaleJiDe Zhang2021-04-1513-100/+116
| | | | | | | | | | | | | | | | | | | The use of "Country" is misleading as some entries in the enumeration are not countries (eg, HongKong), for all that most are. The Unicode Consortium's Common Locale Data Repository (CLDR, from which QLocale's data is taken) calls these territories, so introduce territory-based names and prepare to deprecate the country-based ones in due course. [ChangeLog][QtCore][QLocale] QLocale now has Territory as an alias for its Country enumeration, and associated territory-based names to match its country-named methods, to better match the usage in relevant standards. The country-based names shall in due course be deprecated in favor of the territory-based names. Fixes: QTBUG-91686 Change-Id: Ia1ae1ad7323867016186fb775c9600cd5113aa42 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* 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 Pick-to: 6.1 6.1.0 6.0 5.15 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>
* Avoid attempting to parse insanely long texts as zone namesEdward Welbourne2021-04-071-0/+18
| | | | | | | | | | | | | | There are limits on zone name length and the trial-and-error approach we're more or less forced to take to parsing gets horribly expensive if applied to every prefix of a very long string. So apply a loosened version of the zone-name validity rule that limits the length of the fragments between slashes and limit the number of such fragments. Fixes: QTBUG-92275 Pick-to: 6.1 6.0 5.15 Change-Id: I83052b1b6888728c81135db22a9c6298ae439375 Reviewed-by: Robert Löhning <robert.loehning@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge integration refs/builds/qtci/dev/1616505582Qt CI Bot2021-03-231-1/+1
|\