diff options
Diffstat (limited to 'lib/pure/times.nim')
-rw-r--r-- | lib/pure/times.nim | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim index b78a2b966..efc1dfa92 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -266,13 +266,13 @@ proc initInterval*(milliseconds, seconds, minutes, hours, days, months, result.milliseconds = `mod`(milliseconds, 1000) carryO = `div`(milliseconds, 1000) result.seconds = `mod`(carryO + seconds, 60) - carryO = `div`(seconds, 60) + carryO = `div`(carryO + seconds, 60) result.minutes = `mod`(carryO + minutes, 60) - carryO = `div`(minutes, 60) + carryO = `div`(carryO + minutes, 60) result.hours = `mod`(carryO + hours, 24) - carryO = `div`(hours, 24) + carryO = `div`(carryO + hours, 24) result.days = carryO + days - carryO = 0 + result.months = `mod`(months, 12) carryO = `div`(months, 12) result.years = carryO + years @@ -283,13 +283,13 @@ proc `+`*(ti1, ti2: TimeInterval): TimeInterval = result.milliseconds = `mod`(ti1.milliseconds + ti2.milliseconds, 1000) carryO = `div`(ti1.milliseconds + ti2.milliseconds, 1000) result.seconds = `mod`(carryO + ti1.seconds + ti2.seconds, 60) - carryO = `div`(ti1.seconds + ti2.seconds, 60) + carryO = `div`(carryO + ti1.seconds + ti2.seconds, 60) result.minutes = `mod`(carryO + ti1.minutes + ti2.minutes, 60) - carryO = `div`(ti1.minutes + ti2.minutes, 60) + carryO = `div`(carryO + ti1.minutes + ti2.minutes, 60) result.hours = `mod`(carryO + ti1.hours + ti2.hours, 24) - carryO = `div`(ti1.hours + ti2.hours, 24) + carryO = `div`(carryO + ti1.hours + ti2.hours, 24) result.days = carryO + ti1.days + ti2.days - carryO = 0 + result.months = `mod`(ti1.months + ti2.months, 12) carryO = `div`(ti1.months + ti2.months, 12) result.years = carryO + ti1.years + ti2.years @@ -1248,12 +1248,18 @@ proc parse*(value, layout: string): TimeInfo = else: parseToken(info, token, value, j) token = "" - # Reset weekday (might not have been provided and the default may be wrong) - # and yearday (is never provided directly and therefore probably wrong) - let processed = getLocalTime(toTime(info)) - info.weekday = processed.weekday - info.yearday = processed.yearday - return info + + # We are going to process the date to find out if we are in DST, because the + # default based on the current time may be wrong. Calling getLocalTime will + # set this correctly, but the actual time may be offset from when we called + # toTime with a possibly incorrect DST setting, so we are only going to take + # the isDST from this result. + let correctDST = getLocalTime(toTime(info)) + info.isDST = correctDST.isDST + + # Now we preocess it again with the correct isDST to correct things like + # weekday and yearday. + return getLocalTime(toTime(info)) # Leap year calculations are adapted from: # http://www.codeproject.com/Articles/7358/Ultra-fast-Algorithms-for-Working-with-Leap-Years |