Merge branch 'calculate_yearday_in_timeinfo_js' into fix_time_offset_in_times_js

This commit is contained in:
Konstantin Molchanov
2017-03-27 21:38:19 +04:00
2 changed files with 21 additions and 2 deletions

View File

@@ -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)

13
tests/js/ttimes.nim Normal file
View File

@@ -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