aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@digia.com>2014-10-24 15:06:22 +0200
committerUlf Hermann <ulf.hermann@digia.com>2014-10-24 17:03:51 +0200
commitf06daaf3d8747c6c0a277bf055c80d8f2e7bcc81 (patch)
tree8e5e77c72e33dbe0771b48aabd12325722ec2422 /src
parentf876562de8eb978cea39fe72e76c49ae51ff2f97 (diff)
Properly handle negative years when printing JS Dates to strings.
JavaScript knows a year 0. That is correctly translated into QDateTime terms when creating a Date object, but it's not correctly translated back when converting the JavaScript date to a string. Task-number: QTBUG-29491 Change-Id: I46b200a144434187656d08e87f422f97523acd0e Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/jsruntime/qv4dateobject.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp
index 66601b64e5..e00a705700 100644
--- a/src/qml/jsruntime/qv4dateobject.cpp
+++ b/src/qml/jsruntime/qv4dateobject.cpp
@@ -557,7 +557,13 @@ static inline QString ToString(double t)
{
if (std::isnan(t))
return QStringLiteral("Invalid Date");
- QString str = ToDateTime(t, Qt::LocalTime).toString() + QStringLiteral(" GMT");
+ 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");
double tzoffset = LocalTZA + DaylightSavingTA(t);
if (tzoffset) {
int hours = static_cast<int>(::fabs(tzoffset) / 1000 / 60 / 60);