summaryrefslogtreecommitdiff
path: root/src/qml/jsruntime/qv4dateobject.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QML: Add more overloads to Qt.format{Date|Time|DateTime}()Ulf Hermann2023-01-171-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Since JavaScript has no concept of time or date separate from the Date object that contains both, and since we implicitly (via QVariant::convert) or explicitly accept string arguments to all these methods, we should really accept string coercions of Date objects. We should also make all the string overloads explicit. Converting strings to QDateTime is a really obscure feature of the metatype system. We should not rely on it. Furthermore, we need to accept QDateTime, as the native representation of the JavaScript Date object, as argument to formatDate() and formatTime(). Otherwise there are two ambiguous paths to calling formatTime() or formatDate() using a Date object: Either coerce the Date into a string and call the string overload or coerce it into a QTime or QDate and call the QTime or QDate overload. The QML engine special cases this and prefers the QTime/QDate way, but this just needlessly complicates the overload resolution. Interestingly, tst_qqmlqt already tests most of those variants. We just have to add the JS string coercions. Task-number: QTBUG-109380 Change-Id: I880e622256fe115dade32bde880605df2031ff2f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* V4: Unify type conversions for date and time valuesUlf Hermann2023-01-171-0/+5
| | | | | | | | | | We should always use the same conversion to string and we shouldn't duplicate the code for the date conversion. Task-number: QTBUG-109380 Change-Id: I1b1959c8e9b5957ddcf287d252b8143511237565 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QJSEngine: Add efficient conversions for QDateTime and friendsUlf Hermann2023-01-171-0/+25
| | | | | | | | | The JavaScript date and time conversions are different from Qt's. Add them to coerceValue. Task-number: QTBUG-109380 Change-Id: Ic0d7dd8ff51fb8e29d80d9084d4415becaa76259 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Fix write back of Date valuesUlf Hermann2023-01-171-28/+82
| | | | | | | | | | A JavaScript Date object can be backed by QDate, QTime or QDateTime. Allow those to be written back. Pick-to: 6.5 Fixes: QTBUG-28981 Change-Id: Ic46b5c4daf75453f03e99470933cf179820e63ef Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* Route Qt::TimeSpec usage via QTimeZoneEdward Welbourne2022-12-111-12/+13
| | | | | | | | QTimeZone now packages Qt::TimeSpec details, unifying QDateTime APIs. Task-number: QTBUG-108199 Change-Id: I4a6bfaa213ec6db2fb357d20c7cd59e8c58ad103 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Port from container::count() and length() to size()Marc Mutz2022-10-071-1/+1
| | | | | | | | | | | | | | | | | | | | This is a semantic patch using ClangTidyTransformator as in qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8: auto QtContainerClass = anyOf( expr(hasType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))))).bind(o), expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)); makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container', with the extended set of container classes recognized. Change-Id: Idb1f75dfe2323bd1d9e8b4d58d54f1b4b80c7ed7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Remove unused includes in qml, first partSemih Yavuz2022-09-141-4/+0
| | | | | | | | | | | | | | | Drop unnecessary includes detected by clangd-iwyu. Add new includes due to the transitive includes. Also, some of the includes were detected as unused even if they were actually in use. In those cases, use angular brackets instead of "" which deceives the tool not to complain. Affected subfolders: Debugger, Compiler, JsApi, JsRuntime, Memory, Parser Task-number: QTBUG-106473 Change-Id: I01d996a2a2ba31cbbc5f60f5454c8f850298f528 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use SPDX license identifiersLucie Gérard2022-06-111-38/+2
| | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Pick-to: 6.4 Task-number: QTBUG-67283 Change-Id: I63563bbeb6f60f89d2c99660400dca7fab78a294 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Use qtbase's new (private) QLocalTime for Date's UTC offsetsEdward Welbourne2022-06-101-133/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | This puts all use of system time_t functions in one place, instead of spreading it out. Its implementation improves on what was formerly done in V4 Date's offset calculations, while simplifying them and eliminating most of the #if-ery. Add four more test-cases to tst_qqmlqt::dateTimeConversion(), based on issues seen on MinGW, getting the time-zone wrong due to the failure of localtime_r(); MinGW can use localtime_s, as QLocalTime now does. Revised tst_qqmllocale::timeZoneUpdated()'s conditions. The QEXPECT_FAIL()s have stopped triggering, at least on Darwin, and the issue isn't that Date.timeZoneUpdated() wasn't working, it's that (now only on Android and Windows) we don't have a way to set the system time-zone referenced by the system functions that QLocalTime calls to get time-zone offsets. Setting the TZ environment variable only works on faithful POSIX implementations. Pick-to: 6.4 Fixes: QTBUG-85149 Fixes: QTBUG-95993 Fixes: QTBUG-102971 Change-Id: I7bc983b9fd7167e3bab3db41dbc1c6f4a78665b9 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Simplify ToDateTime() and fix a typo in its docEdward Welbourne2022-05-021-2/+2
| | | | | | | | | | | The QDateTime::fromMSecsSinceEpoch(t, Qt::UTC).toTimeSpec(spec) call is in fact equivalent to QDateTime::fromMSecsSinceEpoch(t, spec), I just got confused when I last changed it ! The \tt in the doc comment should simply have been \a t. Change-Id: I460e4105bfa981fd5e44fb57d447fb035f0a4781 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* V4 Date: Support another nonstandard date format QDateTime has droppedUlf Hermann2022-02-031-0/+2
| | | | | | | | | | | Amends commit 43eaa77e8ed03153335c0002dcc8b660c39a0beb. Fixes: QTBUG-100377 Pick-to: 6.2 6.3 Change-Id: I01028bd991b8a64bd9dcad31ce90536d83dad0a1 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Replace all includes of windows.h with qt_windows.hUlf Hermann2021-10-251-1/+1
| | | | | | | We don't want min and max to be macros. Change-Id: Ifa79eaecf00c9f8b9c61494aa9d883eebfdabc65 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use QDateTime to get offsets for emscripten (wasm)Edward Welbourne2021-08-101-0/+38
| | | | | | | | | | | | | | | | | | | | | Since our wasm implementation doesn't have access to time-zone data by default, but its QDateTime implementation does manage to get offsets right for local time, use it as fall-back for V4's Date implementation's DaylightSavingTA() and getLocalTZA(). This implementation might also be viable for other cases without timezone support (and a way to reset it when the system zone has changed), but we'll need to experiment to find out. For now, since we have nothing better for wasm, use it there. In passing, update a comment about a bug report against the ECMA spec to say it's been fixed (and we're compatible with the result). Fixes: QTBUG-95314 Pick-to: 6.2 5.15 Change-Id: I40c1537815ada950dc0b5cebd4d641f7bfc45bd9 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* Rename a parameter to avoid shadowing a memberEdward Welbourne2021-05-181-3/+3
| | | | | Change-Id: I189e6fd49e5c5dec8240d2b36043240d1c059f81 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Use QDate::startOfDay() rather than QDateTime(,QTime(0, 0),)Edward Welbourne2020-11-121-3/+2
| | | | | | | | Makes no difference in this case, as it's UTC, but is terser and perhaps slightly clearer. Change-Id: I7de315def2f45ec4a12d2a682e5d1d7a4d0a3e6d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Make date parsing more lenientFabian Kosmale2020-10-291-0/+2
| | | | | | | | | | | This fixes a regression from Qt 5 to Qt 6, because QDateTime is now apparently more strict in its parsing of RFC2822Date. The string in the test-case is not valid according to that spec, but JS engines like V8 still accept it, and so did we in Qt 5. Fixes: QTBUG-87610 Change-Id: I2c6eb2087e4845b04fa0dc4f7aa9a229b3428a43 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* V4 Date: pass QDate, QTime by value, not by const referenceEdward Welbourne2020-09-011-1/+1
| | | | | | | They're value types, packaging qint64 and int respectively. Change-Id: I78a0097f77238751ac3ef9f928537f719a6d05d6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qv4dateobject.cpp: USE_QTZ_SYSTEM_TIMEZONE on more platformsUlf Hermann2020-06-251-2/+19
| | | | | | | | | | | | | The only platform where we may have a semi-adequate native implementation of the time/date functions is windows. On all other platforms we should use QTimeZone::systemTimeZone() if possible as that at least gives us correct results when the system time zone doesn't change at runtime. Fixes: QTBUG-84474 Pick-to: 5.15 Change-Id: I34b01e12a751ee1c9b17735810e62e2e847f8446 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QtQml: Use unicode character literalsUlf Hermann2020-06-031-10/+10
| | | | | | | This avoids the warnings on conversion to QChar. Change-Id: Ib774f24592d6f09a531c60bb6fa6e5bdbec88120 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Reduce Qt Declarative's use of QDateTime's locale-dependent APIsFabian Kosmale2020-01-301-3/+3
| | | | | | | | | | | [ChangeLog][QtQml] Qt.formatDateTime, Qt.formatDate and Qt.formatTime now support formatting according to a locale and an optional locale format type. If locale dependent formatting is desired, this method should be used instead of the locale-related DateFormat enum members. Fixes: QTBUG-81631 Change-Id: I971231644ebbeaccbf54dd8f036adf4d31547301 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* V4: Check for exceptions before we use the result of a JS callUlf Hermann2020-01-231-1/+1
| | | | | | | | If the call resulted in an exception the return value is undefined. Task-number: QTBUG-81581 Change-Id: Ibfdd5e1229cf5437f270232d3b1a91308adeec72 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Merge remote-tracking branch 'origin/5.13' into 5.14Liang Qi2019-10-101-5/+20
|\ | | | | | | | | | | | | | | Conflicts: src/plugins/scenegraph/openvg/qsgopenvgcontext.cpp tests/auto/quick/qquickpathview/tst_qquickpathview.cpp Change-Id: I117c8d62b21800329d1035021d312d9924f83a1b
| * Be more fussy about the MakeDay() calculationEdward Welbourne2019-10-081-5/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The ES Date spec goes into minute detail about doing various algorithms in the dumbest possible way (like InLeapYear() calling DaysInYear(), rather than the other way round) but, in MakeDay(), leaves the implementation to solve the problem of finding the start of the first day of a specified month in a given year. So exercise the freedom we have in that to be a little more robust; and actually check we have met the conditions the spec requires, returning NaN (as specified) if not. Added tests for some denormal dates and date-times and for a date mentioned in QTBUG-78996. Task-number: QTBUG-78996 Change-Id: I8d9a841dd1f1d9995273a3de8f6f9130207c7c2b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* | Convert a few sizeof(array)/sizeof(element0) fors to range forsAlbert Astals Cid2019-10-041-2/+1
| | | | | | | | | | | | | | | | Increases readability Change-Id: I46d82fac83e538988cea79a053d70b954a3cb9f1 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Convert QTime to V4 Date on a date with no DST in forceEdward Welbourne2019-09-271-7/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Sadly the third centennary of Cassini's birth isn't such a good date after all, since round-tripping will ignore DST on the QDateTime leg but include it in V4's implementation of ES's ill-conceived spec for handling DST and time-zone transitions; and June 8th is in summer for much of the world. So use a date which (as far as I can tell) appears to have been DST-free everywhere; and after the start of 1970 so that, even if we find ourselves working with a zone in which it did have DST, we'll apply DST consistently during round-tripping. Fixes: QTBUG-78706 Change-Id: I25be2548e2c97eae2c4f6c5bbe661dea2f35aaba Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | Fix tst_qqmllocale::timeZoneUpdated() test on AndroidJan Arve Sæther2019-07-181-1/+1
| | | | | | | | | | | | | | | | | | Switching to the POSIX implementation of DaylightSavingTA() fixes it Fixes: QTBUG-77052 Task-number: QTBUG-73512 Change-Id: I24804f193ac6f85eb6764f656d351cdc272c7987 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* | Remove some unneeded includesUlf Hermann2019-07-081-2/+0
|/ | | | | | Change-Id: Id05059dfc9910dad206e511b08f18487e241e508 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Merge remote-tracking branch 'origin/5.12' into devQt Forward Merge Bot2018-11-241-6/+12
|\ | | | | | | Change-Id: I57e4b762dcccf2f7f6e4b659f6fc8c40465d3322
| * Ensure our builtin constructors are subclassableLars Knoll2018-11-221-6/+12
| | | | | | | | | | | | | | | | | | Respect the newTarget passed into those constructors and make sure we set up the proto chain correctly. Change-Id: I3d12c7dbef4b33660a6715d73e9fb0f89105167a Fixes: QTBUG-71138 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
* | Stop using deprecated Qt:LocaleDateEdward Welbourne2018-09-211-3/+3
|/ | | | | | | | | | The Q(Date|Time)+::toString() methods to which it was passed all, at present, treat it the same as DefaultLocaleShortDate, so replace it with that. It's possible we should use the long format instead, but that would be a behavior change. Change-Id: I238ecd0bf0782f0c930ffee8bce23e2881922fed Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Cleanups in Value/PrimitiveLars Knoll2018-09-171-13/+13
| | | | | | | | | | | | Get rid of Primitive and move the corresponding methods directly into Value. Mark many methods in Value as constexpr and turn Value into a POD type again. Keep Primitive as a pure alias to Value for source compatibility of other modules that might be using it. Change-Id: Icb47458947dd3482c8852e95782123ea4346f5ec Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix Date.Utc()Lars Knoll2018-09-071-16/+43
| | | | | Change-Id: Iefba82adbf8f7b944079d165054e9dfe4461ac77 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix toLocaleString implementations in (Typed)Array.prototypeLars Knoll2018-08-231-1/+1
| | | | | Change-Id: Idcabd68b1651ad3cae315a16cb0e1361cba21253 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix handling of out-of-range year in Date's toISOString()Edward Welbourne2018-07-031-1/+1
| | | | | | | | | | ECMAScript 2015 clarified the handling of out-of-range years, requiring that an exception be raised: http://www.ecma-international.org/ecma-262/7.0/index.html#sec-corrections-and-clarifications-in-ecmascript-2015-with-possible-compatibility-impact http://www.ecma-international.org/ecma-262/7.0/index.html#sec-date.prototype.toisostring Change-Id: I91d76703705f3919d2ee77557e36af362db1adf9 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Apply TimeClip() in a few places it was missingEdward Welbourne2018-07-031-3/+3
| | | | | | | | | When parsing or converting from a QDateTime, we didn't always check that the resulting Date object was within range (1e8 days either side of the start of 1970). Change-Id: I1bee69f9070829f68998d576c19907a827fabc39 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Implement support for new.targetLars Knoll2018-07-031-1/+1
| | | | | | | | | Support the new.target meta property in the codegen, and add support for passing the newtarget into the constructor vtable methods and the execution context. Change-Id: I62ea58e5e92d894035a76e35776203e9837c383b Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Prefix vtable methods with virtualLars Knoll2018-07-031-2/+2
| | | | | | | | | Turns out that the overloading of vtable methods and regular ones is problematic in some cases. So let's rather make it explicit which methods are part of the vtable, and which aren't. Change-Id: Ifee32a26104d30f3c82bca8b5a9cdea2d4f4f526 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Clean up the property key API in StringOrSymbolLars Knoll2018-07-021-3/+3
| | | | | | | | | | | | | | Get rid of makeIdentifier(), as toPropertyKey() will take care of it. Rename identifier() to propertyKey() and check that the key is valid. Remove String/StringOrSymbol::asArrayIndex(), we don't need it anymore. Change-Id: I3c490fabc1475c9ea288b49b1638b6fa1bc237b7 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Replace Identifier by PropertyKeyLars Knoll2018-07-021-1/+1
| | | | | | | | Change all uses of Identifier to use the new PropertyKey class and get rid of Identifier. Change-Id: Ib7e83b06a3c923235e145b6e083fe980dc240452 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Implement toPrimitive() the way the ES7 spec wants itLars Knoll2018-05-281-0/+18
| | | | | | | | Add Dat.prototype[Symbol.toPrimitive] and make use of those methods in the toPrimitive implementation. Change-Id: I82a9a94dcae6822100de364373b3f4de1e3d749b Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
* Merge remote-tracking branch 'origin/5.11' into devLiang Qi2018-05-111-1/+1
|\ | | | | | | | | | | | | | | | | Conflicts: src/qml/compiler/qv4compilerscanfunctions.cpp tools/tools.pro Done-with: Lars Knoll <lars.knoll@qt.io> Change-Id: Ia77ee6ede6fc9760ce5a03d68079579a63e5a02f
| * Fix build without features.timezoneTasuku Suzuki2018-05-111-1/+1
| | | | | | | | | | | | Change-Id: Id40b7a9394a9027551a1334e9e520630e8967cb7 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
* | Cleanup creation code for builtin functionsLars Knoll2018-05-021-3/+1
| | | | | | | | | | | | | | | | Centralize the code in FunctionObject::createBuiltinFunction and setup function names and length properties there. Change-Id: I21f1d42b475070ee091d96d97387149af1dc47f2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Remove static localTZA variableLars Knoll2018-05-021-52/+51
|/ | | | | | | | | This one leads to lots of complaints from thread sanitizers as we're writing to it from multiple threads. Move it into the engine to avoid the noise. Change-Id: I081eeb1de80e623c68fcbd17df1875943c6c019c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Get rid of BuiltinFunctionLars Knoll2018-01-151-1/+1
| | | | | | | It's now unused. Change-Id: Id2941c212d488c9b0933fa06aac9922b9db13a05 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Raise minimum supported MSVC version to 2015Friedemann Kleint2018-01-061-1/+1
| | | | | | | | | | | | Remove code for older versions and streamline #ifdefs. Remove the helpers macros Q_STATIC_ASSERT_FOR_SANE_COMPILERS and V4_ASSERT_IS_TRIVIAL. Task-number: QTBUG-40658 Task-number: QTBUG-51673 Change-Id: Ifa4fab653b10ce7858739adef08364cddc6507cf Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Merge remote-tracking branch 'origin/wip/new-backend' into devSimon Hausmann2017-11-211-263/+333
|\ | | | | | | | | | | | | | | | | | | | | Conflicts: src/qml/compiler/qv4isel_moth.cpp src/qml/compiler/qv4jsir_p.h src/qml/jsruntime/qv4engine_p.h src/qml/jsruntime/qv4vme_moth.cpp tests/auto/qml/qml.pro Change-Id: Ia7b6ec24c7fcbcbb1786d9e798d2df294020ae37
| * Convert Date methods to new calling conventionLars Knoll2017-11-131-150/+145
| | | | | | | | | | Change-Id: I5b80eb9d9f18b113a04461fc8b5217a3695269a4 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
| * Change signature for call/callAsConstructorLars Knoll2017-11-071-12/+12
| | | | | | | | | | Change-Id: I159b57acc7a2133ef1ad545aa84e792c63449a57 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
| * Rename the construct 'virtual' method to callAsConstructorLars Knoll2017-11-071-1/+1
| | | | | | | | | | | | | | To make it consistent with the rest of the engine. Change-Id: I57b98fa26134f9864c663f47371ef3e9ca16ac9c Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>