[IMP] web: Time(hours,minutes,seconds) should be calculate using timedelta with datetime on web client, added test cases for pyeval datetime.timedelta
This commit is contained in:
@@ -436,6 +436,22 @@ datetime.datetime = py.type('datetime', null, {
|
||||
this.second,
|
||||
this.microsecond / 1000);
|
||||
},
|
||||
__add__: function (other) {
|
||||
if (!py.PY_isInstance(other, datetime.timedelta)) {
|
||||
return py.NotImplemented;
|
||||
}
|
||||
var s = tmxxx(this.year, this.month, this.day + other.days, this.hour, this.minute, this.second + other.seconds);
|
||||
return datetime.datetime.fromJSON(s.year, s.month, s.day, s.hour, s.minute, s.second);
|
||||
},
|
||||
__sub__: function (other) {
|
||||
if (py.PY_isInstance(other, datetime.timedelta)) {
|
||||
return py.PY_add(this, py.PY_negative(other));
|
||||
}
|
||||
return py.NotImplemented;
|
||||
},
|
||||
fromJSON: function (year, month, day, hour, minute, second) {
|
||||
return py.PY_call(datetime.datetime, [year, month, day, hour, minute, second]);
|
||||
},
|
||||
});
|
||||
|
||||
datetime.date = py.type('date', null, {
|
||||
|
||||
@@ -302,6 +302,25 @@ odoo.define_section('eval.types', ['web.pyeval'], function (test, mock) {
|
||||
'2015-02-02');
|
||||
});
|
||||
|
||||
test('timedelta', function (assert, pyeval) {
|
||||
assert.strictEqual(
|
||||
py.eval("(datetime.datetime(2017, 2, 15, 1, 7, 31) + datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')",
|
||||
pyeval.context()),
|
||||
"2017-02-16 01:07:31");
|
||||
strictEqual(
|
||||
py.eval("(datetime.datetime(2012, 2, 15, 1, 7, 31) - datetime.timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S')",
|
||||
pyeval.context()),
|
||||
"2012-02-15 00:07:31");
|
||||
strictEqual(
|
||||
py.eval("(datetime.datetime(2012, 2, 15, 1, 7, 31) + datetime.timedelta(hours=-1)).strftime('%Y-%m-%d %H:%M:%S')",
|
||||
pyeval.context()),
|
||||
"2012-02-15 00:07:31");
|
||||
strictEqual(
|
||||
py.eval("(datetime.datetime(2012, 2, 15, 1, 7, 31) + datetime.timedelta(minutes=100)).strftime('%Y-%m-%d %H:%M:%S')",
|
||||
pyeval.context()),
|
||||
"2012-02-15 02:47:31");
|
||||
});
|
||||
|
||||
test('datetime.tojson', function (assert, pyeval) {
|
||||
var result = py.eval(
|
||||
'datetime.datetime(2012, 2, 15, 1, 7, 31)',
|
||||
|
||||
Reference in New Issue
Block a user