summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@gmail.com>2016-06-18 16:11:27 +0100
committerDominik Picheta <dominikpicheta@gmail.com>2016-06-18 16:11:57 +0100
commit8182414a6f99c46dc31ba63e00fe1315981d2b50 (patch)
treea7d0b4790373ce3555101b16976dbc968083d7b3
parentf5bdc138bb57a6edd52dd6d977958f9951f83300 (diff)
downloadNim-8182414a6f99c46dc31ba63e00fe1315981d2b50.tar.gz
Fix times.`+` and `-` for TimeInfo and TimeInterval.
-rw-r--r--lib/pure/times.nim12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim
index ac8dc93ad..c0a121518 100644
--- a/lib/pure/times.nim
+++ b/lib/pure/times.nim
@@ -66,7 +66,7 @@ when defined(posix) and not defined(JS):
 
   when not defined(freebsd) and not defined(netbsd) and not defined(openbsd):
     var timezone {.importc, header: "<time.h>".}: int
-  var  
+  var
     tzname {.importc, header: "<time.h>" .}: array[0..1, cstring]
   # we also need tzset() to make sure that tzname is initialized
   proc tzset() {.importc, header: "<time.h>".}
@@ -369,7 +369,10 @@ proc `+`*(a: TimeInfo, interval: TimeInterval): TimeInfo =
   ## very accurate.
   let t = toSeconds(toTime(a))
   let secs = toSeconds(a, interval)
-  result = getLocalTime(fromSeconds(t + secs))
+  if a.tzname == "UTC":
+    result = getGMTime(fromSeconds(t + secs))
+  else:
+    result = getLocalTime(fromSeconds(t + secs))
 
 proc `-`*(a: TimeInfo, interval: TimeInterval): TimeInfo =
   ## subtracts ``interval`` time from TimeInfo ``a``.
@@ -386,7 +389,10 @@ proc `-`*(a: TimeInfo, interval: TimeInterval): TimeInfo =
   intval.months = - interval.months
   intval.years = - interval.years
   let secs = toSeconds(a, intval)
-  result = getLocalTime(fromSeconds(t + secs))
+  if a.tzname == "UTC":
+    result = getGMTime(fromSeconds(t + secs))
+  else:
+    result = getLocalTime(fromSeconds(t + secs))
 
 proc miliseconds*(t: TimeInterval): int {.deprecated.} = t.milliseconds