summary refs log tree commit diff stats
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 17:55:53 +0200
commit42333d27d0165e0e28e39ee7b409e0ae301e241f (patch)
treefe15ea716e59586e0311843f97e75f772f06c987
parent7532b37405c9365f3f2935633111f309234297b2 (diff)
downloadNim-42333d27d0165e0e28e39ee7b409e0ae301e241f.tar.gz
Don't assume utcOffset == +0 for old dates on Windows (#8744)
-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: