[WIP] another testable solution
This commit is contained in:
@@ -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>',
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user