diff options
author | Oscar NihlgÄrd <oscarnihlgard@gmail.com> | 2018-08-22 17:20:41 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-08-22 17:20:41 +0200 |
commit | 1d93991929e7691fdd7218a0d9638d420a0f2492 (patch) | |
tree | 451b6e6f52eef52782e74680710f8a1eb2857c25 /lib/pure | |
parent | 7dcf435b4bf5e0de37b04d8062dd74177eedd7e8 (diff) | |
download | Nim-1d93991929e7691fdd7218a0d9638d420a0f2492.tar.gz |
Cleanup ttimes (#8714)
* Refactor fromWinTime * Cleanup ttimes
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/times.nim | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim index cbf3e6413..6251c70d9 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -423,18 +423,14 @@ proc toUnix*(t: Time): int64 {.benign, tags: [], raises: [], noSideEffect.} = ## Convert ``t`` to a unix timestamp (seconds since ``1970-01-01T00:00:00Z``). runnableExamples: doAssert fromUnix(0).toUnix() == 0 - t.seconds proc fromWinTime*(win: int64): Time = ## Convert a Windows file time (100-nanosecond intervals since ``1601-01-01T00:00:00Z``) ## to a ``Time``. - let hnsecsSinceEpoch = (win - epochDiff) - var seconds = hnsecsSinceEpoch div rateDiff - var nanos = ((hnsecsSinceEpoch mod rateDiff) * 100).int - if nanos < 0: - nanos += convert(Seconds, Nanoseconds, 1) - seconds -= 1 + const hnsecsPerSec = convert(Seconds, Nanoseconds, 1) div 100 + let nanos = floorMod(win, hnsecsPerSec) * 100 + let seconds = floorDiv(win - epochDiff, hnsecsPerSec) result = initTime(seconds, nanos) proc toWinTime*(t: Time): int64 = |