summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorAdrien Dieudonne <adr@odoo.com>2017-08-16 13:21:54 +0200
committerAaron Bohy <aab@odoo.com>2017-08-17 17:24:00 +0200
commitb9bfec96dd038d23e26cc822560fee452a0a3271 (patch)
tree47c6c74a934e86ce01839122a2fb7dcf552cf913 /addons/web/static/src
parent88dfcfd025ad87476d27cb7122cedc9ab2e94d3c (diff)
[FIX] web: don't apply timezone offset for date fields
Before this rev., all date fields values were off by one day as soon as the user timezone was negative. With the new views, all dates manipulated by the JS are moment instances in UTC, and when being displayed, they are correctly formatted in the user locale by applying the timezone offset. However, this should obviously not be done for date fields as when no time is specified when creating a moment instance, it defaults to 00:00:00, so applying a negative offset always leads to the day before. Remark: It happens that datetime fields are displayed as a date (e.g. purchase order line form view). In that case, the offset is applied on the displayed date.
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/fields/field_utils.js11
-rw-r--r--addons/web/static/src/js/fields/special_fields.js2
2 files changed, 6 insertions, 7 deletions
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js
index 0a44a52e315..787f66080dd 100644
--- a/addons/web/static/src/js/fields/field_utils.js
+++ b/addons/web/static/src/js/fields/field_utils.js
@@ -95,8 +95,10 @@ function formatDate(value, field, options) {
if (value === false) {
return "";
}
- if (!options || !('timezone' in options) || options.timezone) {
- value = value.clone().add(session.tzOffset < 0 ? -1 : 0, 'days');
+ if (field && field.type === 'datetime') {
+ 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);
@@ -357,11 +359,8 @@ function parseDate(value, field, options) {
date = moment.utc(value);
} else {
date = moment.utc(value, [datePattern, datePatternWoZero, moment.ISO_8601], true);
- if (options && options.timezone) {
- date.add(session.tzOffset > 0 ? -1 : 0, 'days');
- }
}
- if (date.isValid() && date.year() >= 1900) {
+ if (date.isValid()) {
if (date.year() === 0) {
date.year(moment.utc().year());
}
diff --git a/addons/web/static/src/js/fields/special_fields.js b/addons/web/static/src/js/fields/special_fields.js
index 69647902afe..7a0bb9ed092 100644
--- a/addons/web/static/src/js/fields/special_fields.js
+++ b/addons/web/static/src/js/fields/special_fields.js
@@ -54,7 +54,7 @@ var FieldTimezoneMismatch = FieldSelection.extend({
}
var offset = this.recordData.tz_offset.match(/([+-])([0-9]{2})([0-9]{2})/);
offset = (offset[1] === '-' ? -1 : 1) * (parseInt(offset[2])*60 + parseInt(offset[3]));
- var datetime = field_utils.format.datetime(moment.utc().add(offset, 'minutes'), {timezone: false});
+ var datetime = field_utils.format.datetime(moment.utc().add(offset, 'minutes'), this.field, {timezone: false});
var content = this.$option.html().split(' ')[0];
content += ' ('+ datetime + ')';
this.$option.html(content);