summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/pure/times.nim10
-rw-r--r--tests/js/ttimes.nim13
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim
index fe35c404c..2b7c22145 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..<result.month:
+      result.yearday += getDaysInMonth(month, result.year)
+
   proc getGMTime(t: Time): TimeInfo =
     result.second = t.getUTCSeconds()
     result.minute = t.getUTCMinutes()
@@ -608,7 +611,10 @@ elif defined(JS):
     result.month = Month(t.getUTCMonth())
     result.year = t.getUTCFullYear()
     result.weekday = weekDays[t.getUTCDay()]
-    result.yearday = 0
+
+    result.yearday = result.monthday - 1
+    for month in mJan..<result.month:
+      result.yearday += getDaysInMonth(month, result.year)
 
   proc timeInfoToTime(timeInfo: TimeInfo): Time = toTime(timeInfo)
 
diff --git a/tests/js/ttimes.nim b/tests/js/ttimes.nim
new file mode 100644
index 000000000..644e9670a
--- /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 == 18