summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorOscar NihlgÄrd <oscarnihlgard@gmail.com>2018-08-23 17:55:53 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-08-23 20:35:22 +0200
commit8aae5c9385c5273c4339a242222a14afead19f2f (patch)
treedb97d4aca104601ac637955fbf8256961c5e4c5a /lib
parent1b1633991a738f100101407ffd1b16a08362814b (diff)
downloadNim-8aae5c9385c5273c4339a242222a14afead19f2f.tar.gz
Don't assume utcOffset == +0 for old dates on Windows (#8744)
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/times.nim11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim
index 6251c70d9..9f6ea5722 100644
--- a/lib/pure/times.nim
+++ b/lib/pure/times.nim
@@ -957,6 +957,17 @@ else:
     result.inc tm.second
 
   proc getLocalOffsetAndDst(unix: int64): tuple[offset: int, dst: bool] =
+    # Windows can't handle unix < 0, so we fall back to unix = 0.
+    # FIXME: This should be improved by falling back to the WinAPI instead.
+    when defined(windows):
+      if unix < 0:
+        var a = 0.CTime
+        let tmPtr = localtime(addr(a))
+        if not tmPtr.isNil:
+          let tm = tmPtr[]
+          return ((0 - tm.toAdjUnix).int, false)
+        return (0, false)
+
     var a = unix.CTime
     let tmPtr = localtime(addr(a))
     if not tmPtr.isNil: