[FIX] web: field_utils date
* list view must use stringtify value for py eval comparaison * use utc to parse database value (avoid timezone error)
This commit is contained in:
committed by
Aaron Bohy
parent
b34279c89a
commit
7465798ccd
@@ -239,18 +239,18 @@ function parseDate (value) {
|
||||
}
|
||||
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(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601], true);
|
||||
var date = moment.utc(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601], true);
|
||||
if (date.isValid() && date.year() >= 1900) {
|
||||
date.toJSON = time.date_to_str.bind(time, date.toDate());
|
||||
date.toJSON = function () {return this.utc().format('YYYY-MM-DD');};
|
||||
return date;
|
||||
}
|
||||
date = moment(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601]);
|
||||
date = moment.utc(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601]);
|
||||
if (date.isValid()) {
|
||||
if (date.year() === 0) {
|
||||
date.year(moment.utc().year());
|
||||
}
|
||||
if (date.year() >= 1900) {
|
||||
date.toJSON = time.date_to_str.bind(time, date.toDate());
|
||||
date.toJSON = function () {return this.utc().format('YYYY-MM-DD');};
|
||||
return date;
|
||||
}
|
||||
}
|
||||
@@ -274,18 +274,20 @@ 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(value, [pattern1, pattern2, moment.ISO_8601], true);
|
||||
var datetime = moment.utc(value, [pattern1, pattern2, moment.ISO_8601], true);
|
||||
if (datetime.isValid() && datetime.year() >= 1900) {
|
||||
datetime.toJSON = time.datetime_to_str.bind(time, datetime.toDate());
|
||||
datetime.toJSON = function () {
|
||||
return this.utc().format('YYYY-MM-DD HH:mm:ss');
|
||||
};
|
||||
return datetime;
|
||||
}
|
||||
datetime = moment(value, [pattern1, pattern2, moment.ISO_8601]);
|
||||
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 = time.datetime_to_str.bind(time, datetime.toDate());
|
||||
datetime.toJSON = function () {return this.utc().format('YYYY-MM-DD HH:mm:ss');};
|
||||
return datetime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,8 @@ var ListRenderer = BasicRenderer.extend({
|
||||
* @returns {string[]} a list of css classes
|
||||
*/
|
||||
_computeDecorationClassNames: function (record) {
|
||||
var context = _.extend({}, record.data, {
|
||||
var data = JSON.parse(JSON.stringify(record.data));
|
||||
var context = _.extend({}, data, {
|
||||
uid: session.uid,
|
||||
current_date: moment().format('YYYY-MM-DD')
|
||||
// TODO: time, datetime, relativedelta
|
||||
|
||||
@@ -675,6 +675,30 @@ QUnit.module('Views', {
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('support row decoration with date', function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
this.data.foo.records[0].datetime = '2017-02-27 12:51:35';
|
||||
|
||||
var list = createView({
|
||||
View: ListView,
|
||||
model: 'foo',
|
||||
data: this.data,
|
||||
arch: '<tree decoration-info="datetime == \'2017-02-27 12:51:35\'" decoration-danger="datetime > \'2017-02-27 12:51:35\' AND datetime < \'2017-02-27 10:51:35\'">' +
|
||||
'<field name="datetime"/><field name="int_field"/>' +
|
||||
'</tree>',
|
||||
});
|
||||
|
||||
assert.strictEqual(list.$('tbody tr.text-info').length, 1,
|
||||
"should have 1 columns with text-info class with good datetime");
|
||||
|
||||
assert.strictEqual(list.$('tbody tr.text-danger').length, 0,
|
||||
"should have 0 columns with text-danger class with wrong timezone datetime");
|
||||
|
||||
assert.strictEqual(list.$('tbody tr').length, 4, "should have 4 rows");
|
||||
list.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('no content helper when no data', function (assert) {
|
||||
assert.expect(5);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user