Merge pull request #3213 from yglukhov/times-js-fix
Fixed compilation of times module with JS.
This commit is contained in:
commit
bb2aa24c99
1 changed files with 18 additions and 16 deletions
|
|
@ -548,11 +548,9 @@ elif defined(JS):
|
||||||
## get the milliseconds from the start of the program
|
## get the milliseconds from the start of the program
|
||||||
return int(getTime() - startMilsecs)
|
return int(getTime() - startMilsecs)
|
||||||
|
|
||||||
proc valueOf(time: Time): float {.importcpp: "getTime", tags:[]}
|
|
||||||
|
|
||||||
proc fromSeconds(since1970: float): Time = result = newDate(since1970 * 1000)
|
proc fromSeconds(since1970: float): Time = result = newDate(since1970 * 1000)
|
||||||
|
|
||||||
proc toSeconds(time: Time): float = result = time.valueOf() / 1000
|
proc toSeconds(time: Time): float = result = time.getTime() / 1000
|
||||||
|
|
||||||
proc getTimezone(): int = result = newDate().getTimezoneOffset()
|
proc getTimezone(): int = result = newDate().getTimezoneOffset()
|
||||||
|
|
||||||
|
|
@ -1109,9 +1107,10 @@ proc getDayOfWeekJulian*(day, month, year: int): WeekDay =
|
||||||
proc timeToTimeInfo*(t: Time): TimeInfo =
|
proc timeToTimeInfo*(t: Time): TimeInfo =
|
||||||
## Converts a Time to TimeInfo.
|
## Converts a Time to TimeInfo.
|
||||||
let
|
let
|
||||||
daysSinceEpoch = t.int div secondsInDay
|
secs = t.toSeconds().int
|
||||||
|
daysSinceEpoch = secs div secondsInDay
|
||||||
(yearsSinceEpoch, daysRemaining) = countYearsAndDays(daysSinceEpoch)
|
(yearsSinceEpoch, daysRemaining) = countYearsAndDays(daysSinceEpoch)
|
||||||
daySeconds = t.int mod secondsInDay
|
daySeconds = secs mod secondsInDay
|
||||||
|
|
||||||
y = yearsSinceEpoch + epochStartYear
|
y = yearsSinceEpoch + epochStartYear
|
||||||
|
|
||||||
|
|
@ -1137,12 +1136,14 @@ proc timeToTimeInfo*(t: Time): TimeInfo =
|
||||||
s = daySeconds mod secondsInMin
|
s = daySeconds mod secondsInMin
|
||||||
result = TimeInfo(year: y, yearday: yd, month: m, monthday: md, weekday: wd, hour: h, minute: mi, second: s)
|
result = TimeInfo(year: y, yearday: yd, month: m, monthday: md, weekday: wd, hour: h, minute: mi, second: s)
|
||||||
|
|
||||||
proc timetoTimeInterval*(t: Time): TimeInterval =
|
proc timeToTimeInterval*(t: Time): TimeInterval =
|
||||||
## Converts a Time to a TimeInterval.
|
## Converts a Time to a TimeInterval.
|
||||||
var
|
|
||||||
daysSinceEpoch = t.int div secondsInDay
|
let
|
||||||
|
secs = t.toSeconds().int
|
||||||
|
daysSinceEpoch = secs div secondsInDay
|
||||||
(yearsSinceEpoch, daysRemaining) = countYearsAndDays(daysSinceEpoch)
|
(yearsSinceEpoch, daysRemaining) = countYearsAndDays(daysSinceEpoch)
|
||||||
daySeconds = t.int mod secondsInDay
|
daySeconds = secs mod secondsInDay
|
||||||
|
|
||||||
result.years = yearsSinceEpoch + epochStartYear
|
result.years = yearsSinceEpoch + epochStartYear
|
||||||
|
|
||||||
|
|
@ -1183,12 +1184,13 @@ when isMainModule:
|
||||||
" ss t tt y yy yyy yyyy yyyyy z zz zzz ZZZ") ==
|
" ss t tt y yy yyy yyyy yyyyy z zz zzz ZZZ") ==
|
||||||
"27 27 Mon Monday 4 04 16 16 6 06 1 01 Jan January 29 29 P PM 5 75 975 1975 01975 0 00 00:00 UTC"
|
"27 27 Mon Monday 4 04 16 16 6 06 1 01 Jan January 29 29 P PM 5 75 975 1975 01975 0 00 00:00 UTC"
|
||||||
|
|
||||||
when not defined(JS) and sizeof(Time) == 8:
|
when not defined(JS):
|
||||||
var t3 = getGMTime(fromSeconds(889067643645)) # Fri 7 Jun 19:20:45 BST 30143
|
when sizeof(Time) == 8:
|
||||||
assert t3.format("d dd ddd dddd h hh H HH m mm M MM MMM MMMM s" &
|
var t3 = getGMTime(fromSeconds(889067643645)) # Fri 7 Jun 19:20:45 BST 30143
|
||||||
" ss t tt y yy yyy yyyy yyyyy z zz zzz ZZZ") ==
|
assert t3.format("d dd ddd dddd h hh H HH m mm M MM MMM MMMM s" &
|
||||||
"7 07 Fri Friday 6 06 18 18 20 20 6 06 Jun June 45 45 P PM 3 43 143 0143 30143 0 00 00:00 UTC"
|
" ss t tt y yy yyy yyyy yyyyy z zz zzz ZZZ") ==
|
||||||
assert t3.format(":,[]()-/") == ":,[]()-/"
|
"7 07 Fri Friday 6 06 18 18 20 20 6 06 Jun June 45 45 P PM 3 43 143 0143 30143 0 00 00:00 UTC"
|
||||||
|
assert t3.format(":,[]()-/") == ":,[]()-/"
|
||||||
|
|
||||||
var t4 = getGMTime(fromSeconds(876124714)) # Mon 6 Oct 08:58:34 BST 1997
|
var t4 = getGMTime(fromSeconds(876124714)) # Mon 6 Oct 08:58:34 BST 1997
|
||||||
assert t4.format("M MM MMM MMMM") == "10 10 Oct October"
|
assert t4.format("M MM MMM MMMM") == "10 10 Oct October"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue