diff options
author | Caroline Chao <caroline.chao@digia.com> | 2014-04-23 16:12:16 +0200 |
---|---|---|
committer | Caroline Chao <caroline.chao@digia.com> | 2014-04-23 15:41:23 +0200 |
commit | 3de69e47160268f9d3eaba1ba07d6f6f99dee86b (patch) | |
tree | b51aecc8d5ab43da4fddc94140edf25f15f6eddd | |
parent | b017d7f39df8a58f15f8cf6c9a2ccce9acc21c76 (diff) |
Fix timezone error
Javacript Date() is using UTC time. However the time
given by yr.no is in the city local timezone and should
be used as it.
Now retrieve the offset between the UTC time and the device
local time to correct the time accordingly.
Change-Id: Ib95bba390a890cbef57c55c950440e253ba6f380
Reviewed-by: Andrew Knight <andrew.knight@digia.com>
-rw-r--r-- | qml/js/utils.js | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/qml/js/utils.js b/qml/js/utils.js index 2bf6907..76dffe3 100644 --- a/qml/js/utils.js +++ b/qml/js/utils.js @@ -85,18 +85,28 @@ function isNegative(val) return val < 0 } +function toOriginalDateTime(val) +{ + var tzo = (new Date().getTimezoneOffset())/60 + var dat = new Date(val) + dat.setHours(dat.getHours() + tzo) + return dat +} + // OneDayPage utils function getFromTime(index, dayModel) { var fromDate = dayModel.getDayDetails(index, 'from') - var fromTime = Qt.formatTime(new Date(fromDate), Qt.locale().timeFormat(QtQml.Locale.ShortFormat)) + fromDate = toOriginalDateTime(fromDate) + var fromTime = Qt.formatTime(fromDate, Qt.locale().timeFormat(QtQml.Locale.ShortFormat)) fromTime = fromTime.replace(/(:00) /, "") // save some space if display like 11:00 am return fromTime } function getToTime(index, dayModel) { var toDate = dayModel.getDayDetails(index, 'to') - var toTime = Qt.formatTime(new Date(toDate), Qt.locale().timeFormat(QtQml.Locale.ShortFormat)) + toDate = toOriginalDateTime(toDate) + var toTime = Qt.formatTime(toDate, Qt.locale().timeFormat(QtQml.Locale.ShortFormat)) toTime = toTime.replace(/(:00) /, "") // save some space if display like 11:00 am return toTime } @@ -221,13 +231,13 @@ function getDay(index, dayModel, isShort) { if (isShort === undefined) isShort = false - var dayDate = new Date(dayModel.date) + var dayDate = toOriginalDateTime(dayModel.date) return Qt.locale().dayName(dayDate.getDay(), isShort ? QtQml.Locale.ShortFormat : QtQml.Locale.LongFormat ) } function getShortDate(date) { - var d = new Date(date) + var d = toOriginalDateTime(date) var formatWithYear = Qt.locale().dateFormat(QtQml.Locale.ShortFormat) var formatWithoutYear = formatWithYear.replace(/[y]{1,4}/, "") formatWithoutYear = formatWithoutYear.replace(/^\W/, "") @@ -237,7 +247,7 @@ function getShortDate(date) function getLongDate(date) { - var d = new Date(date) + var d = toOriginalDateTime(date) return Qt.formatDate(d, Qt.locale().dateFormat(QtQml.Locale.ShortFormat)) } |