summaryrefslogtreecommitdiffstats
path: root/src/corelib/time/qdatetimeparser.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Merge remote-tracking branch 'origin/tqtc/lts-5.15.10' into ↵v5.15.10-lts-lgplTarja Sundqvist2023-04-241-4/+9
|\ | | | | | | | | | | tqtc/lts-5.15-opensource Change-Id: Ic1bb4240ca70a8a361fa0267476707446579221d
| * Fix assertion failure when parsing a doubly-invalid date-time textEdward Welbourne2022-04-251-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the date-time string falls in a spring-forward (so is invalid) and one of the fields of the parsed string doesn't match the format it's meant to (e.g. a single-digit seconds field when format ss was specified), a check that the current fall-back date-time is between the minimum and maximum for the parser object failed, triggering an assertion. In any case, an invalid default-value wasn't useful to the code that parsed a single section of the date-time string, so brute-force the current value to a valid date-time (when possible) using the usual round-trip via milliseconds since the epoch. Added the test-case which first revealed the problem, plus a couple more informed by it, to exercise the same code-paths with fewer things failing. (For 5.15: converted u"..."_qs to QStringLiteral("...").) Fixes: QTBUG-102199 Change-Id: I658308614505ef25f4c97d0de6148acb54a65a0f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 9fee35a2eda68b5968d911d5e14d298b91418d2c) Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
* | Merge remote-tracking branch 'origin/tqtc/lts-5.15.6' into ↵Tarja Sundqvist2022-08-161-13/+26
|\| | | | | | | | | | | tqtc/lts-5.15-opensource Change-Id: Ia9164a17d80376f0a3ab9752c4a9f4dd2f0bd3d9
| * 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>
* | Merge remote-tracking branch 'origin/tqtc/lts-5.15.4' into ↵Tarja Sundqvist2022-04-071-0/+18
|\| | | | | | | | | | | tqtc/lts-5.15-opensource Change-Id: I3d223d54a832c8365fec4b399550da79f4c1abbb
| * 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 Change-Id: I83052b1b6888728c81135db22a9c6298ae439375 Reviewed-by: Robert Löhning <robert.loehning@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 0c9fc20e7ff7b4ff0f15e0b2c071ea834625dce9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* | Revert "Update commercial license headers to src/concurrent and src/corelib"Tarja Sundqvist2021-03-231-20/+20
|/ | | | | | | | | | | This reverts commit b98b16de25dd5463342a2165a20b5fdc1cf9c32a. Revert of commercial license headers is required for Qt 5.15.3 opensource release. Task-number: QTBUG-91108 Change-Id: I51f2e169ec144ab9b902df2cff87eae60df53c57 Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
* Update commercial license headers to src/concurrent and src/corelibTarja Sundqvist2021-01-281-20/+20
| | | | | | | | | | | | | | | | | | | Updated the header.COMM to the files under tqtc-qtbase/src/concurrent and tqtc-qtbase/src/corelib. Note! The following files are not updated: - the .qdoc files with the FDL license headers - the .cpp files with BSD license headers The commercial license header may contain some additional lines so that its line count equals with the earlier license header. Reason for this is that some autotests use hard coded line numbers and changing the line count would cause test failures. Task-number: QTQAINFRA-4154 Change-Id: I37a4dc8c89b0a84d78ca890a61e212966d8b20b5 Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
* Make QDateTimeParser recognize local time offsetsAndrei Golubev2020-05-281-13/+10
| | | | | | | | Fixes: QTBUG-84209 Change-Id: Iedbc7beafcaa55c72fec3ac5a5f519c6ed5f7770 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit cfbb30decda13fb630127246af5bea32c5f4da57) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Teach QDateTimeParser some common time-zone offset formatsAndrei Golubev2020-05-201-56/+137
| | | | | | | | Fixes: QTBUG-83687 Fixes: QTBUG-83844 Change-Id: Ia1c827017b93cf8277aa5a0266805d773d2d9818 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit bed25fdf6065d7137fa5610e4f214e9a8f8e172b)
* Make qtbase compile without QT_CONFIG(timezone)Andrei Golubev2020-05-201-3/+6
| | | | | | | | | Fixes: QTBUG-83795 Change-Id: I05eaaf57d87a9111d3609ebab81bc707f8af98f0 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit b428e98052aa1b97a42f31ed52b1266d17e186ee) Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Make t specifier for time-zone only apply to date-timeEdward Welbourne2020-04-231-1/+1
| | | | | | | | | It previously applied to dates and date-times, but was documented as applying to times (and date-times then included it by reference). It's only meaningful for a date-time. Change-Id: Id9e8e8cb987b03e5ddc77b05c581b9b6944065fc Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Handle specified time-spec in date-time parsingAndrei Golubev2020-04-221-28/+46
| | | | | | | | | | | | | | | | | | | | | | When a date-time was parsed from a string, the result was equal (as a date-time) to the correct value, but had (at least in some cases) the wrong spec, where it should have had a spec reflecting the zone specifier parsed. The time-spec imposed for the benefit of QDateTimeEdit is now moved from QDateTimeParser to QDateTimeEditPrivate, which takes over responsibility for imposing it. QDateTimeParser assumes Qt::LocalTime in member functions (where applicable) and uses the time-spec parsed from the string when constructing the date-time. QDateTime::fromString() and QLocale::toDateTime() are updated to use the full QDateTime returned by QDateTimeParser. Fixes: QTBUG-83075 Done-With: Edward Welbourne <edward.welbourne@qt.io> Change-Id: I8b79add2c7fc13a200e1252d48dbfa70b36757bf Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Fix QDateTimeEdit's handling of invalid time in dst gapVolker Hilsheimer2020-02-271-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | During a spring forward, a time-zone omits an hour. A QDateTime with such an hour is invalid, but QDateTimeEdit's handling of this invalid time was not done correctly. With this fix, up/down changes of any field that would result in an invalid date-time corrects the time to be valid, while leaving as much as possible of the user-entered data unchanged. To do that, we rely on QDateTime::toMSecsSinceEpoch to return a value even for such an invalid time, which then can be used to construct a valid QDateTime. Edits that would result in an invalid hour are reverted to the previous when pressing return, if correctionMode is CorrectToPreviousValue. This change also implements support for CorrectToNearestValue, which uses the same mechanism as when stepping over an invalid time. Include a test that verifies that the various interactions result in a reasonable value. Since QDateTimeEdit does not respect the timezone or timespec of the QDateTime it is initialized with, we have to find the first hour of daylight saving time for a year that we know works for most time zones. Failing that, we have to skip the tests. Verified in a wide range of time zones. Change-Id: I05b906ae3b5f6681891d23704f00f9c10cd479ae Fixes: QTBUG-79803 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Merge remote-tracking branch 'origin/5.14' into 5.15Qt Forward Merge Bot2020-02-061-12/+25
|\ | | | | | | | | | | | | Conflicts: src/network/ssl/qsslsocket_openssl_symbols.cpp Change-Id: I8c13b5c48a8ecce96540b39c6d5f8ca146eb2339
| * Coding style: put case bodies on separate lines from the case labelEdward Welbourne2020-02-051-12/+25
| | | | | | | | | | | | | | | | | | While the single-line-case format is more readable when consistently applied through the whole switch, it works less well when several of the cases are too complex to fit on a single line. Change-Id: I6a84a3d3d1493dadddab103da0336a8ef860563c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* | Merge remote-tracking branch 'origin/5.14' into 5.15Qt Forward Merge Bot2020-02-041-1/+1
|\| | | | | | | | | | | | | | | | | | | Conflicts: .qmake.conf examples/widgets/widgets/imageviewer/imageviewer.cpp src/corelib/text/qchar.cpp src/corelib/time/qdatetime.cpp Change-Id: I9762f5c4ff650799219729d6aee79ac07ce9024a
| * Pass QDate and QTime by value in various static and local functionsEdward Welbourne2020-01-311-1/+1
| | | | | | | | | | | | | | They're value types, so pass them as such. Change-Id: I0dc46c63a3a0e6d859b821362f71390f0148b64c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Replace most use of QVariant::type and occurrences of QVariant::TypeOlivier Goffart2020-01-231-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I made a clazy automated check that replaced the use of QVariant::Type by the equivalent in QMetaType. This has been deprecated since Qt 5.0, but many uses were not yet removed. In addition, there was some manual changes to fix the compilation errors. Adapted the Private API of QDateTimeParser and QMimeDataPrivate and adjust QDateTimeEdit and QSpinBox. QVariant(QVariant::Invalid) in qstylesheet made no sense. But note that in QVariant::save, we actually wanted to use the non-user type. In the SQL module, many changes were actually reverted because the API still expects QVarient::Type. Change-Id: I98c368490e4ee465ed3a3b63bda8b8eaa50ea67e Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* | Merge remote-tracking branch 'origin/5.14' into 5.15Qt Forward Merge Bot2020-01-151-15/+14
|\| | | | | | | Change-Id: I8dbcf23835d52d3aa7d018ed250814d60c68aa83
| * Do fewer calendrical calculations in QDateTimeParser::setDigit()Edward Welbourne2020-01-141-15/+14
| | | | | | | | | | | | | | | | | | | | | | It was calling a QDate's year(), month() and day() methods, each of which repeats most of the same calendrical calculations; and the same results can be obtained from the calendar's partsFromDate() all in one go. This also reduces the number of local variables needed. Change-Id: I8f84e66a5f677f55cb2113c56ebbdf7c2517e828 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Merge remote-tracking branch 'origin/5.14' into 5.15Liang Qi2019-12-101-1/+1
|\| | | | | | | | | | | | | Conflicts: tests/auto/network/kernel/qnetworkinterface/BLACKLIST Change-Id: I1e8866c63b54bcd95fc2a044276ee15b7f60e79a
| * Fix crash when a date-time has an invalid time-zoneEdward Welbourne2019-12-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QDateTime is a friend of QTimeZone, so can access its internals; but it must check the zone is valid before doing so. Expanded tst_QDateTime::invalid() and made it data-driven to catch the failure cases. Commented on a test-case that caught a mistake in my first attempt at this, and on QDateTimeParser's surprising reliance on a quirk of QDateTime::toMSecsSinceEpoch()'s behavior. Fixes: QTBUG-80146 Change-Id: I24856e19ff9bf402152d17d71f83be84e366faad Reviewed-by: Alex Blasche <alexander.blasche@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>
* | Merge remote-tracking branch 'origin/5.14' into 5.15Qt Forward Merge Bot2019-12-041-7/+5
|\| | | | | | | Change-Id: Ia70e81943ef097941339f9ef9ace28592a2eb740
| * Relocate a comment that had become detached from its codeEdward Welbourne2019-12-031-7/+5
| | | | | | | | | | | | | | | | Two little tool functions had come between it and the function it actually describes. Change-Id: Ib49d1623833275ea79c7916fece29aed9503aa40 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* | Deprecate constructing QFlags from a pointerAllan Sandfeld Jensen2019-11-201-2/+2
|/ | | | | | | | | This was used to support QFlags f = 0 initialization, but with 0 used as a pointer literal now considered bad form, it had been changed many places to QFlags f = nullptr, which is meaningless and confusing. Change-Id: I4bc592151c255dc5cab1a232615caecc520f02e8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Rename calendar methods from m{in,ax} to m{in,ax}imumEdward Welbourne2019-09-041-12/+14
| | | | | | | | | Words should not be abbreviated. Split a long line and reflowed some comments in the process. Fixes: QTBUG-78008 Change-Id: I52d75409f02e2cecbed3e94d424617ad594c275b Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QDateTimeParser: replace QVector with QVarLengthArray<12>Marc Mutz2019-08-301-3/+6
| | | | | | | | | | | | | The lists of month and day-of-week names usually currently do not exceed 13 elements (incl. possible leap months), so don't use QVector, use QVarLengthArray with Prealloc = 13. This value may be increased when ISO week-as-month is merged, but the container remains valid even with 52 "months" (though the code that calculates its runtime size will naturally need to be adjusted). Change-Id: I4ead897d933f89fc092850fcc22ca41da0a6ddc6 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Add support for calendars beside GregorianSoroush Rabiei2019-08-201-73/+92
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add QCalendarBackend as a base class for calendar implementations and QCalendar as a facade via which to access it. QDate's implicit implementation of the Gregorian calendar becomes QGregorianCalendar and QDate methods now support choice of calendar. Convert QLocale's CLDR data for month names to a locale-data component of each supported calendar and relevant QLocale methods now support choice of calendar. Adapt Python scripts for locale data generation to extract month name data from CLDR (keeping on version v35.1) into the new calendar-locale files. The locale data for the Gregorian calendar is held in a Roman calendar base, for sharing with other calendars. Add tests for basic uses of the new API. [ChangeLog][QtCore][QCalendar] Added QCalendar to support diverse calendars, supported by implementing QCalendarBackend. [ChangeLog][QtCore][QDate] Allow choice of calendar in various operations, with Gregorian remaining the default. Done-with: Lars Knoll <lars.knoll@qt.io> Done-with: Edward Welbourne <edward.welbourne@qt.io> Fixes: QTBUG-17110 Fixes: QTBUG-950 Change-Id: I9d6278f394269a183aee8156e990cec4d5198ab8 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Merge remote-tracking branch 'origin/5.13' into devLiang Qi2019-06-271-12/+15
| | | | | | | | | Conflicts: .qmake.conf src/network/ssl/qsslsocket_openssl.cpp Done-With: Timur Pocheptsov <timur.pocheptsov@qt.io> Change-Id: Ibb57a0548b4977797b400637487a56245ac1c024
* Separate out the time, zone, date code from corelib/tools/Edward Welbourne2019-06-061-0/+2047
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>