From 3fa15618aec4fc4910d1f34109c5552d718765b5 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sat, 4 May 2013 23:18:20 +0200 Subject: [PATCH] Fix some bugs in converting to and from QDateTime Use the conversion methods in QDateTime instead of trying to do our own thing in qv4dateobject. Change-Id: Ib44b3e0c60b14f94fd717a6954610d249a1bea66 Reviewed-by: Simon Hausmann --- src/qml/qml/v4/qv4dateobject.cpp | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/qml/qml/v4/qv4dateobject.cpp b/src/qml/qml/v4/qv4dateobject.cpp index d7d1cbd..6d78e47 100644 --- a/src/qml/qml/v4/qv4dateobject.cpp +++ b/src/qml/qml/v4/qv4dateobject.cpp @@ -344,26 +344,6 @@ static inline double TimeClip(double t) return Value::toInteger(t); } -static inline double FromDateTime(const QDateTime &dt) -{ - if (!dt.isValid()) - return qSNaN(); - QDate date = dt.date(); - QTime taim = dt.time(); - int year = date.year(); - int month = date.month() - 1; - int day = date.day(); - int hours = taim.hour(); - int mins = taim.minute(); - int secs = taim.second(); - int ms = taim.msec(); - double t = MakeDate(MakeDay(year, month, day), - MakeTime(hours, mins, secs, ms)); - if (dt.timeSpec() == Qt::LocalTime) - t = UTC(t); - return TimeClip(t); -} - static inline double ParseString(const QString &s) { // first try the format defined in 15.9.1.15, only if that fails fall back to @@ -562,7 +542,9 @@ static inline double ParseString(const QString &s) break; } } - return FromDateTime(dt); + if (!dt.isValid()) + return qSNaN(); + return dt.toMSecsSinceEpoch(); } /*! @@ -661,7 +643,7 @@ DateObject::DateObject(ExecutionEngine *engine, const QDateTime &date) : Object(engine) { type = Type_DateObject; - value = Value::fromDouble(FromDateTime(date)); + value = Value::fromDouble(date.toMSecsSinceEpoch()); } QDateTime DateObject::toQDateTime() const -- 2.7.4