summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-08-31 09:15:30 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-08-31 09:20:40 (GMT)
commitae574f7341f4f76a1f7de570cc3d56f77781e625 (patch)
treefd85a743bfb3917380b6134ee2a0b92956e3b2ba /src
parenteb1015c7bbf135af3656110a4d112377c1209db8 (diff)
downloadQt-ae574f7341f4f76a1f7de570cc3d56f77781e625.zip
Qt-ae574f7341f4f76a1f7de570cc3d56f77781e625.tar.gz
Qt-ae574f7341f4f76a1f7de570cc3d56f77781e625.tar.bz2
Fix QtScript Date <--> QDateTime (local time) conversion
This has already been fixed in 4.7 (QTBUG-9770), but the change is too big to backport. The general idea is the same: Only operate on UTC dates internally (since that's how JS dates are stored), and let QDateTime take care of converting from/to local dates as necessary. The fix itself shouldn't be merged to 4.7, but the autotests should. Task-number: QTBUG-9770 Reviewed-by: Jedrzej Nowacki
Diffstat (limited to 'src')
-rw-r--r--src/script/utils/qscriptdate.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/script/utils/qscriptdate.cpp b/src/script/utils/qscriptdate.cpp
index 5980256..3985adb 100644
--- a/src/script/utils/qscriptdate.cpp
+++ b/src/script/utils/qscriptdate.cpp
@@ -320,8 +320,9 @@ qsreal FromDateTime(const QDateTime &dt)
return qSNaN();
if (!LocalTZA) // ### move
LocalTZA = getLocalTZA();
- QDate date = dt.date();
- QTime taim = dt.time();
+ QDateTime utc = dt.toUTC();
+ QDate date = utc.date();
+ QTime taim = utc.time();
int year = date.year();
int month = date.month() - 1;
int day = date.day();
@@ -331,8 +332,6 @@ qsreal FromDateTime(const QDateTime &dt)
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);
}
@@ -348,8 +347,6 @@ QDateTime ToDateTime(qsreal t, Qt::TimeSpec spec)
return QDateTime();
if (!LocalTZA) // ### move
LocalTZA = getLocalTZA();
- if (spec == Qt::LocalTime)
- t = LocalTime(t);
int year = int(YearFromTime(t));
int month = int(MonthFromTime(t) + 1);
int day = int(DateFromTime(t));
@@ -357,7 +354,7 @@ QDateTime ToDateTime(qsreal t, Qt::TimeSpec spec)
int mins = MinFromTime(t);
int secs = SecFromTime(t);
int ms = msFromTime(t);
- return QDateTime(QDate(year, month, day), QTime(hours, mins, secs, ms), spec);
+ return QDateTime(QDate(year, month, day), QTime(hours, mins, secs, ms), Qt::UTC).toTimeSpec(spec);
}
} // namespace QScript