summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2018-11-12 16:12:29 +0000
committerLucas Perais (lpe) <lpe@odoo.com>2018-11-12 16:12:29 +0000
commit293f9d27ad8cf2d9efddf20467264c46d324d84d (patch)
tree86b0559fd6854255f82738f247d89c12a1f5c18e /addons/web/static/src
parentbd83517fecaaa6803fd6e300085b98470242bc8d (diff)
[WIP] another testable solution
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/chrome/search_inputs.js14
-rw-r--r--addons/web/static/src/js/fields/field_utils.js10
2 files changed, 14 insertions, 10 deletions
diff --git a/addons/web/static/src/js/chrome/search_inputs.js b/addons/web/static/src/js/chrome/search_inputs.js
index 29db17df252..6c88d82a5d5 100644
--- a/addons/web/static/src/js/chrome/search_inputs.js
+++ b/addons/web/static/src/js/chrome/search_inputs.js
@@ -6,6 +6,7 @@ var core = require('web.core');
var Domain = require('web.Domain');
var field_utils = require('web.field_utils');
var pyeval = require('web.pyeval');
+var session = require('web.session');
var time = require('web.time');
var utils = require('web.utils');
var Widget = require('web.Widget');
@@ -346,18 +347,25 @@ var DateField = Field.extend(/** @lends instance.web.search.DateField# */{
complete: function (needle) {
// Make sure the needle has a correct format before the creation of the moment object. See
// issue https://github.com/moment/moment/issues/1407
- var parseFormatOptions = {timezone: true};
var t, v;
try {
t = (this.attrs && this.attrs.type === 'datetime') ? 'datetime' : 'date';
- v = field_utils.parse[t](needle, {type: t}, parseFormatOptions);
+ v = field_utils.parse[t](needle, {type: t}, {timezone: true});
} catch (e) {
return $.when(null);
}
var m = moment(v, t === 'datetime' ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD');
+
+ if (t === 'date') {
+ // at this point, m is SOMEDAY at midnight BUT
+ // Constructed from a "v" object that was forced in utc
+ // So we need to apply timezone correction here
+ m = m.clone().add(-session.getTZOffset(m), 'minutes');
+ }
+
if (!m.isValid()) { return $.when(null); }
- var date_string = field_utils.format[t](m, {type: t}, parseFormatOptions);
+ var date_string = field_utils.format[t](m, {type: t});
var label = _.str.sprintf(_.str.escapeHTML(
_t("Search %(field)s at: %(value)s")), {
field: '<em>' + _.escape(this.attrs.string) + '</em>',
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js
index 7da03b023b8..5a11f1b0ba8 100644
--- a/addons/web/static/src/js/fields/field_utils.js
+++ b/addons/web/static/src/js/fields/field_utils.js
@@ -109,11 +109,10 @@ function formatDate(value, field, options) {
if (value === false) {
return "";
}
- var fieldType = field && field.type;
- if (fieldType === 'datetime' &&
- (!options || !('timezone' in options)) ||
- options && options.timezone) {
+ if (field && field.type === 'datetime') {
+ if (!options || !('timezone' in options) || options.timezone) {
value = value.clone().add(session.getTZOffset(value), 'minutes');
+ }
}
var date_format = time.getLangDateFormat();
return value.format(date_format);
@@ -373,9 +372,6 @@ 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.getTZOffset(date), 'minutes');
- }
}
if (date.isValid()) {
if (date.year() === 0) {