Skip to content

Commit

Permalink
Times: JS: Add yearday to TimeInfo.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
moigagoo committed Mar 26, 2017
1 parent d02486a commit bef86f5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/pure/times.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand Down

0 comments on commit bef86f5

Please sign in to comment.