Revert @endragor's fix for Windows
_mkgmtime is not supported by mingw because of the older msvcrt versions. Fortunately, mktime implementation in Windows is just broken enough to make the initial implementation work... As far as I can tell, this works with both *nix-like platforms and Win, and fixes #4690
This commit is contained in:
parent
50a1267b7d
commit
dc8ee72eb6
1 changed files with 16 additions and 14 deletions
|
|
@ -436,10 +436,8 @@ when not defined(JS):
|
||||||
TimeInfoPtr = ptr StructTM
|
TimeInfoPtr = ptr StructTM
|
||||||
Clock {.importc: "clock_t".} = distinct int
|
Clock {.importc: "clock_t".} = distinct int
|
||||||
|
|
||||||
when defined(windows):
|
when not defined(windows):
|
||||||
proc timegm(t: StructTM): Time {.
|
# This is not ANSI C, but common enough
|
||||||
importc: "_mkgmtime", header: "<time.h>", tags: [].}
|
|
||||||
else:
|
|
||||||
proc timegm(t: StructTM): Time {.
|
proc timegm(t: StructTM): Time {.
|
||||||
importc: "timegm", header: "<time.h>", tags: [].}
|
importc: "timegm", header: "<time.h>", tags: [].}
|
||||||
|
|
||||||
|
|
@ -522,18 +520,22 @@ when not defined(JS):
|
||||||
# the conversion is not expensive
|
# the conversion is not expensive
|
||||||
|
|
||||||
proc timeInfoToTime(timeInfo: TimeInfo): Time =
|
proc timeInfoToTime(timeInfo: TimeInfo): Time =
|
||||||
var cTimeInfo = timeInfo # for C++ we have to make a copy,
|
toTime(timeInfo)
|
||||||
# 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 =
|
proc toTime(timeInfo: TimeInfo): Time =
|
||||||
var cTimeInfo = timeInfo # for C++ we have to make a copy,
|
var cTimeInfo = timeInfo # for C++ we have to make a copy
|
||||||
# because the header of timegm is broken in my version of libc
|
# because the header of mktime is broken in my version of libc
|
||||||
result = timegm(timeInfoToTM(cTimeInfo))
|
|
||||||
# As timeInfoToTM does ignore the timezone, we need to adjust this here.
|
when defined(windows):
|
||||||
result = Time(TimeImpl(result) + timeInfo.timezone)
|
# On Windows `mktime` is broken enough to make this work.
|
||||||
|
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)
|
||||||
|
else:
|
||||||
|
result = timegm(timeInfoToTM(cTimeInfo))
|
||||||
|
# As timeInfoToTM does ignore the timezone, we need to adjust this here.
|
||||||
|
result = Time(TimeImpl(result) + timeInfo.timezone)
|
||||||
|
|
||||||
const
|
const
|
||||||
epochDiff = 116444736000000000'i64
|
epochDiff = 116444736000000000'i64
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue