From 76881fb2262c9fcfc306c8b1f6d2394b402d0ce1 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Mon, 13 Apr 2015 14:39:14 +0200 Subject: [PATCH] [FIX] web: backport datetime.toJSON() so we can return local datetimes in search domains This fix adds the toJSON() method to datetime.datetime, so domain expressions can use datetime values directly, without having to compute the stringified version with convoluted strftime() and timezone calculations. The datetime results are sent down to the JSON-RPC level where the JSON.stringify() serialization will convert them to UTC string, to be deserialized properly as UTC datetime values on the server side. Thanks to this we can use the browser's local midnight timestamp in a filter expression, for example like this: `datetime.datetime.combine(context_today(), datetime.time(0,0,0))` and get the expected result regardless of the user/browser's timezone. related to issue #2972 and pull request #2914 and #6229 (Next commit will fix them) opw-621282 --- addons/web/static/src/js/pyeval.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index 6ce85f8d4a3..bfef771d156 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -412,7 +412,17 @@ openerp.web.pyeval = function (instance) { py.PY_getAttr(args.time, 'minute'), py.PY_getAttr(args.time, 'second') ]); - }) + }), + toJSON: function () { + return new Date( + this.year, + this.month - 1, + this.day, + this.hour, + this.minute, + this.second, + this.microsecond / 1000); + }, }); datetime.date = py.type('date', null, { __init__: function () {