mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-02 09:58:01 +00:00
Improve docs around subtracting times (#6152)
The output can be surprising - better provide examples.
This commit is contained in:
committed by
Andreas Rumpf
parent
0861249de7
commit
bad52ca29a
@@ -222,6 +222,12 @@ proc toSeconds*(time: Time): float {.tags: [], raises: [], benign.}
|
||||
proc `-`*(a, b: Time): int64 {.
|
||||
rtl, extern: "ntDiffTime", tags: [], raises: [], noSideEffect, benign.}
|
||||
## computes the difference of two calendar times. Result is in seconds.
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## let a = fromSeconds(1_000_000_000)
|
||||
## let b = fromSeconds(1_500_000_000)
|
||||
## echo initInterval(seconds=int(b - a))
|
||||
## # (milliseconds: 0, seconds: 20, minutes: 53, hours: 0, days: 5787, months: 0, years: 0)
|
||||
|
||||
proc `<`*(a, b: Time): bool {.
|
||||
rtl, extern: "ntLtTime", tags: [], raises: [], noSideEffect.} =
|
||||
@@ -318,6 +324,12 @@ proc `-`*(ti: TimeInterval): TimeInterval =
|
||||
|
||||
proc `-`*(ti1, ti2: TimeInterval): TimeInterval =
|
||||
## Subtracts TimeInterval ``ti1`` from ``ti2``.
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## let a = fromSeconds(1_000_000_000)
|
||||
## let b = fromSeconds(1_500_000_000)
|
||||
## echo b.toTimeInterval - a.toTimeInterval
|
||||
## # (milliseconds: 0, seconds: -40, minutes: -6, hours: 1, days: -2, months: -2, years: 16)
|
||||
result = ti1 + (-ti2)
|
||||
|
||||
proc isLeapYear*(year: int): bool =
|
||||
|
||||
Reference in New Issue
Block a user