summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorFederico Ceratto <federico.ceratto@suse.com>2017-09-03 00:01:06 +0100
committerAndreas Rumpf <rumpf_a@web.de>2017-09-03 01:01:06 +0200
commitbad52ca29aa958d51ab1c121f7c4c5fef8b49043 (patch)
tree4a645dd908c16b2cfdc130053e82a1843465dd1e /lib/pure
parent0861249de75adabc5d9761c77f7f057644014fd2 (diff)
downloadNim-bad52ca29aa958d51ab1c121f7c4c5fef8b49043.tar.gz
Improve docs around subtracting times (#6152)
The output can be surprising - better provide examples.
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/times.nim12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/pure/times.nim b/lib/pure/times.nim
index c2809acf7..03054e2d9 100644
--- a/lib/pure/times.nim
+++ b/lib/pure/times.nim
@@ -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 =