summaryrefslogtreecommitdiff
path: root/addons/web/static
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2018-11-12 15:29:07 +0000
committerLucas Perais (lpe) <lpe@odoo.com>2018-11-12 15:29:07 +0000
commitbd83517fecaaa6803fd6e300085b98470242bc8d (patch)
treec11b82d10ca846a0025c2f97283800cc5ab65532 /addons/web/static
parentc346428397d257881969978317f950fdb81e925c (diff)
[FIXUP] testable solution
Diffstat (limited to 'addons/web/static')
-rw-r--r--addons/web/static/src/js/chrome/search_inputs.js12
-rw-r--r--addons/web/static/src/js/fields/field_utils.js10
2 files changed, 10 insertions, 12 deletions
diff --git a/addons/web/static/src/js/chrome/search_inputs.js b/addons/web/static/src/js/chrome/search_inputs.js
index 6d8d4ec35b3..29db17df252 100644
--- a/addons/web/static/src/js/chrome/search_inputs.js
+++ b/addons/web/static/src/js/chrome/search_inputs.js
@@ -346,24 +346,18 @@ 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}, {timezone: true});
+ v = field_utils.parse[t](needle, {type: t}, parseFormatOptions);
} catch (e) {
return $.when(null);
}
- if (t === 'date') {
- // v is flagged UTC, so it will get transformed
- // into the browser's timezone when calling toDate
- // to avoid it, we use the string representation
- // that will be truncated later to build another moment
- v = v.format();
- }
var m = moment(v, t === 'datetime' ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD');
if (!m.isValid()) { return $.when(null); }
- var date_string = field_utils.format[t](m, {type: t});
+ var date_string = field_utils.format[t](m, {type: t}, parseFormatOptions);
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 5a11f1b0ba8..7da03b023b8 100644
--- a/addons/web/static/src/js/fields/field_utils.js
+++ b/addons/web/static/src/js/fields/field_utils.js
@@ -109,10 +109,11 @@ function formatDate(value, field, options) {
if (value === false) {
return "";
}
- if (field && field.type === 'datetime') {
- if (!options || !('timezone' in options) || options.timezone) {
+ var fieldType = field && field.type;
+ if (fieldType === 'datetime' &&
+ (!options || !('timezone' in options)) ||
+ options && options.timezone) {
value = value.clone().add(session.getTZOffset(value), 'minutes');
- }
}
var date_format = time.getLangDateFormat();
return value.format(date_format);
@@ -372,6 +373,9 @@ 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) {