diff options
| author | Christophe Matthieu <chm@odoo.com> | 2017-04-12 11:53:42 +0200 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2017-04-13 16:55:00 +0200 |
| commit | c32724eae06c987e74a0600f1669696e499edc33 (patch) | |
| tree | e80d8ccc3c08ec4a95889a06f6624e2c63b5bb29 /addons/web/static/src/js/fields/field_utils.js | |
| parent | 9c43ad85d463ef8f1fb4b8d16924bc71c0885a55 (diff) | |
[FIX] web: calendar timezone with user configuration
The client must receive the tzOffset to apply this on all hours.
To use the date picker we must change the date to apply the change
in the user's tzOffset, without this change the result is wrong.
For datetime widget we must change like it to avoid max stack error.
The server send the tzOffset, if it's undefined, by default the client
use the browser time offset.
Every test are change to use tzOffset.
A test is added in calendar to use the click by position for the
fullcalendar lib. This test create and drag and drop an event to check
timezone error and error when we use default value in the context.
Use formating date like 2026-04-04T08:00:00Z instead of 2026-04-04 08:00:00
is important for phantomjs, because it's crash without information if the
formating is not the standard format.
For the parsing, when the client receive a server date the date is utc
formating but when it's parsed from the client is in the user's timezone
Diffstat (limited to 'addons/web/static/src/js/fields/field_utils.js')
| -rw-r--r-- | addons/web/static/src/js/fields/field_utils.js | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js index a086ebefd15..d6677291d47 100644 --- a/addons/web/static/src/js/fields/field_utils.js +++ b/addons/web/static/src/js/fields/field_utils.js @@ -79,10 +79,13 @@ function formatDate(value) { * @params {Moment|false} * @returns {string} */ -function formatDateTime(value) { +function formatDateTime(value, options) { if (!value) { return ""; } + if (!options || !('timezone' in options) || options.timezone) { + value = value.clone().add(session.tzOffset, 'minutes'); + } var l10n = core._t.database.parameters; var date_format = time.strftime_to_moment_format(l10n.date_format); var time_format = time.strftime_to_moment_format(l10n.time_format); @@ -267,24 +270,26 @@ function formatSelection(value, field) { * @params {string} * @returns {Moment|false} Moment date object */ -function parseDate(value) { +function parseDate(value, field, options) { if (!value) { return false; } var date_pattern = time.strftime_to_moment_format(core._t.database.parameters.date_format); var date_pattern_wo_zero = date_pattern.replace('MM','M').replace('DD','D'); - var date = moment.utc(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601], true); - if (date.isValid() && date.year() >= 1900) { - date.toJSON = function () {return this.utc().format('YYYY-MM-DD');}; - return date; + var date; + if (options && options.isUTC) { + date = moment.utc(value); + } else { + date = moment.utc(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601], true); } - date = moment.utc(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601]); - if (date.isValid()) { + if (date.isValid() && date.year() >= 1900) { if (date.year() === 0) { date.year(moment.utc().year()); } if (date.year() >= 1900) { - date.toJSON = function () {return this.utc().format('YYYY-MM-DD');}; + date.toJSON = function () { + return this.format('YYYY-MM-DD'); + }; return date; } } @@ -298,7 +303,7 @@ function parseDate(value) { * @params {string} * @returns {Moment|false} Moment date object */ -function parseDateTime(value) { +function parseDateTime(value, field, options) { if (!value) { return false; } @@ -308,20 +313,24 @@ function parseDateTime(value) { time_pattern_wo_zero = time_pattern.replace('HH','H').replace('mm','m').replace('ss','s'); var pattern1 = date_pattern + ' ' + time_pattern; var pattern2 = date_pattern_wo_zero + ' ' + time_pattern_wo_zero; - var datetime = moment.utc(value, [pattern1, pattern2, moment.ISO_8601], true); - if (datetime.isValid() && datetime.year() >= 1900) { - datetime.toJSON = function () { - return this.utc().format('YYYY-MM-DD HH:mm:ss'); - }; - return datetime; + var datetime; + if (options && options.isUTC) { + // phatomjs crash if we don't use this format + datetime = moment.utc(value.replace(' ', 'T') + 'Z'); + } else { + datetime = moment.utc(value, [pattern1, pattern2, moment.ISO_8601], true); + if (options && options.timezone) { + datetime.add(-session.tzOffset, 'minutes'); + } } - datetime = moment.utc(value, [pattern1, pattern2, moment.ISO_8601]); if (datetime.isValid()) { if (datetime.year() === 0) { datetime.year(moment.utc().year()); } if (datetime.year() >= 1900) { - datetime.toJSON = function () {return this.utc().format('YYYY-MM-DD HH:mm:ss');}; + datetime.toJSON = function () { + return this.format('YYYY-MM-DD HH:mm:ss'); + }; return datetime; } } |
