From 42333d27d0165e0e28e39ee7b409e0ae301e241f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Nihlg=C3=A5rd?= Date: Thu, 23 Aug 2018 17:55:53 +0200 Subject: [PATCH] Don't assume utcOffset == +0 for old dates on Windows (#8744) --- lib/pure/times.nim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/pure/times.nim b/lib/pure/times.nim index 6251c70d91..9f6ea5722b 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: