summaryrefslogtreecommitdiff
path: root/addons/web/static/test/evals.js
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2014-01-22 16:19:11 +0100
committerXavier Morel <xmo@openerp.com>2014-01-22 16:19:11 +0100
commit5b7ade9db180b8a038c2a9944aba85d1ffd220ea (patch)
tree14a6c6b3052a756f2032baef042060dfc6ac99ab /addons/web/static/test/evals.js
parent36eedfab43a28b72a6dd6375c0f71828f238fc37 (diff)
[ADD] ways to correctly handle local datetimes in e.g. domains
* change datetime.now() to generate user-local naive datetimes * add datetime.utcnow() behaving as the old now() * add date.today() generating a user-local date (for the current day) * add datetime.replace() to replace any specific attribute of the datetime object (except tzinfo, for now) * datetime.toJSON() now returns the equivalent javascript Date object (warning: uses the datetime attributes directly, since datetimes are naive if they were created with utcnow() the Date result is going to be complete nonsense). With the previous commit datetime.now() generates a user-local now() which is converted to the correct UTC datetime when sent to the server. This means it becomes possible to generate datetime bounds for the user's local today with either datetime.datetime.now().replace(hour=0, minute=0, second=0) or datetime.datetime.combine( datetime.date.today(), datetime.time()) and once send over JSON-RPC the server will get the local datetime in UTC to the server's format. nb: user-local means "in the timezone of the user's browser" in this context. bzr revid: xmo@openerp.com-20140122151911-akn1nr6e739eg92s
Diffstat (limited to 'addons/web/static/test/evals.js')
-rw-r--r--addons/web/static/test/evals.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/addons/web/static/test/evals.js b/addons/web/static/test/evals.js
index 840ad051aca..13ac0f3f3b7 100644
--- a/addons/web/static/test/evals.js
+++ b/addons/web/static/test/evals.js
@@ -265,6 +265,41 @@ openerp.testing.section('eval.types', {
instance.web.pyeval.context()),
"2012-02-14 23:59:59");
});
+ test('datetime.tojson', function (instance) {
+ var result = py.eval(
+ 'datetime.datetime(2012, 2, 15, 1, 7, 31)',
+ instance.web.pyeval.context());
+ ok(result instanceof Date);
+ equal(result.getFullYear(), 2012);
+ equal(result.getMonth(), 1);
+ equal(result.getDate(), 15);
+ equal(result.getHours(), 1);
+ equal(result.getMinutes(), 7);
+ equal(result.getSeconds(), 31);
+ });
+ test('datetime.combine', function (instance) {
+ var result = py.eval(
+ 'datetime.datetime.combine(datetime.date(2012, 2, 15),' +
+ ' datetime.time(1, 7, 13))' +
+ ' .strftime("%Y-%m-%d %H:%M:%S")',
+ instance.web.pyeval.context());
+ equal(result, "2012-02-15 01:07:13");
+
+ result = py.eval(
+ 'datetime.datetime.combine(datetime.date(2012, 2, 15),' +
+ ' datetime.time())' +
+ ' .strftime("%Y-%m-%d %H:%M:%S")',
+ instance.web.pyeval.context());
+ equal(result, '2012-02-15 00:00:00');
+ });
+ test('datetime.replace', function (instance) {
+ var result = py.eval(
+ 'datetime.datetime(2012, 2, 15, 1, 7, 13)' +
+ ' .replace(hour=0, minute=0, second=0)' +
+ ' .strftime("%Y-%m-%d %H:%M:%S")',
+ instance.web.pyeval.context());
+ equal(result, "2012-02-15 00:00:00");
+ });
});
openerp.testing.section('eval.edc', {
dependencies: ['web.data'],