[FIX] web: correct date and datetime parsing at end of month.

As `new Date()` return the current date, when we are the 31,
setting the month to a month with less than 31 days will change
the date to next day (1st of next month). This result to a date(time)
object one month ahead of the wanted date(time).

bzr revid: chs@openerp.com-20131031103333-vt68132ptj9sbr04
This commit is contained in:
Christophe Simonis 2013-10-31 11:33:33 +01:00
parent 062d075f36
commit d9ca536396
2 changed files with 40 additions and 3 deletions

View File

@ -1265,7 +1265,7 @@ openerp.str_to_datetime = function(str) {
if ( !res ) {
throw new Error("'" + str + "' is not a valid datetime");
}
var tmp = new Date();
var tmp = new Date(0);
tmp.setUTCFullYear(parseFloat(res[1]));
tmp.setUTCMonth(parseFloat(res[2]) - 1);
tmp.setUTCDate(parseFloat(res[3]));
@ -1297,7 +1297,7 @@ openerp.str_to_date = function(str) {
if ( !res ) {
throw new Error("'" + str + "' is not a valid date");
}
var tmp = new Date();
var tmp = new Date(0);
tmp.setFullYear(parseFloat(res[1]));
tmp.setMonth(parseFloat(res[2]) - 1);
tmp.setDate(parseFloat(res[3]));
@ -1424,4 +1424,4 @@ if (typeof(define) !== "undefined") { // amd
window.openerp = declare($, _, QWeb2);
}
})();
})();

View File

@ -427,12 +427,49 @@ ropenerp.testing.section('server-formats', {
date3.getUTCHours(), date3.getUTCMinutes(), date3.getUTCSeconds(), date3.getUTCMilliseconds()],
[2009, 5 - 1, 4, 12, 34, 23, 845]);
});
test('Parse server datetime on 31', function() {
var wDate = window.Date;
var s = openerp.testing.Stack();
return s.push(function() {
window.Date = function() {
return wDate('2013-10-31 12:34:56');
};
}, function() {
window.Date = wDate;
}).execute(function() {
return openerp.str_to_datetime('2013-11-11 02:45:21');
}).then(function(date) {
deepEqual(
[date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(),
date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds()],
[2013, 11 - 1, 11, 2, 45, 21]);
});
});
test('Parse server date', function () {
var date = openerp.str_to_date("2009-05-04");
deepEqual(
[date.getFullYear(), date.getMonth(), date.getDate()],
[2009, 5 - 1, 4]);
});
test('Parse server date on 31', function() {
var wDate = window.Date;
var s = openerp.testing.Stack();
return s.push(function() {
window.Date = function() {
return wDate('2013-10-31 12:34:56');
};
}, function() {
window.Date = wDate;
}).execute(function() {
return openerp.str_to_date('2013-11-11');
}).then(function(date) {
deepEqual(
[date.getFullYear(), date.getMonth(), date.getDate()],
[2013, 11 - 1, 11]);
});
});
test('Parse server time', function () {
var date = openerp.str_to_time("12:34:23");
deepEqual(