summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorAdrien Dieudonne <adr@odoo.com>2017-08-16 14:49:08 +0200
committerAaron Bohy <aab@odoo.com>2017-08-17 17:24:00 +0200
commitf5b7ad80fcfd1638cb7ea019a38871c3b8438e36 (patch)
treee8d5b29cfb608c04f0e67450d0d5a851607ffbea /addons/web/static/src/js
parentb9bfec96dd038d23e26cc822560fee452a0a3271 (diff)
[FIX] web: always use browser timezone
With the new views, we stopped using the browser timezone to display the dates in Odoo, and we used the timezone defined on the User profile instead. When loading the webclient, the timezone offset was put into the session and used to display all dates. This wasn't a good idea. The given offset was computed for the current time, meaning that it may be incorrect for specific dates (e.g. with the daylight saving, the UTC offset of today is not the same as 6 months ago). Moreover (but less likely), as the offset was stored in the session, it wasn't recalculated afterwards. So if the offset actually changed during the session (e.g. from or to daylight saving time), the displayed dates were incorrect until the user reloaded the page. With this rev., we don't retrieve the offset from the server anymore and we use the browser timezone again (like before the new views). However, we keep the computation of the offset (on the fly) in the session, so that it can be mocked in the test environment.
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/core/session.js15
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js6
-rw-r--r--addons/web/static/src/js/fields/field_utils.js6
-rw-r--r--addons/web/static/src/js/views/calendar/calendar_model.js12
4 files changed, 23 insertions, 16 deletions
diff --git a/addons/web/static/src/js/core/session.js b/addons/web/static/src/js/core/session.js
index c98ff7fbe9a..033d7995c9c 100644
--- a/addons/web/static/src/js/core/session.js
+++ b/addons/web/static/src/js/core/session.js
@@ -285,10 +285,6 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
var result = _.extend({}, window.odoo.session_info);
delete result.session_id;
_.extend(this, result);
- if (this.tzOffset === false) {
- // send by server to have the user timezone and not the browser timezone
- this.tzOffset = -new Date().getTimezoneOffset();
- }
return $.when();
},
check_session_id: function () {
@@ -410,6 +406,17 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
}) ? '' : this.prefix;
return prefix + path + qs;
},
+ /**
+ * Returns the time zone difference (in minutes) from the current locale
+ * (host system settings) to UTC, for a given date. The offset is positive
+ * if the local timezone is behind UTC, and negative if it is ahead.
+ *
+ * @param {string || moment} date a valid string date or moment instance
+ * @returns {integer}
+ */
+ getTZOffset: function (date) {
+ return -new Date(date).getTimezoneOffset();
+ },
});
return Session;
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index ec04f67e270..035d24dbdf2 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -450,7 +450,7 @@ var FieldDateTime = FieldDate.extend({
*/
_getValue: function () {
var value = this.datewidget.getValue();
- return value && value.add(-this.getSession().tzOffset, 'minutes');
+ return value && value.add(-this.getSession().getTZOffset(value), 'minutes');
},
/**
@@ -460,7 +460,7 @@ var FieldDateTime = FieldDate.extend({
* @private
*/
_makeDatePicker: function () {
- var value = this.value && this.value.clone().add(this.getSession().tzOffset, 'minutes');
+ var value = this.value && this.value.clone().add(this.getSession().getTZOffset(this.value), 'minutes');
return new datepicker.DateTimeWidget(this, {defaultDate: value});
},
@@ -471,7 +471,7 @@ var FieldDateTime = FieldDate.extend({
* @private
*/
_renderEdit: function () {
- var value = this.value && this.value.clone().add(this.getSession().tzOffset, 'minutes');
+ var value = this.value && this.value.clone().add(this.getSession().getTZOffset(this.value), 'minutes');
this.datewidget.setValue(value);
this.$input = this.datewidget.$input;
},
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js
index 787f66080dd..db5cd34d8b9 100644
--- a/addons/web/static/src/js/fields/field_utils.js
+++ b/addons/web/static/src/js/fields/field_utils.js
@@ -97,7 +97,7 @@ function formatDate(value, field, options) {
}
if (field && field.type === 'datetime') {
if (!options || !('timezone' in options) || options.timezone) {
- value = value.clone().add(session.tzOffset, 'minutes');
+ value = value.clone().add(session.getTZOffset(value), 'minutes');
}
}
var l10n = core._t.database.parameters;
@@ -123,7 +123,7 @@ function formatDateTime(value, field, options) {
return "";
}
if (!options || !('timezone' in options) || options.timezone) {
- value = value.clone().add(session.tzOffset, 'minutes');
+ value = value.clone().add(session.getTZOffset(value), 'minutes');
}
var l10n = core._t.database.parameters;
var date_format = time.strftime_to_moment_format(l10n.date_format);
@@ -404,7 +404,7 @@ function parseDateTime(value, field, options) {
} else {
datetime = moment.utc(value, [pattern1, pattern2, moment.ISO_8601], true);
if (options && options.timezone) {
- datetime.add(-session.tzOffset, 'minutes');
+ datetime.add(-session.getTZOffset(datetime), 'minutes');
}
}
if (datetime.isValid()) {
diff --git a/addons/web/static/src/js/views/calendar/calendar_model.js b/addons/web/static/src/js/views/calendar/calendar_model.js
index d2b0c02c524..ed02983d957 100644
--- a/addons/web/static/src/js/views/calendar/calendar_model.js
+++ b/addons/web/static/src/js/views/calendar/calendar_model.js
@@ -65,12 +65,12 @@ return AbstractModel.extend({
end.startOf('day').add(-1, 'days');
} else {
// default hours in the user's timezone
- start.hours(7).add(-this.getSession().tzOffset, 'minutes');
- end.hours(19).add(-this.getSession().tzOffset, 'minutes');
+ start.hours(7).add(-this.getSession().getTZOffset(start), 'minutes');
+ end.hours(19).add(-this.getSession().getTZOffset(end), 'minutes');
}
} else {
- start.add(-this.getSession().tzOffset, 'minutes');
- end.add(-this.getSession().tzOffset, 'minutes');
+ start.add(-this.getSession().getTZOffset(start), 'minutes');
+ end.add(-this.getSession().getTZOffset(end), 'minutes');
}
if (this.mapping.all_day) {
@@ -599,8 +599,8 @@ return AbstractModel.extend({
date_stop = date_start.clone().add(date_delay,'hours');
}
- date_start.add(this.getSession().tzOffset, 'minutes');
- date_stop.add(this.getSession().tzOffset, 'minutes');
+ date_start.add(this.getSession().getTZOffset(date_start), 'minutes');
+ date_stop.add(this.getSession().getTZOffset(date_stop), 'minutes');
if (this.mapping.all_day && evt[this.mapping.all_day]) {
date_stop.add(1, 'days');