aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-05-12 11:05:16 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2021-05-18 16:24:13 +0200
commit0a673d257a02b34450d4bbeb43346d993cf3a109 (patch)
tree9f1fc54b6a3a86033d80fec897487546a555e180 /tests
parent6f1ed8b46abed1a2190c12f8d7b272b075efa0e8 (diff)
Make QDate handling consistent in its use of UTC
Due to the quirk of ECMAScript's Date.parse() spec [0] stipulating the use of UTC for date-only strings, in contrast to most other ways of creating a Date using local time, reasonable users get surprised by the behavior of QDate properties initialized from strings. This can't be avoided without breaking other uses of Date, so document the work-around needed to cope with it (use UTC-specific methods to access the Date object). [0] https://tc39.es/ecma262/#sec-date.parse Make conversions back to QDate from Date work round the possibility that the Date, seen as a QDateTime(,, LocalTime), needs to be handled as UTC when extracting the date, and catch two more places that conversion from QDate neglected to use UTC's start of day, for consistency. Revised tests to call UTC-specific methods instead of the local-time ones, where appropriate. Drive-by: some tests were (entirely bogusly) constructing a fresh Date using the UTC-fields of the Date they had, in order to then test the non-UTC fields of this fresh Date; instead, simply test that the UTC fields are as expected. [ChangeLog][QML][Behavior change] Where a QDate is represented in QML's JavaScript as a Date, it is now more consistently associated with the start of the UTC day it describes. Previously cases where it was represented as the start of local time's day could lead to a Date turning into a QDate for the preceding day. Inconsistencies in the specified behavior of Date preclude eliminating such problems entirely, but they should now be limited to cases where (perversely for a date property or parameter) the date is specified with a local time late enough to make it coincide with the start of the next UTC day (in which case that next day's QDate will be its C++ representation). Fixes: QTBUG-92466 Change-Id: I2306dd9ecef0d5c2d59b562762392e51bb6d66ca Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignDate.1.qml12
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignDate.2.qml4
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignDate.3.qml12
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignDate.4.qml4
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignDate.5.qml12
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignDate.6.qml12
-rw-r--r--tests/auto/qml/qqmlecmascript/data/assignDate.qml6
-rw-r--r--tests/auto/qml/qqmlecmascript/data/checkDate-October.qml6
-rw-r--r--tests/auto/qml/qqmlecmascript/data/checkDate-denormal-Feb.qml8
-rw-r--r--tests/auto/qml/qqmlecmascript/data/checkDate-denormal-March.qml8
-rw-r--r--tests/auto/qml/qqmlecmascript/data/checkDate-denormal-leap.qml8
-rw-r--r--tests/auto/qml/qqmlecmascript/data/checkDate-denormal-wrap.qml8
-rw-r--r--tests/auto/qml/qqmlecmascript/data/checkDate-denormal-year.qml8
-rw-r--r--tests/auto/qml/qqmlecmascript/data/exportDate.2.qml6
-rw-r--r--tests/auto/qml/qqmlecmascript/data/exportDate.3.qml34
-rw-r--r--tests/auto/qml/qqmlecmascript/data/exportDate.4.qml34
-rw-r--r--tests/auto/qml/qqmlecmascript/data/exportDate.5.qml35
-rw-r--r--tests/auto/qml/qqmlecmascript/data/exportDate.6.qml35
-rw-r--r--tests/auto/qml/qqmlecmascript/data/exportDate.7.qml35
-rw-r--r--tests/auto/qml/qqmlecmascript/data/exportDate.8.qml35
-rw-r--r--tests/auto/qml/qqmlecmascript/data/exportDate.qml27
-rw-r--r--tests/auto/qml/qqmlecmascript/data/negativeyear.qml6
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp46
23 files changed, 167 insertions, 234 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/assignDate.1.qml b/tests/auto/qml/qqmlecmascript/data/assignDate.1.qml
index 8912d2a314..c48ed6d933 100644
--- a/tests/auto/qml/qqmlecmascript/data/assignDate.1.qml
+++ b/tests/auto/qml/qqmlecmascript/data/assignDate.1.qml
@@ -12,22 +12,22 @@ MyTypeObject {
dateTimeProperty2 = dateTimeVar2
boolProperty = (dateProperty.getTime() == dateVar.getTime()) &&
- (dateProperty.getFullYear() == 2009) &&
- (dateProperty.getMonth() == 5-1) &&
+ (dateProperty.getUTCFullYear() == 2009) &&
+ (dateProperty.getUTCMonth() == 5-1) &&
(dateProperty.getUTCDate() == 12) &&
(dateProperty.getUTCHours() == 0) &&
(dateProperty.getUTCMinutes() == 0) &&
(dateProperty.getUTCSeconds() == 0) &&
(dateTimeProperty.getTime() == dateTimeVar.getTime()) &&
- (dateTimeProperty.getFullYear() == 2009) &&
- (dateTimeProperty.getMonth() == 5-1) &&
+ (dateTimeProperty.getUTCFullYear() == 2009) &&
+ (dateTimeProperty.getUTCMonth() == 5-1) &&
(dateTimeProperty.getUTCDate() == 12) &&
(dateTimeProperty.getUTCHours() == 0) &&
(dateTimeProperty.getUTCMinutes() == 0) &&
(dateTimeProperty.getUTCSeconds() == 1) &&
(dateTimeProperty2.getTime() == dateTimeVar2.getTime()) &&
- (dateTimeProperty2.getFullYear() == 2009) &&
- (dateTimeProperty2.getMonth() == 5-1) &&
+ (dateTimeProperty2.getUTCFullYear() == 2009) &&
+ (dateTimeProperty2.getUTCMonth() == 5-1) &&
(dateTimeProperty2.getUTCDate() == 12) &&
(dateTimeProperty2.getUTCHours() == 23) &&
(dateTimeProperty2.getUTCMinutes() == 59) &&
diff --git a/tests/auto/qml/qqmlecmascript/data/assignDate.2.qml b/tests/auto/qml/qqmlecmascript/data/assignDate.2.qml
index f8c1f6eb8f..3b519eeb96 100644
--- a/tests/auto/qml/qqmlecmascript/data/assignDate.2.qml
+++ b/tests/auto/qml/qqmlecmascript/data/assignDate.2.qml
@@ -13,8 +13,8 @@ MyTypeObject {
var dateTimeVar2 = new Date("2009-05-12T23:59:59")
boolProperty = (dateProperty.getTime() == dateVar.getTime()) &&
- (dateProperty.getFullYear() == 2009) &&
- (dateProperty.getMonth() == 5-1) &&
+ (dateProperty.getUTCFullYear() == 2009) &&
+ (dateProperty.getUTCMonth() == 5-1) &&
(dateProperty.getUTCDate() == 12) &&
(dateProperty.getUTCHours() == 0) &&
(dateProperty.getUTCMinutes() == 0) &&
diff --git a/tests/auto/qml/qqmlecmascript/data/assignDate.3.qml b/tests/auto/qml/qqmlecmascript/data/assignDate.3.qml
index e960eef193..eef48091bb 100644
--- a/tests/auto/qml/qqmlecmascript/data/assignDate.3.qml
+++ b/tests/auto/qml/qqmlecmascript/data/assignDate.3.qml
@@ -13,22 +13,22 @@ MyTypeObject {
var dateTimeVar2 = new Date("2009-05-12T23:59:59Z")
boolProperty = (dateProperty.getTime() == dateVar.getTime()) &&
- (dateProperty.getFullYear() == 2009) &&
- (dateProperty.getMonth() == 5-1) &&
+ (dateProperty.getUTCFullYear() == 2009) &&
+ (dateProperty.getUTCMonth() == 5-1) &&
(dateProperty.getUTCDate() == 12) &&
(dateProperty.getUTCHours() == 0) &&
(dateProperty.getUTCMinutes() == 0) &&
(dateProperty.getUTCSeconds() == 0) &&
(dateTimeProperty.getTime() == dateTimeVar.getTime()) &&
- (dateTimeProperty.getFullYear() == 2009) &&
- (dateTimeProperty.getMonth() == 5-1) &&
+ (dateTimeProperty.getUTCFullYear() == 2009) &&
+ (dateTimeProperty.getUTCMonth() == 5-1) &&
(dateTimeProperty.getUTCDate() == 12) &&
(dateTimeProperty.getUTCHours() == 0) &&
(dateTimeProperty.getUTCMinutes() == 0) &&
(dateTimeProperty.getUTCSeconds() == 1) &&
(dateTimeProperty2.getTime() == dateTimeVar2.getTime()) &&
- (dateTimeProperty2.getFullYear() == 2009) &&
- (dateTimeProperty2.getMonth() == 5-1) &&
+ (dateTimeProperty2.getUTCFullYear() == 2009) &&
+ (dateTimeProperty2.getUTCMonth() == 5-1) &&
(dateTimeProperty2.getUTCDate() == 12) &&
(dateTimeProperty2.getUTCHours() == 23) &&
(dateTimeProperty2.getUTCMinutes() == 59) &&
diff --git a/tests/auto/qml/qqmlecmascript/data/assignDate.4.qml b/tests/auto/qml/qqmlecmascript/data/assignDate.4.qml
index 6dd29afbc9..d4d31b1902 100644
--- a/tests/auto/qml/qqmlecmascript/data/assignDate.4.qml
+++ b/tests/auto/qml/qqmlecmascript/data/assignDate.4.qml
@@ -13,8 +13,8 @@ MyTypeObject {
var dateTimeVar2 = new Date("2009-05-12T23:59:59Z")
boolProperty = (dateProperty.getTime() == dateVar.getTime()) &&
- (dateProperty.getFullYear() == 2009) &&
- (dateProperty.getMonth() == 5-1) &&
+ (dateProperty.getUTCFullYear() == 2009) &&
+ (dateProperty.getUTCMonth() == 5-1) &&
(dateProperty.getUTCDate() == 12) &&
(dateProperty.getUTCHours() == 0) &&
(dateProperty.getUTCMinutes() == 0) &&
diff --git a/tests/auto/qml/qqmlecmascript/data/assignDate.5.qml b/tests/auto/qml/qqmlecmascript/data/assignDate.5.qml
index cfadaafc54..bfb8e6bdc1 100644
--- a/tests/auto/qml/qqmlecmascript/data/assignDate.5.qml
+++ b/tests/auto/qml/qqmlecmascript/data/assignDate.5.qml
@@ -13,22 +13,22 @@ MyTypeObject {
var dateTimeVar2 = new Date("2009-05-12T23:59:59+02:00")
boolProperty = (dateProperty.getTime() == dateVar.getTime()) &&
- (dateProperty.getFullYear() == 2009) &&
- (dateProperty.getMonth() == 5-1) &&
+ (dateProperty.getUTCFullYear() == 2009) &&
+ (dateProperty.getUTCMonth() == 5-1) &&
(dateProperty.getUTCDate() == 12) &&
(dateProperty.getUTCHours() == 0) &&
(dateProperty.getUTCMinutes() == 0) &&
(dateProperty.getUTCSeconds() == 0) &&
(dateTimeProperty.getTime() == dateTimeVar.getTime()) &&
- (dateTimeProperty.getFullYear() == 2009) &&
- (dateTimeProperty.getMonth() == 5-1) &&
+ (dateTimeProperty.getUTCFullYear() == 2009) &&
+ (dateTimeProperty.getUTCMonth() == 5-1) &&
(dateTimeProperty.getUTCDate() == 11) &&
(dateTimeProperty.getUTCHours() == 22) &&
(dateTimeProperty.getUTCMinutes() == 0) &&
(dateTimeProperty.getUTCSeconds() == 1) &&
(dateTimeProperty2.getTime() == dateTimeVar2.getTime()) &&
- (dateTimeProperty2.getFullYear() == 2009) &&
- (dateTimeProperty2.getMonth() == 5-1) &&
+ (dateTimeProperty2.getUTCFullYear() == 2009) &&
+ (dateTimeProperty2.getUTCMonth() == 5-1) &&
(dateTimeProperty2.getUTCDate() == 12) &&
(dateTimeProperty2.getUTCHours() == 21) &&
(dateTimeProperty2.getUTCMinutes() == 59) &&
diff --git a/tests/auto/qml/qqmlecmascript/data/assignDate.6.qml b/tests/auto/qml/qqmlecmascript/data/assignDate.6.qml
index 97cd0d1e60..099bc070ea 100644
--- a/tests/auto/qml/qqmlecmascript/data/assignDate.6.qml
+++ b/tests/auto/qml/qqmlecmascript/data/assignDate.6.qml
@@ -13,22 +13,22 @@ MyTypeObject {
var dateTimeVar2 = new Date("2009-05-12T23:59:59+02:00")
boolProperty = (dateProperty.getTime() == dateVar.getTime()) &&
- (dateProperty.getFullYear() == 2009) &&
- (dateProperty.getMonth() == 5-1) &&
+ (dateProperty.getUTCFullYear() == 2009) &&
+ (dateProperty.getUTCMonth() == 5-1) &&
(dateProperty.getUTCDate() == 12) &&
(dateProperty.getUTCHours() == 0) &&
(dateProperty.getUTCMinutes() == 0) &&
(dateProperty.getUTCSeconds() == 0) &&
(dateTimeProperty.getTime() == dateTimeVar.getTime()) &&
- (dateTimeProperty.getFullYear() == 2009) &&
- (dateTimeProperty.getMonth() == 5-1) &&
+ (dateTimeProperty.getUTCFullYear() == 2009) &&
+ (dateTimeProperty.getUTCMonth() == 5-1) &&
(dateTimeProperty.getUTCDate() == 11) &&
(dateTimeProperty.getUTCHours() == 22) &&
(dateTimeProperty.getUTCMinutes() == 0) &&
(dateTimeProperty.getUTCSeconds() == 1) &&
(dateTimeProperty2.getTime() == dateTimeVar2.getTime()) &&
- (dateTimeProperty2.getFullYear() == 2009) &&
- (dateTimeProperty2.getMonth() == 5-1) &&
+ (dateTimeProperty2.getUTCFullYear() == 2009) &&
+ (dateTimeProperty2.getUTCMonth() == 5-1) &&
(dateTimeProperty2.getUTCDate() == 12) &&
(dateTimeProperty2.getUTCHours() == 21) &&
(dateTimeProperty2.getUTCMinutes() == 59) &&
diff --git a/tests/auto/qml/qqmlecmascript/data/assignDate.qml b/tests/auto/qml/qqmlecmascript/data/assignDate.qml
index 73677e99f1..60a3d72fa1 100644
--- a/tests/auto/qml/qqmlecmascript/data/assignDate.qml
+++ b/tests/auto/qml/qqmlecmascript/data/assignDate.qml
@@ -14,9 +14,9 @@ MyTypeObject {
dateTimeProperty2 = dateTimeVar2
boolProperty = (dateProperty.getTime() == dateVar.getTime()) &&
- (dateProperty.getFullYear() == 2009) &&
- (dateProperty.getMonth() == 5-1) &&
- (dateProperty.getDate() == 12) &&
+ (dateProperty.getUTCFullYear() == 2009) &&
+ (dateProperty.getUTCMonth() == 5-1) &&
+ (dateProperty.getUTCDate() == 12) &&
(dateProperty.getUTCHours() == 0) &&
(dateProperty.getUTCMinutes() == 0) &&
(dateProperty.getUTCSeconds() == 0) &&
diff --git a/tests/auto/qml/qqmlecmascript/data/checkDate-October.qml b/tests/auto/qml/qqmlecmascript/data/checkDate-October.qml
index 6686831e1c..da32a899db 100644
--- a/tests/auto/qml/qqmlecmascript/data/checkDate-October.qml
+++ b/tests/auto/qml/qqmlecmascript/data/checkDate-October.qml
@@ -5,8 +5,8 @@ MyTypeObject {
Component.onCompleted: {
// QTBUG-78996
dateProperty = new Date(2019, 9, 3)
- boolProperty = (dateProperty.getFullYear() == 2019
- && dateProperty.getMonth() == 9
- && dateProperty.getDate() == 3)
+ boolProperty = (dateProperty.getUTCFullYear() == 2019
+ && dateProperty.getUTCMonth() == 9
+ && dateProperty.getUTCDate() == 3);
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-Feb.qml b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-Feb.qml
index 29ec40ffbd..c3abfc6d91 100644
--- a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-Feb.qml
+++ b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-Feb.qml
@@ -3,9 +3,9 @@ import QtQuick 2.0
MyTypeObject {
Component.onCompleted: {
- dateProperty = new Date(2019, 2, 0) // Feb 28th
- boolProperty = (dateProperty.getFullYear() == 2019
- && dateProperty.getMonth() == 1
- && dateProperty.getDate() == 28)
+ dateProperty = new Date(2019, 2, 0); // Feb 28th
+ boolProperty = (dateProperty.getUTCFullYear() == 2019
+ && dateProperty.getUTCMonth() == 1
+ && dateProperty.getUTCDate() == 28);
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-March.qml b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-March.qml
index 7fc8bf43bd..6cd9e8798c 100644
--- a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-March.qml
+++ b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-March.qml
@@ -3,9 +3,9 @@ import QtQuick 2.0
MyTypeObject {
Component.onCompleted: {
- dateProperty = new Date(2019, 1, 29) // March 1st
- boolProperty = (dateProperty.getFullYear() == 2019
- && dateProperty.getMonth() == 2
- && dateProperty.getDate() == 1)
+ dateProperty = new Date(2019, 1, 29); // March 1st
+ boolProperty = (dateProperty.getUTCFullYear() == 2019
+ && dateProperty.getUTCMonth() == 2
+ && dateProperty.getUTCDate() == 1);
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-leap.qml b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-leap.qml
index 6dd84810e6..be622c0f90 100644
--- a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-leap.qml
+++ b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-leap.qml
@@ -3,9 +3,9 @@ import QtQuick 2.0
MyTypeObject {
Component.onCompleted: {
- dateProperty = new Date(2020, 2, 0) // Feb 29th
- boolProperty = (dateProperty.getFullYear() == 2020
- && dateProperty.getMonth() == 1
- && dateProperty.getDate() == 29)
+ dateProperty = new Date(2020, 2, 0); // Feb 29th
+ boolProperty = (dateProperty.getUTCFullYear() == 2020
+ && dateProperty.getUTCMonth() == 1
+ && dateProperty.getUTCDate() == 29);
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-wrap.qml b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-wrap.qml
index ddb79727ef..d92001c0cc 100644
--- a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-wrap.qml
+++ b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-wrap.qml
@@ -3,9 +3,9 @@ import QtQuick 2.0
MyTypeObject {
Component.onCompleted: {
- dateProperty = new Date(2017, 40, -61) // 2020, Feb 29th
- boolProperty = (dateProperty.getFullYear() == 2020
- && dateProperty.getMonth() == 1
- && dateProperty.getDate() == 29)
+ dateProperty = new Date(2017, 40, -61); // 2020, Feb 29th
+ boolProperty = (dateProperty.getUTCFullYear() == 2020
+ && dateProperty.getUTCMonth() == 1
+ && dateProperty.getUTCDate() == 29);
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-year.qml b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-year.qml
index 90514c39c8..1d99144009 100644
--- a/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-year.qml
+++ b/tests/auto/qml/qqmlecmascript/data/checkDate-denormal-year.qml
@@ -3,9 +3,9 @@ import QtQuick 2.0
MyTypeObject {
Component.onCompleted: {
- dateProperty = new Date(2019, 12, 0) // Dec 31
- boolProperty = (dateProperty.getFullYear() == 2019
- && dateProperty.getMonth() == 11
- && dateProperty.getDate() == 31)
+ dateProperty = new Date(2019, 12, 0); // Dec 31
+ boolProperty = (dateProperty.getUTCFullYear() == 2019
+ && dateProperty.getUTCMonth() == 11
+ && dateProperty.getUTCDate() == 31);
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/exportDate.2.qml b/tests/auto/qml/qqmlecmascript/data/exportDate.2.qml
index 4420cf846c..d74a2901c9 100644
--- a/tests/auto/qml/qqmlecmascript/data/exportDate.2.qml
+++ b/tests/auto/qml/qqmlecmascript/data/exportDate.2.qml
@@ -26,8 +26,8 @@ MyTypeObject {
(dtAdjusted.getHours() == 23) &&
(dtAdjusted.getMinutes() == 59) &&
(dtAdjusted.getSeconds() == 59) &&
- (date.getFullYear() == 2009) &&
- (date.getMonth() == 5-1) &&
- (date.getDate() == 12)
+ (date.getUTCFullYear() == 2009) &&
+ (date.getUTCMonth() == 5-1) &&
+ (date.getUTCDate() == 12);
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/exportDate.3.qml b/tests/auto/qml/qqmlecmascript/data/exportDate.3.qml
index 2ba1cc6607..dde958d6e3 100644
--- a/tests/auto/qml/qqmlecmascript/data/exportDate.3.qml
+++ b/tests/auto/qml/qqmlecmascript/data/exportDate.3.qml
@@ -12,28 +12,18 @@ MyTypeObject {
// The test date is 2009-5-12 00:00:01 (UTC)
var compare = new Date(Date.UTC(2009, 5-1, 12, 0, 0, 1))
- var compareOffset = 0
- // Adjust for timezone to extract correct partial values
- var dtAdjusted = new Date(dt.getUTCFullYear(),
- dt.getUTCMonth(),
- dt.getUTCDate(),
- dt.getUTCHours(),
- dt.getUTCMinutes(),
- dt.getUTCSeconds(),
- dt.getUTCMilliseconds())
-
- boolProperty = (dt.getTime() == compare.getTime()) &&
- (offset == compareOffset) &&
- (timespec == 'UTC') &&
- (dtAdjusted.getFullYear() == 2009) &&
- (dtAdjusted.getMonth() == 5-1) &&
- (dtAdjusted.getDate() == 12) &&
- (dtAdjusted.getHours() == 0) &&
- (dtAdjusted.getMinutes() == 0) &&
- (dtAdjusted.getSeconds() == 1) &&
- (date.getFullYear() == 2009) &&
- (date.getMonth() == 5-1) &&
- (date.getDate() == 12)
+ boolProperty = (dt.getTime() == compare.getTime() &&
+ offset == 0 &&
+ timespec == 'UTC' &&
+ dt.getUTCFullYear() == 2009 &&
+ dt.getUTCMonth() == 5-1 &&
+ dt.getUTCDate() == 12 &&
+ dt.getUTCHours() == 0 &&
+ dt.getUTCMinutes() == 0 &&
+ dt.getUTCSeconds() == 1 &&
+ date.getUTCFullYear() == 2009 &&
+ date.getUTCMonth() == 5-1 &&
+ date.getUTCDate() == 12);
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/exportDate.4.qml b/tests/auto/qml/qqmlecmascript/data/exportDate.4.qml
index c5b2388df2..3781b719bb 100644
--- a/tests/auto/qml/qqmlecmascript/data/exportDate.4.qml
+++ b/tests/auto/qml/qqmlecmascript/data/exportDate.4.qml
@@ -12,28 +12,18 @@ MyTypeObject {
// The test date is 2009-5-12 23:59:59 (UTC)
var compare = new Date(Date.UTC(2009, 5-1, 12, 23, 59, 59))
- var compareOffset = 0
- // Adjust for timezone to extract correct partial values
- var dtAdjusted = new Date(dt.getUTCFullYear(),
- dt.getUTCMonth(),
- dt.getUTCDate(),
- dt.getUTCHours(),
- dt.getUTCMinutes(),
- dt.getUTCSeconds(),
- dt.getUTCMilliseconds())
-
- boolProperty = (dt.getTime() == compare.getTime()) &&
- (offset == compareOffset) &&
- (timespec == 'UTC') &&
- (dtAdjusted.getFullYear() == 2009) &&
- (dtAdjusted.getMonth() == 5-1) &&
- (dtAdjusted.getDate() == 12) &&
- (dtAdjusted.getHours() == 23) &&
- (dtAdjusted.getMinutes() == 59) &&
- (dtAdjusted.getSeconds() == 59) &&
- (date.getFullYear() == 2009) &&
- (date.getMonth() == 5-1) &&
- (date.getDate() == 12)
+ boolProperty = (dt.getTime() == compare.getTime() &&
+ offset == 0 &&
+ timespec == 'UTC' &&
+ dt.getUTCFullYear() == 2009 &&
+ dt.getUTCMonth() == 5-1 &&
+ dt.getUTCDate() == 12 &&
+ dt.getUTCHours() == 23 &&
+ dt.getUTCMinutes() == 59 &&
+ dt.getUTCSeconds() == 59 &&
+ date.getUTCFullYear() == 2009 &&
+ date.getUTCMonth() == 5-1 &&
+ date.getUTCDate() == 12);
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/exportDate.5.qml b/tests/auto/qml/qqmlecmascript/data/exportDate.5.qml
index 6da3a4a8e0..faefb38956 100644
--- a/tests/auto/qml/qqmlecmascript/data/exportDate.5.qml
+++ b/tests/auto/qml/qqmlecmascript/data/exportDate.5.qml
@@ -12,28 +12,19 @@ MyTypeObject {
// The test date is 2009-5-12 00:00:01 (UTC+11:30)
var compare = new Date('2009-05-12T00:00:01+11:30')
+ // That's 2009-05-11 12:30:01 UTC
- // Adjust for timezone to extract correct partial values
- var dtUtc = new Date(dt.getTime() + (offset * 60000))
- var dtAdjusted = new Date(dtUtc.getUTCFullYear(),
- dtUtc.getUTCMonth(),
- dtUtc.getUTCDate(),
- dtUtc.getUTCHours(),
- dtUtc.getUTCMinutes(),
- dtUtc.getUTCSeconds(),
- dtUtc.getUTCMilliseconds())
-
- boolProperty = (dt.getTime() == compare.getTime()) &&
- (offset == ((11 * 60) + 30)) &&
- (timespec == '+11:30') &&
- (dtAdjusted.getFullYear() == 2009) &&
- (dtAdjusted.getMonth() == 5-1) &&
- (dtAdjusted.getDate() == 12) &&
- (dtAdjusted.getHours() == 0) &&
- (dtAdjusted.getMinutes() == 0) &&
- (dtAdjusted.getSeconds() == 1) &&
- (date.getFullYear() == 2009) &&
- (date.getMonth() == 5-1) &&
- (date.getDate() == 12)
+ boolProperty = (dt.getTime() == compare.getTime() &&
+ offset == 11 * 60 + 30 &&
+ timespec == '+11:30' &&
+ dt.getUTCFullYear() == 2009 &&
+ dt.getUTCMonth() == 5-1 &&
+ dt.getUTCDate() == 11 &&
+ dt.getUTCHours() == 12 &&
+ dt.getUTCMinutes() == 30 &&
+ dt.getUTCSeconds() == 1 &&
+ date.getUTCFullYear() == 2009 &&
+ date.getUTCMonth() == 5-1 &&
+ date.getUTCDate() == 12);
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/exportDate.6.qml b/tests/auto/qml/qqmlecmascript/data/exportDate.6.qml
index 9980af4afe..3117400b3a 100644
--- a/tests/auto/qml/qqmlecmascript/data/exportDate.6.qml
+++ b/tests/auto/qml/qqmlecmascript/data/exportDate.6.qml
@@ -12,28 +12,19 @@ MyTypeObject {
// The test date is 2009-5-12 23:59:59 (UTC+11:30)
var compare = new Date('2009-05-12T23:59:59+11:30')
+ // That's 2009-05-12 12:29:59 UTC
- // Adjust for timezone to extract correct partial values
- var dtUtc = new Date(dt.getTime() + (offset * 60000))
- var dtAdjusted = new Date(dtUtc.getUTCFullYear(),
- dtUtc.getUTCMonth(),
- dtUtc.getUTCDate(),
- dtUtc.getUTCHours(),
- dtUtc.getUTCMinutes(),
- dtUtc.getUTCSeconds(),
- dtUtc.getUTCMilliseconds())
-
- boolProperty = (dt.getTime() == compare.getTime()) &&
- (offset == ((11 * 60) + 30)) &&
- (timespec == '+11:30') &&
- (dtAdjusted.getFullYear() == 2009) &&
- (dtAdjusted.getMonth() == 5-1) &&
- (dtAdjusted.getDate() == 12) &&
- (dtAdjusted.getHours() == 23) &&
- (dtAdjusted.getMinutes() == 59) &&
- (dtAdjusted.getSeconds() == 59) &&
- (date.getFullYear() == 2009) &&
- (date.getMonth() == 5-1) &&
- (date.getDate() == 12)
+ boolProperty = (dt.getTime() == compare.getTime() &&
+ offset == 11 * 60 + 30 &&
+ timespec == '+11:30' &&
+ dt.getUTCFullYear() == 2009 &&
+ dt.getUTCMonth() == 5-1 &&
+ dt.getUTCDate() == 12 &&
+ dt.getUTCHours() == 12 &&
+ dt.getUTCMinutes() == 29 &&
+ dt.getUTCSeconds() == 59 &&
+ date.getUTCFullYear() == 2009 &&
+ date.getUTCMonth() == 5-1 &&
+ date.getUTCDate() == 12);
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/exportDate.7.qml b/tests/auto/qml/qqmlecmascript/data/exportDate.7.qml
index d1de970cc5..5612cbbe23 100644
--- a/tests/auto/qml/qqmlecmascript/data/exportDate.7.qml
+++ b/tests/auto/qml/qqmlecmascript/data/exportDate.7.qml
@@ -12,28 +12,19 @@ MyTypeObject {
// The test date is 2009-5-12 00:00:01 (UTC-11:30)
var compare = new Date('2009-05-12T00:00:01-11:30')
+ // That's 2009-05-12 11:30:01 UTC
- // Adjust for timezone to extract correct partial values
- var dtUtc = new Date(dt.getTime() + (offset * 60000))
- var dtAdjusted = new Date(dtUtc.getUTCFullYear(),
- dtUtc.getUTCMonth(),
- dtUtc.getUTCDate(),
- dtUtc.getUTCHours(),
- dtUtc.getUTCMinutes(),
- dtUtc.getUTCSeconds(),
- dtUtc.getUTCMilliseconds())
-
- boolProperty = (dt.getTime() == compare.getTime()) &&
- (offset == -((11 * 60) + 30)) &&
- (timespec == '-11:30') &&
- (dtAdjusted.getFullYear() == 2009) &&
- (dtAdjusted.getMonth() == 5-1) &&
- (dtAdjusted.getDate() == 12) &&
- (dtAdjusted.getHours() == 0) &&
- (dtAdjusted.getMinutes() == 0) &&
- (dtAdjusted.getSeconds() == 1) &&
- (date.getFullYear() == 2009) &&
- (date.getMonth() == 5-1) &&
- (date.getDate() == 12)
+ boolProperty = (dt.getTime() == compare.getTime() &&
+ offset == -(11 * 60 + 30) &&
+ timespec == '-11:30' &&
+ dt.getUTCFullYear() == 2009 &&
+ dt.getUTCMonth() == 5-1 &&
+ dt.getUTCDate() == 12 &&
+ dt.getUTCHours() == 11 &&
+ dt.getUTCMinutes() == 30 &&
+ dt.getUTCSeconds() == 1 &&
+ date.getUTCFullYear() == 2009 &&
+ date.getUTCMonth() == 5-1 &&
+ date.getUTCDate() == 12);
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/exportDate.8.qml b/tests/auto/qml/qqmlecmascript/data/exportDate.8.qml
index 6459ca8bcd..8bb3b0ae1d 100644
--- a/tests/auto/qml/qqmlecmascript/data/exportDate.8.qml
+++ b/tests/auto/qml/qqmlecmascript/data/exportDate.8.qml
@@ -12,28 +12,19 @@ MyTypeObject {
// The test date is 2009-5-12 23:59:59 (UTC-11:30)
var compare = new Date('2009-05-12T23:59:59-11:30')
+ // That's 2009-05-13 11:29:59 UTC
- // Adjust for timezone to extract correct partial values
- var dtUtc = new Date(dt.getTime() + (offset * 60000))
- var dtAdjusted = new Date(dtUtc.getUTCFullYear(),
- dtUtc.getUTCMonth(),
- dtUtc.getUTCDate(),
- dtUtc.getUTCHours(),
- dtUtc.getUTCMinutes(),
- dtUtc.getUTCSeconds(),
- dtUtc.getUTCMilliseconds())
-
- boolProperty = (dt.getTime() == compare.getTime()) &&
- (offset == -((11 * 60) + 30)) &&
- (timespec == '-11:30') &&
- (dtAdjusted.getFullYear() == 2009) &&
- (dtAdjusted.getMonth() == 5-1) &&
- (dtAdjusted.getDate() == 12) &&
- (dtAdjusted.getHours() == 23) &&
- (dtAdjusted.getMinutes() == 59) &&
- (dtAdjusted.getSeconds() == 59) &&
- (date.getFullYear() == 2009) &&
- (date.getMonth() == 5-1) &&
- (date.getDate() == 12)
+ boolProperty = (dt.getTime() == compare.getTime() &&
+ offset == -(11 * 60 + 30) &&
+ timespec == '-11:30' &&
+ dt.getUTCFullYear() == 2009 &&
+ dt.getUTCMonth() == 5-1 &&
+ dt.getUTCDate() == 13 &&
+ dt.getUTCHours() == 11 &&
+ dt.getUTCMinutes() == 29 &&
+ dt.getUTCSeconds() == 59 &&
+ date.getUTCFullYear() == 2009 &&
+ date.getUTCMonth() == 5-1 &&
+ date.getUTCDate() == 12);
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/exportDate.qml b/tests/auto/qml/qqmlecmascript/data/exportDate.qml
index c42b092fc7..225422b5e3 100644
--- a/tests/auto/qml/qqmlecmascript/data/exportDate.qml
+++ b/tests/auto/qml/qqmlecmascript/data/exportDate.qml
@@ -14,20 +14,17 @@ MyTypeObject {
var compare = new Date(2009, 5-1, 12, 0, 0, 1)
var compareOffset = compare.getTimezoneOffset()
- // The date is already in local time, so we can use the partial values directly
- var dtAdjusted = dt
-
- boolProperty = (dt.getTime() == compare.getTime()) &&
- (offset == compareOffset) &&
- (timespec == 'LocalTime') &&
- (dtAdjusted.getFullYear() == 2009) &&
- (dtAdjusted.getMonth() == 5-1) &&
- (dtAdjusted.getDate() == 12) &&
- (dtAdjusted.getHours() == 0) &&
- (dtAdjusted.getMinutes() == 0) &&
- (dtAdjusted.getSeconds() == 1) &&
- (date.getFullYear() == 2009) &&
- (date.getMonth() == 5-1) &&
- (date.getDate() == 12)
+ boolProperty = (dt.getTime() == compare.getTime() &&
+ offset == compareOffset &&
+ timespec == 'LocalTime' &&
+ dt.getFullYear() == 2009 &&
+ dt.getMonth() == 5-1 &&
+ dt.getDate() == 12 &&
+ dt.getHours() == 0 &&
+ dt.getMinutes() == 0 &&
+ dt.getSeconds() == 1 &&
+ date.getUTCFullYear() == 2009 &&
+ date.getUTCMonth() == 5-1 &&
+ date.getUTCDate() == 12);
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/negativeyear.qml b/tests/auto/qml/qqmlecmascript/data/negativeyear.qml
index e6c857d266..7c6b307b45 100644
--- a/tests/auto/qml/qqmlecmascript/data/negativeyear.qml
+++ b/tests/auto/qml/qqmlecmascript/data/negativeyear.qml
@@ -2,12 +2,12 @@ import QtQuick 2.0
import Qt.test 1.0
Item {
+ // Use the second of January, to avoid any time-zone glitch pulling to previous year !
function check_negative_tostring() {
- return "result: " + new Date(-2000, 0, 1);
+ return "result: " + new Date(-2000, 0, 2);
}
function check_negative_toisostring() {
- // Make that february, to avoid timezone problems
- return "result: " + (new Date(-2000, 1, 1)).toISOString();
+ return "result: " + (new Date(-2000, 0, 2)).toISOString();
}
}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index cb14333e6d..7b85e5af36 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -605,32 +605,24 @@ void tst_qqmlecmascript::exportDate_data()
const QDate date(2009, 5, 12);
const QTime early(0, 0, 1);
const QTime late(23, 59, 59);
- const int offset(((11 * 60) + 30) * 60);
-
- QTest::newRow("Localtime early") << testFileUrl("exportDate.qml") << QDateTime(date, early, Qt::LocalTime);
- QTest::newRow("Localtime late") << testFileUrl("exportDate.2.qml") << QDateTime(date, late, Qt::LocalTime);
- QTest::newRow("UTC early") << testFileUrl("exportDate.3.qml") << QDateTime(date, early, Qt::UTC);
- QTest::newRow("UTC late") << testFileUrl("exportDate.4.qml") << QDateTime(date, late, Qt::UTC);
- {
- QDateTime dt(date, early, Qt::OffsetFromUTC);
- dt.setOffsetFromUtc(offset);
- QTest::newRow("+11:30 early") << testFileUrl("exportDate.5.qml") << dt;
- }
- {
- QDateTime dt(date, late, Qt::OffsetFromUTC);
- dt.setOffsetFromUtc(offset);
- QTest::newRow("+11:30 late") << testFileUrl("exportDate.6.qml") << dt;
- }
- {
- QDateTime dt(date, early, Qt::OffsetFromUTC);
- dt.setOffsetFromUtc(-offset);
- QTest::newRow("-11:30 early") << testFileUrl("exportDate.7.qml") << dt;
- }
- {
- QDateTime dt(date, late, Qt::OffsetFromUTC);
- dt.setOffsetFromUtc(-offset);
- QTest::newRow("-11:30 late") << testFileUrl("exportDate.8.qml") << dt;
- }
+ const int offset = (11 * 60 + 30) * 60;
+
+ QTest::newRow("Local time early")
+ << testFileUrl("exportDate.qml") << QDateTime(date, early, Qt::LocalTime);
+ QTest::newRow("Local time late")
+ << testFileUrl("exportDate.2.qml") << QDateTime(date, late, Qt::LocalTime);
+ QTest::newRow("UTC early")
+ << testFileUrl("exportDate.3.qml") << QDateTime(date, early, Qt::UTC);
+ QTest::newRow("UTC late")
+ << testFileUrl("exportDate.4.qml") << QDateTime(date, late, Qt::UTC);
+ QTest::newRow("+11:30 early")
+ << testFileUrl("exportDate.5.qml") << QDateTime(date, early, Qt::OffsetFromUTC, offset);
+ QTest::newRow("+11:30 late")
+ << testFileUrl("exportDate.6.qml") << QDateTime(date, late, Qt::OffsetFromUTC, offset);
+ QTest::newRow("-11:30 early")
+ << testFileUrl("exportDate.7.qml") << QDateTime(date, early, Qt::OffsetFromUTC, -offset);
+ QTest::newRow("-11:30 late")
+ << testFileUrl("exportDate.8.qml") << QDateTime(date, late, Qt::OffsetFromUTC, -offset);
}
void tst_qqmlecmascript::exportDate()
@@ -7984,7 +7976,7 @@ void tst_qqmlecmascript::negativeYear()
// Only check for the year. We hope that every language writes the year in arabic numerals and
// in relation to a specific dude's date of birth. We also hope that no language adds a "-2001"
// junk string somewhere in the middle.
- QVERIFY(q.toString().indexOf(QStringLiteral("-2001")) != -1);
+ QVERIFY2(q.toString().indexOf(QStringLiteral("-2001")) != -1, qPrintable(q.toString()));
QMetaObject::invokeMethod(object.get(), "check_negative_toisostring", Q_RETURN_ARG(QVariant, q));
QCOMPARE(q.toString().left(16), QStringLiteral("result: -002000-"));