aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-10-12 01:00:20 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-10-12 01:00:20 +0200
commitd6cbf42e3720f0bdb1d6dc328ec8b8ac0ffb13ca (patch)
tree0326fbd4f1d54beba03399701e91c91b2c6195ae /src/qml
parent1d2cf00cecd537cc1dfdedda776897c0dc23e229 (diff)
parent8cb08ca42157bb43b523103a6d1be94534be0597 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/doc/src/javascript/imports.qdoc7
-rw-r--r--src/qml/jsruntime/qv4dateobject.cpp25
2 files changed, 25 insertions, 7 deletions
diff --git a/src/qml/doc/src/javascript/imports.qdoc b/src/qml/doc/src/javascript/imports.qdoc
index 974f2e154f..8e26c4aadd 100644
--- a/src/qml/doc/src/javascript/imports.qdoc
+++ b/src/qml/doc/src/javascript/imports.qdoc
@@ -144,14 +144,17 @@ A JavaScript resource may import a QML module in the following fashion:
.import TypeNamespace MajorVersion.MinorVersion as Qualifier
\endcode
-For example:
+Below you can see an example that also shows how to use the QML types from a
+module imported in javascript:
+
\code
.import Qt.test 1.0 as JsQtTest
+
+var importedEnumValue = JsQtTest.MyQmlObject.EnumValue3
\endcode
In particular, this may be useful in order to access functionality provided
via a singleton type; see qmlRegisterSingletonType() for more information.
\note The .import syntax doesn't work for scripts used in the \l {WorkerScript}
-
*/
diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp
index 520b715189..cc89947cec 100644
--- a/src/qml/jsruntime/qv4dateobject.cpp
+++ b/src/qml/jsruntime/qv4dateobject.cpp
@@ -294,13 +294,28 @@ static double MakeDay(double year, double month, double day)
if (month < 0)
month += 12.0;
- double d = DayFromYear(year);
- bool leap = InLeapYear(d*msPerDay);
+ /* Quoting the spec:
- d += DayFromMonth(month, leap);
- d += day - 1;
+ Find a value t such that YearFromTime(t) is ym and MonthFromTime(t) is mn
+ and DateFromTime(t) is 1; but if this is not possible (because some
+ argument is out of range), return NaN.
+ */
+ double first = DayFromYear(year);
+ /* Beware floating-point glitches: don't test the first millisecond of a
+ * year, month or day when we could test a moment firmly in the interior of
+ * the interval. A rounding glitch might give the first millisecond to the
+ * preceding interval.
+ */
+ bool leap = InLeapYear((first + 60) * msPerDay);
- return d;
+ first += DayFromMonth(month, leap);
+ const double t = first * msPerDay + msPerDay / 2; // Noon on the first of the month
+ Q_ASSERT(Day(t) == first);
+ if (YearFromTime(t) != year || MonthFromTime(t) != month || DateFromTime(t) != 1) {
+ qWarning("Apparently out-of-range date %.0f-%02.0f-%02.0f", year, month, day);
+ return qt_qnan();
+ }
+ return first + day - 1;
}
static inline double MakeDate(double day, double time)