diff options
author | Konstantin Molchanov <moigagoo@live.com> | 2017-03-27 00:14:48 +0400 |
---|---|---|
committer | Konstantin Molchanov <moigagoo@live.com> | 2017-03-27 00:14:48 +0400 |
commit | bef86f55ceefb1f2ea3fb95a1a5112530707bd46 (patch) | |
tree | 46b56a32b2fbef9023da2efd7c618a0c7fac63bc /lib/pure/times.nim | |
parent | d02486aa48e51b8db51baa762d6e87fe7eb91f04 (diff) | |
download | Nim-bef86f55ceefb1f2ea3fb95a1a5112530707bd46.tar.gz |
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.
Diffstat (limited to 'lib/pure/times.nim')
-rw-r--r-- | lib/pure/times.nim | 10 |
1 files changed, 8 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) |