bug fix: + and - handle GM and Local time correctly

eg,  getGmTime(getTime()) + initInterval(hours=1) gave incorrect results
This commit is contained in:
JamesP 2015-09-10 17:38:00 +10:00
commit c122d71e66

View file

@ -307,9 +307,9 @@ proc `+`*(a: TimeInfo, interval: TimeInterval): TimeInfo =
## very accurate. ## very accurate.
let t = toSeconds(timeInfoToTime(a)) let t = toSeconds(timeInfoToTime(a))
let secs = toSeconds(a, interval) let secs = toSeconds(a, interval)
if a.tzname == "UTC": #if a.tzname == "UTC":
result = getGMTime(fromSeconds(t + secs)) # result = getGMTime(fromSeconds(t + secs))
else: #else:
result = getLocalTime(fromSeconds(t + secs)) result = getLocalTime(fromSeconds(t + secs))
proc `-`*(a: TimeInfo, interval: TimeInterval): TimeInfo = proc `-`*(a: TimeInfo, interval: TimeInterval): TimeInfo =
@ -319,9 +319,9 @@ proc `-`*(a: TimeInfo, interval: TimeInterval): TimeInfo =
## when you subtract so much that you reach the Julian calendar. ## when you subtract so much that you reach the Julian calendar.
let t = toSeconds(timeInfoToTime(a)) let t = toSeconds(timeInfoToTime(a))
let secs = toSeconds(a, interval) let secs = toSeconds(a, interval)
if a.tzname == "UTC": #if a.tzname == "UTC":
result = getGMTime(fromSeconds(t - secs)) # result = getGMTime(fromSeconds(t - secs))
else: #else:
result = getLocalTime(fromSeconds(t - secs)) result = getLocalTime(fromSeconds(t - secs))
when not defined(JS): when not defined(JS):