aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4dateobject.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2014-12-11 14:05:31 +0100
committerUlf Hermann <ulf.hermann@theqtcompany.com>2014-12-12 12:56:57 +0100
commit68c2c56a1a3d7948c687ffae3a9d3c6cbd06a527 (patch)
treea577ad94d46e625512351b2d0a67d76c91e90004 /src/qml/jsruntime/qv4dateobject.cpp
parent6179550a0ca761bfabd4f6c67103f5397a306df0 (diff)
Revert "Properly handle negative years when printing JS Dates to strings."
This reverts commit f06daaf3d8747c6c0a277bf055c80d8f2e7bcc81. The only things actually specified by the ECMAScript standard on dates are: 1. Reparsing a date output from any of the to*String() functions has to result in the same date representation. 2. The ISO 8601 standard has to be followed for the ISO format. Currently we clearly don't follow rule 1. Date.parse(d.toString()) will not yield the same as d.valueOf() for negative dates. The ISO 8601 standard clearly has a year 0 while common human language has not. All non ISO date representations are considered "implementation-dependent" in the ECMAScript standard. We can thus define the relation between our representations and the ISO standard any way we like. If we try to match up the dates so that the negative years look equal in each representation we cannot properly interact with QDate for dates in the year 0 as that doesn't exist in QDate. We can, however, choose not to make the dates look equal. That means a date with a negative year will be "one off" when represented in ISO 8601. "333 BC" in human language is "-332" in ISO 8601. Our internal representation is aligned to ISO 8601 and the to*String() methods may output something else. That means we can easily set the year in ISO 8601 sense from the Date constructor as well as from setYear() and setFullYear(). This, of course, is somewhat unintuitive and also differs from most other JavaScript implementations (which don't have to interoperate with QDate). However, it is still correct. Change-Id: I5fc26b709a486cb520a075918b184a80bec56c9b Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4dateobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4dateobject.cpp8
1 files changed, 1 insertions, 7 deletions
diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp
index 6455219881..7fc9855f98 100644
--- a/src/qml/jsruntime/qv4dateobject.cpp
+++ b/src/qml/jsruntime/qv4dateobject.cpp
@@ -559,13 +559,7 @@ static inline QString ToString(double t)
{
if (std::isnan(t))
return QStringLiteral("Invalid Date");
- QDateTime dateTime = ToDateTime(t, Qt::LocalTime);
-
- // JavaScript knows a year 0, while QDateTime doesn't. So, in order to show the right date we
- // have to add a year to negative ones here.
- if (dateTime.date().year() < 0)
- dateTime = dateTime.addYears(1);
- QString str = dateTime.toString() + QStringLiteral(" GMT");
+ QString str = ToDateTime(t, Qt::LocalTime).toString() + QStringLiteral(" GMT");
double tzoffset = LocalTZA + DaylightSavingTA(t);
if (tzoffset) {
int hours = static_cast<int>(::fabs(tzoffset) / 1000 / 60 / 60);