diff options
author | Ruslan Mustakov <r.mustakov@gmail.com> | 2016-11-30 20:28:17 +0700 |
---|---|---|
committer | Ruslan Mustakov <r.mustakov@gmail.com> | 2016-11-30 20:28:17 +0700 |
commit | 50a1267b7d028f18df39523fd90399f0751180a4 (patch) | |
tree | d128f84ec809617d8c10540e19586b79d9b47061 /lib | |
parent | b1b2dd606ba736775868853657e331f287423dee (diff) | |
download | Nim-50a1267b7d028f18df39523fd90399f0751180a4.tar.gz |
Fix TimeInfo to Time conversion. Fixes #5065.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/times.nim | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim index 1767a37be..e5b4f383f 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -436,6 +436,13 @@ when not defined(JS): TimeInfoPtr = ptr StructTM Clock {.importc: "clock_t".} = distinct int + when defined(windows): + proc timegm(t: StructTM): Time {. + importc: "_mkgmtime", header: "<time.h>", tags: [].} + else: + proc timegm(t: StructTM): Time {. + importc: "timegm", header: "<time.h>", tags: [].} + proc localtime(timer: ptr Time): TimeInfoPtr {. importc: "localtime", header: "<time.h>", tags: [].} proc gmtime(timer: ptr Time): TimeInfoPtr {. @@ -516,19 +523,17 @@ when not defined(JS): proc timeInfoToTime(timeInfo: TimeInfo): Time = var cTimeInfo = timeInfo # for C++ we have to make a copy, - # because the header of mktime is broken in my version of libc - result = mktime(timeInfoToTM(cTimeInfo)) - # mktime is defined to interpret the input as local time. As timeInfoToTM - # does ignore the timezone, we need to adjust this here. - result = Time(TimeImpl(result) - getTimezone() + timeInfo.timezone) + # because the header of timegm is broken in my version of libc + result = timegm(timeInfoToTM(cTimeInfo)) + # As timeInfoToTM does ignore the timezone, we need to adjust this here. + result = Time(TimeImpl(result) + timeInfo.timezone) proc toTime(timeInfo: TimeInfo): Time = var cTimeInfo = timeInfo # for C++ we have to make a copy, - # because the header of mktime is broken in my version of libc - result = mktime(timeInfoToTM(cTimeInfo)) - # mktime is defined to interpret the input as local time. As timeInfoToTM - # does ignore the timezone, we need to adjust this here. - result = Time(TimeImpl(result) - getTimezone() + timeInfo.timezone) + # because the header of timegm is broken in my version of libc + result = timegm(timeInfoToTM(cTimeInfo)) + # As timeInfoToTM does ignore the timezone, we need to adjust this here. + result = Time(TimeImpl(result) + timeInfo.timezone) const epochDiff = 116444736000000000'i64 |