From f150cf50fed7b5cf191d5e781e9f25d4f701b0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 19 Oct 2021 00:20:37 +0200 Subject: [PATCH] Run tests in UTC and use millisecond precision for moment comparison Backout of changeset d5742068fd8d issue10846 review389071002 --- Gruntfile.js | 3 +++ src/pyson.js | 6 +++--- src/sao.js | 5 +---- tests/sao.js | 38 +++++++++++++++++++------------------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 33d2442e4d..3210294536 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -140,6 +140,9 @@ module.exports = function(grunt) { args: [ '--no-sandbox', ], + env: { + TZ: 'UTC', + }, }, }, all: ['tests/*.html'] diff --git a/src/pyson.js b/src/pyson.js index df7f0c2ce3..f775c98dbf 100644 --- a/src/pyson.js +++ b/src/pyson.js @@ -453,7 +453,7 @@ var values = [value.s1, value.s2]; for (var i=0; i < 2; i++) { if (values[i] instanceof moment) { - values[i] = values[i].unix(); + values[i] = values[i].valueOf(); } else { values[i] = Number(values[i]); @@ -760,10 +760,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(), true); + date = Sao.Date(date.year(), date.month(), date.date()); } if (!date || !date.isDate) { - date = Sao.Date(undefined, undefined, undefined, true); + date = Sao.Date(); } if (value.y) date.year(value.y); if (value.M) date.month(value.M - 1); diff --git a/src/sao.js b/src/sao.js index 6363db13bb..cf1862f8e3 100644 --- a/src/sao.js +++ b/src/sao.js @@ -198,7 +198,7 @@ var Sao = {}; } }; - Sao.Date = function(year, month, day, utc) { + Sao.Date = function(year, month, day) { var date; if (month === undefined) { date = moment(year); @@ -207,9 +207,6 @@ var Sao = {}; else { date = moment(); } - if (utc) { - date.utc(); - } date.year(year); date.month(month); date.date(day); diff --git a/tests/sao.js b/tests/sao.js index 22f41bc299..5bfbc56b41 100644 --- a/tests/sao.js +++ b/tests/sao.js @@ -468,18 +468,18 @@ 'Date(2020, 0, 2)))'); 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))); - QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), false, - 'decode(Greater(PYSON.DateTime(2020, 1, 1, 0, 0, 0, 0), ' + - 'Date(2020, 0, 1, true)))'); + new Sao.PYSON.DateTime(2020, 1, 1, 0, 0, 0, 1000), + Sao.Date(2020, 0, 1))); + QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), true, + 'decode(Greater(PYSON.DateTime(2020, 1, 1, 0, 0, 0, 1000), ' + + 'Date(2020, 0, 1)))'); 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), true)); + Sao.Date(2020, 0, 1), 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), true))'); + '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), @@ -490,7 +490,7 @@ eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Greater( new Sao.PYSON.Date(2020, 1, 1), - Sao.Date(2020, 0, 1, true))); + Sao.Date(2020, 0, 1))); QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), false, 'decode(Greater(PYSON.Date(2020, 1, 1), Date(2020, 0, 1)))'); @@ -587,10 +587,10 @@ "Less(0, 1, false)"); eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Less( - new Sao.PYSON.DateTime(2020, 1, 1, 0, 0, 0, 0), + new Sao.PYSON.DateTime(2020, 1, 1, 0, 0, 0, 1000), Sao.Date(2020, 0, 1))); QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), false, - 'decode(Less(PYSON.DateTime(2020, 1, 1, 0, 0, 0, 0), ' + + 'decode(Less(PYSON.DateTime(2020, 1, 1, 0, 0, 0, 1000), ' + 'Date(2020, 0, 1)))'); eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Less( @@ -615,10 +615,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, 1, 0))); + new Sao.PYSON.DateTime(2020, 1, 1, 0, 0, 0, 1000))); QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), true, 'decode(Less(PYSON.Date(2020, 1, 1), ' + - 'PYSON.DateTime(2020, 1, 1, 0, 0, 1, 0)))'); + 'PYSON.DateTime(2020, 1, 1, 0, 0, 1000)))'); eval_ = new Sao.PYSON.Encoder().encode(new Sao.PYSON.Less( new Sao.PYSON.DateTime(2020, 1, 1, 0, 0, 0, 0), @@ -827,27 +827,27 @@ eval_ = new Sao.PYSON.Encoder().encode( new Sao.PYSON.Date(2010, 1, 12)); QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_).valueOf(), - Sao.Date(2010, 0, 12, true).valueOf()); + new Date(2010, 0, 12).valueOf()); eval_ = new Sao.PYSON.Encoder().encode( new Sao.PYSON.Date(2010, 1, 12, -1)); QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_).valueOf(), - Sao.Date(2009, 0, 12, true).valueOf()); + new Date(2009, 0, 12).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(), - Sao.Date(2011, 0, 12, true).valueOf()); + new Date(2011, 0, 12).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(), - Sao.Date(2010, 0, 5, true).valueOf()); + new Date(2010, 0, 5).valueOf()); eval_ = new Sao.PYSON.Encoder().encode( new Sao.PYSON.Date(2010, 2, 22)); QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_).valueOf(), - Sao.Date(2010, 1, 22, true).valueOf()); + new Date(2010, 1, 22).valueOf()); QUnit.strictEqual( new Sao.PYSON.Date(2010, 1, 12, -1, 12, -7).toString(), @@ -876,7 +876,7 @@ QUnit.strictEqual(new Sao.PYSON.Decoder( {'datetime': datetime}).decode(eval_).valueOf(), - Sao.Date(2000, 1, 1, true).valueOf()); + Sao.Date(2000, 1, 1).valueOf()); eval_ = new Sao.PYSON.Encoder().encode( new Sao.PYSON.Date( @@ -886,7 +886,7 @@ QUnit.strictEqual(new Sao.PYSON.Decoder( {'foo': 'bar'}).decode(eval_).valueOf(), - Sao.Date(undefined, undefined, undefined, true).valueOf()); + Sao.Date().valueOf()); }); QUnit.test('PYSON DateTime', function() {