changeset d5742068fd8d in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=d5742068fd8d
description:
        Add support for UTC Date for testing purpose

        The tests may depend on the timezone of the browser so we need a way to 
write
        tests as UTC only.

        issue9577
        review298511002
diffstat:

 src/pyson.js |   4 ++--
 src/sao.js   |   5 ++++-
 tests/sao.js |  30 +++++++++++++++---------------
 3 files changed, 21 insertions(+), 18 deletions(-)

diffs (137 lines):

diff -r eb238bf04203 -r d5742068fd8d src/pyson.js
--- a/src/pyson.js      Sat Sep 05 22:59:38 2020 +0200
+++ b/src/pyson.js      Wed Sep 09 23:25:24 2020 +0200
@@ -745,10 +745,10 @@
     Sao.PYSON.Date.eval_ = function(value, context) {
         var date = value.start;
         if (date && date.isDateTime) {
-            date = Sao.Date(date.year(), date.month(), date.date());
+            date = Sao.Date(date.year(), date.month(), date.date(), true);
         }
         if (!date || !date.isDate) {
-            date = Sao.Date();
+            date = Sao.Date(undefined, undefined, undefined, true);
         }
         if (value.y) date.year(value.y);
         if (value.M) date.month(value.M - 1);
diff -r eb238bf04203 -r d5742068fd8d src/sao.js
--- a/src/sao.js        Sat Sep 05 22:59:38 2020 +0200
+++ b/src/sao.js        Wed Sep 09 23:25:24 2020 +0200
@@ -168,7 +168,7 @@
 
     Sao.Decimal = Number;
 
-    Sao.Date = function(year, month, day) {
+    Sao.Date = function(year, month, day, utc) {
         var date;
         if (month === undefined) {
             date = moment(year);
@@ -177,6 +177,9 @@
         else {
             date = moment();
         }
+        if (utc) {
+            date.utc();
+        }
         date.year(year);
         date.month(month);
         date.date(day);
diff -r eb238bf04203 -r d5742068fd8d tests/sao.js
--- a/tests/sao.js      Sat Sep 05 22:59:38 2020 +0200
+++ b/tests/sao.js      Wed Sep 09 23:25:24 2020 +0200
@@ -471,17 +471,17 @@
 
         eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Greater(
             new Sao.PYSON.DateTime(2020, 1, 1, 0, 0, 0, 0),
-            Sao.Date(2020, 0, 1)));
-        QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), true,
+            Sao.Date(2020, 0, 1, true)));
+        QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), false,
             'decode(Greater(PYSON.DateTime(2020, 1, 1, 0, 0, 0, 0), ' +
-            'Date(2020, 0, 1)))');
+            'Date(2020, 0, 1, true)))');
 
         eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Greater(
             new Sao.PYSON.DateTime(2020, 1, 1, 0, 0, 0, 0),
-            Sao.Date(2020, 0, 1), true));
+            Sao.Date(2020, 0, 1, true), true));
         QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), true,
             'decode(Greater(PYSON.DateTime(2020, 1, 1, 0, 0, 0, 0), ' +
-            'Date(2020, 0, 1), true))');
+            'Date(2020, 0, 1, true), true))');
 
         eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Greater(
             new Sao.PYSON.DateTime(2020, 1, 1, 0, 0, 0, 0),
@@ -492,7 +492,7 @@
 
         eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Greater(
             new Sao.PYSON.Date(2020, 1, 1),
-            Sao.Date(2020, 0, 1)));
+            Sao.Date(2020, 0, 1, true)));
         QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), false,
             'decode(Greater(PYSON.Date(2020, 1, 1), Date(2020, 0, 1)))');
 
@@ -617,10 +617,10 @@
 
         eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Less(
             new Sao.PYSON.Date(2020, 1, 1),
-            new Sao.PYSON.DateTime(2020, 1, 1, 0, 0, 0, 1)));
+            new Sao.PYSON.DateTime(2020, 1, 1, 0, 0, 1, 0)));
         QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), true,
             'decode(Less(PYSON.Date(2020, 1, 1), ' +
-            'PYSON.DateTime(2020, 1, 1, 0, 0, 1)))');
+            'PYSON.DateTime(2020, 1, 1, 0, 0, 1, 0)))');
 
         eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Less(
             new Sao.PYSON.DateTime(2020, 1, 1, 0, 0, 0, 0),
@@ -819,27 +819,27 @@
         eval_ = new Sao.PYSON.Encoder().encode(
                 new Sao.PYSON.Date(2010, 1, 12));
         QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_).valueOf(),
-                new Date(2010, 0, 12).valueOf());
+                Sao.Date(2010, 0, 12, true).valueOf());
 
         eval_ = new Sao.PYSON.Encoder().encode(
                 new Sao.PYSON.Date(2010, 1, 12, -1));
         QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_).valueOf(),
-                new Date(2009, 0, 12).valueOf());
+                Sao.Date(2009, 0, 12, true).valueOf());
 
         eval_ = new Sao.PYSON.Encoder().encode(
                 new Sao.PYSON.Date(2010, 1, 12, 0, 12));
         QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_).valueOf(),
-                new Date(2011, 0, 12).valueOf());
+                Sao.Date(2011, 0, 12, true).valueOf());
 
         eval_ = new Sao.PYSON.Encoder().encode(
                 new Sao.PYSON.Date(2010, 1, 12, 0, 0, -7));
         QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_).valueOf(),
-                new Date(2010, 0, 5).valueOf());
+                Sao.Date(2010, 0, 5, true).valueOf());
 
         eval_ = new Sao.PYSON.Encoder().encode(
                 new Sao.PYSON.Date(2010, 2, 22));
         QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_).valueOf(),
-                new Date(2010, 1, 22).valueOf());
+                Sao.Date(2010, 1, 22, true).valueOf());
 
         QUnit.strictEqual(
             new Sao.PYSON.Date(2010, 1, 12, -1, 12, -7).toString(),
@@ -868,7 +868,7 @@
 
         QUnit.strictEqual(new Sao.PYSON.Decoder(
             {'datetime': datetime}).decode(eval_).valueOf(),
-            Sao.Date(2000, 1, 1).valueOf());
+            Sao.Date(2000, 1, 1, true).valueOf());
 
         eval_ = new Sao.PYSON.Encoder().encode(
             new Sao.PYSON.Date(
@@ -878,7 +878,7 @@
 
         QUnit.strictEqual(new Sao.PYSON.Decoder(
             {'foo': 'bar'}).decode(eval_).valueOf(),
-            Sao.Date().valueOf());
+            Sao.Date(undefined, undefined, undefined, true).valueOf());
     });
 
     QUnit.test('PYSON DateTime', function() {

Reply via email to