From f5b7ad80fcfd1638cb7ea019a38871c3b8438e36 Mon Sep 17 00:00:00 2001 From: Adrien Dieudonne Date: Wed, 16 Aug 2017 14:49:08 +0200 Subject: [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. --- addons/web/static/src/js/core/session.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src/js/core/session.js') 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; -- cgit v1.2.3