@@ -595,26 +595,27 @@ proc toUnix*(t: Time): int64 {.benign, tags: [], raises: [], noSideEffect.} =
595
595
doAssert fromUnix(0).toUnix() == 0
596
596
t.seconds
597
597
598
- proc fromUnixFloat*(seconds: float ): Time
599
- {.benign, tags: [], raises: [], noSideEffect, since: (1, 1).} =
598
+ proc fromUnixFloat(seconds: float ): Time {.benign, tags: [], raises: [], noSideEffect.} =
600
599
## Convert a unix timestamp in seconds to a `Time`; same as `fromUnix`
601
600
## but with subsecond resolution.
602
601
runnableExamples:
603
- doAssert fromUnixFloat(123.0) == fromUnixFloat(123)
602
+ doAssert fromUnixFloat(123456.0) == fromUnixFloat(123456)
603
+ doAssert fromUnixFloat(-123456.0) == fromUnixFloat(-123456)
604
604
let secs = seconds.floor
605
605
let nsecs = (seconds - secs) * 1e9
606
606
initTime(secs.int64 , nsecs.NanosecondRange)
607
607
608
- template toUnixFloatImpl(t): untyped =
609
- t.seconds.float + t.nanosecond / convert(Seconds, Nanoseconds, 1)
610
-
611
- proc toUnixFloat*(t: Time): float {.benign, tags: [], raises: [], since: (1, 1).} =
608
+ proc toUnixFloat(t: Time): float {.benign, tags: [], raises: [].} =
612
609
## Same as `toUnix` but using subsecond resolution.
613
610
runnableExamples:
614
611
let t = getTime()
615
612
# `<` because of rounding errors
616
613
doAssert abs(t.toUnixFloat().fromUnixFloat - t) < initDuration(nanoseconds = 1000)
617
- toUnixFloatImpl(t)
614
+ t.seconds.float + t.nanosecond / convert(Seconds, Nanoseconds, 1)
615
+
616
+ since((1, 1)):
617
+ export fromUnixFloat
618
+ export toUnixFloat
618
619
619
620
proc fromWinTime*(win: int64 ): Time =
620
621
## Convert a Windows file time (100-nanosecond intervals since
@@ -2707,14 +2708,12 @@ proc initInterval*(seconds, minutes, hours, days, months, years: int = 0):
2707
2708
initTimeInterval(0 , 0 , 0 , seconds, minutes, hours, days, 0 , months, years)
2708
2709
2709
2710
proc fromSeconds* (since1970: float ): Time
2710
- {.tags: [], raises: [], benign, deprecated.} =
2711
+ {.tags: [], raises: [], benign, deprecated: " Use fromUnixFloat or fromUnix " .} =
2711
2712
# # Takes a float which contains the number of seconds since the unix epoch and
2712
2713
# # returns a time object.
2713
2714
# #
2714
2715
# # **Deprecated since v0.18.0:** use ``fromUnix`` instead
2715
- let nanos = ((since1970 - since1970.int64 .float ) *
2716
- convert(Seconds, Nanoseconds, 1 ).float ).int
2717
- initTime(since1970.int64 , nanos)
2716
+ fromUnixFloat(since1970)
2718
2717
2719
2718
proc fromSeconds* (since1970: int64 ): Time
2720
2719
{.tags: [], raises: [], benign, deprecated.} =
@@ -2727,7 +2726,7 @@ proc fromSeconds*(since1970: int64): Time
2727
2726
proc toSeconds* (time: Time): float
2728
2727
{.tags: [], raises: [], benign, deprecated: " Use toUnixFloat or toUnix" .} =
2729
2728
# # Returns the time in seconds since the unix epoch, with subsecond resolution.
2730
- toUnixFloatImpl (time)
2729
+ toUnixFloat (time)
2731
2730
2732
2731
proc getLocalTime* (time: Time): DateTime
2733
2732
{.tags: [], raises: [], benign, deprecated.} =
0 commit comments