* [docs minor] close #17618 * Update lib/pure/times.nim Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
This commit is contained in:
parent
9abd383a2a
commit
07991d902e
1 changed files with 12 additions and 9 deletions
|
|
@ -313,8 +313,11 @@ type
|
||||||
Duration* = object ## Represents a fixed duration of time, meaning a duration
|
Duration* = object ## Represents a fixed duration of time, meaning a duration
|
||||||
## that has constant length independent of the context.
|
## that has constant length independent of the context.
|
||||||
##
|
##
|
||||||
## To create a new `Duration`, use `initDuration proc
|
## To create a new `Duration`, use `initDuration
|
||||||
## <#initDuration,int64,int64,int64,int64,int64,int64,int64,int64>`_.
|
## <#initDuration,int64,int64,int64,int64,int64,int64,int64,int64>`_.
|
||||||
|
## Instead of trying to access the private attributes, use
|
||||||
|
## `inSeconds <#inSeconds,Duration>`_ for converting to seconds and
|
||||||
|
## `inNanoseconds <#inNanoseconds,Duration>`_ for converting to nanoseconds.
|
||||||
seconds: int64
|
seconds: int64
|
||||||
nanosecond: NanosecondRange
|
nanosecond: NanosecondRange
|
||||||
|
|
||||||
|
|
@ -622,56 +625,56 @@ template convert(dur: Duration, unit: static[FixedTimeUnit]): int64 =
|
||||||
convert(Nanoseconds, unit, dur.nanosecond)
|
convert(Nanoseconds, unit, dur.nanosecond)
|
||||||
|
|
||||||
proc inWeeks*(dur: Duration): int64 =
|
proc inWeeks*(dur: Duration): int64 =
|
||||||
## Convert the duration to the number of whole weeks.
|
## Converts the duration to the number of whole weeks.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let dur = initDuration(days = 8)
|
let dur = initDuration(days = 8)
|
||||||
doAssert dur.inWeeks == 1
|
doAssert dur.inWeeks == 1
|
||||||
dur.convert(Weeks)
|
dur.convert(Weeks)
|
||||||
|
|
||||||
proc inDays*(dur: Duration): int64 =
|
proc inDays*(dur: Duration): int64 =
|
||||||
## Convert the duration to the number of whole days.
|
## Converts the duration to the number of whole days.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let dur = initDuration(hours = -50)
|
let dur = initDuration(hours = -50)
|
||||||
doAssert dur.inDays == -2
|
doAssert dur.inDays == -2
|
||||||
dur.convert(Days)
|
dur.convert(Days)
|
||||||
|
|
||||||
proc inHours*(dur: Duration): int64 =
|
proc inHours*(dur: Duration): int64 =
|
||||||
## Convert the duration to the number of whole hours.
|
## Converts the duration to the number of whole hours.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let dur = initDuration(minutes = 60, days = 2)
|
let dur = initDuration(minutes = 60, days = 2)
|
||||||
doAssert dur.inHours == 49
|
doAssert dur.inHours == 49
|
||||||
dur.convert(Hours)
|
dur.convert(Hours)
|
||||||
|
|
||||||
proc inMinutes*(dur: Duration): int64 =
|
proc inMinutes*(dur: Duration): int64 =
|
||||||
## Convert the duration to the number of whole minutes.
|
## Converts the duration to the number of whole minutes.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let dur = initDuration(hours = 2, seconds = 10)
|
let dur = initDuration(hours = 2, seconds = 10)
|
||||||
doAssert dur.inMinutes == 120
|
doAssert dur.inMinutes == 120
|
||||||
dur.convert(Minutes)
|
dur.convert(Minutes)
|
||||||
|
|
||||||
proc inSeconds*(dur: Duration): int64 =
|
proc inSeconds*(dur: Duration): int64 =
|
||||||
## Convert the duration to the number of whole seconds.
|
## Converts the duration to the number of whole seconds.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let dur = initDuration(hours = 2, milliseconds = 10)
|
let dur = initDuration(hours = 2, milliseconds = 10)
|
||||||
doAssert dur.inSeconds == 2 * 60 * 60
|
doAssert dur.inSeconds == 2 * 60 * 60
|
||||||
dur.convert(Seconds)
|
dur.convert(Seconds)
|
||||||
|
|
||||||
proc inMilliseconds*(dur: Duration): int64 =
|
proc inMilliseconds*(dur: Duration): int64 =
|
||||||
## Convert the duration to the number of whole milliseconds.
|
## Converts the duration to the number of whole milliseconds.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let dur = initDuration(seconds = -2)
|
let dur = initDuration(seconds = -2)
|
||||||
doAssert dur.inMilliseconds == -2000
|
doAssert dur.inMilliseconds == -2000
|
||||||
dur.convert(Milliseconds)
|
dur.convert(Milliseconds)
|
||||||
|
|
||||||
proc inMicroseconds*(dur: Duration): int64 =
|
proc inMicroseconds*(dur: Duration): int64 =
|
||||||
## Convert the duration to the number of whole microseconds.
|
## Converts the duration to the number of whole microseconds.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let dur = initDuration(seconds = -2)
|
let dur = initDuration(seconds = -2)
|
||||||
doAssert dur.inMicroseconds == -2000000
|
doAssert dur.inMicroseconds == -2000000
|
||||||
dur.convert(Microseconds)
|
dur.convert(Microseconds)
|
||||||
|
|
||||||
proc inNanoseconds*(dur: Duration): int64 =
|
proc inNanoseconds*(dur: Duration): int64 =
|
||||||
## Convert the duration to the number of whole nanoseconds.
|
## Converts the duration to the number of whole nanoseconds.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let dur = initDuration(seconds = -2)
|
let dur = initDuration(seconds = -2)
|
||||||
doAssert dur.inNanoseconds == -2000000000
|
doAssert dur.inNanoseconds == -2000000000
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue