mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-31 18:32:11 +00:00
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user