From bef86f55ceefb1f2ea3fb95a1a5112530707bd46 Mon Sep 17 00:00:00 2001 From: Konstantin Molchanov Date: Mon, 27 Mar 2017 00:14:48 +0400 Subject: [PATCH 1/3] Times: JS: Add yearday to TimeInfo. Add yearday calculation to getLocalTime and getGMTime, so that yearday is not 0 for TimeInfo instances under JS backend. Yearday 0 has no sense and contradicts the behaviour under C backend, where yearday is an int from 1 to 365, i.e. cannot be 0 even theoretically. --- lib/pure/times.nim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/pure/times.nim b/lib/pure/times.nim index fe35c404c6..2b7c221452 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -597,9 +597,12 @@ elif defined(JS): result.month = Month(t.getMonth()) result.year = t.getFullYear() result.weekday = weekDays[t.getDay()] - result.yearday = 0 result.timezone = getTimezone() + result.yearday = result.monthday - 1 + for month in mJan.. Date: Mon, 27 Mar 2017 21:14:02 +0400 Subject: [PATCH 2/3] Tests: Times: JS: Add test for yearday attribute. --- tests/js/ttimes.nim | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/js/ttimes.nim diff --git a/tests/js/ttimes.nim b/tests/js/ttimes.nim new file mode 100644 index 0000000000..a39ebe0b3b --- /dev/null +++ b/tests/js/ttimes.nim @@ -0,0 +1,13 @@ +# test times module with js +discard """ + action: run +""" + +import times + +# $ date --date='@2147483647' +# Tue 19 Jan 03:14:07 GMT 2038 + +block yeardayTest: + # check if yearday attribute is properly set on TimeInfo creation + doAssert fromSeconds(2147483647).getGMTime().yearday == 0 From 41e83f7a34f11ea09accaa7d8667ccbabeb0eccf Mon Sep 17 00:00:00 2001 From: Konstantin Molchanov Date: Mon, 27 Mar 2017 21:28:31 +0400 Subject: [PATCH 3/3] Tests: Times: JS: Fix test. --- tests/js/ttimes.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/js/ttimes.nim b/tests/js/ttimes.nim index a39ebe0b3b..644e9670af 100644 --- a/tests/js/ttimes.nim +++ b/tests/js/ttimes.nim @@ -10,4 +10,4 @@ import times block yeardayTest: # check if yearday attribute is properly set on TimeInfo creation - doAssert fromSeconds(2147483647).getGMTime().yearday == 0 + doAssert fromSeconds(2147483647).getGMTime().yearday == 18