[change] Replace mutators with their more generic versions
This commit is contained in:
parent
6590ad6c6d
commit
b7a8eef87a
1 changed files with 22 additions and 37 deletions
|
|
@ -185,8 +185,7 @@ type
|
||||||
|
|
||||||
DurationParts* = array[FixedTimeUnit, int64] # Array of Duration parts starts
|
DurationParts* = array[FixedTimeUnit, int64] # Array of Duration parts starts
|
||||||
TimeIntervalParts* = array[TimeUnit, int] # Array of Duration parts starts
|
TimeIntervalParts* = array[TimeUnit, int] # Array of Duration parts starts
|
||||||
|
TimesMutableTypes = DateTime | Time | Duration | TimeInterval
|
||||||
|
|
||||||
|
|
||||||
{.deprecated: [TMonth: Month, TWeekDay: WeekDay, TTime: Time,
|
{.deprecated: [TMonth: Month, TWeekDay: WeekDay, TTime: Time,
|
||||||
TTimeInterval: TimeInterval, TTimeInfo: DateTime, TimeInfo: DateTime].}
|
TTimeInterval: TimeInterval, TTimeInfo: DateTime, TimeInfo: DateTime].}
|
||||||
|
|
@ -607,30 +606,12 @@ proc `+`*(a: Time, b: Duration): Time {.operator, extern: "ntAddTime".} =
|
||||||
doAssert (fromUnix(0) + initDuration(seconds = 1)) == fromUnix(1)
|
doAssert (fromUnix(0) + initDuration(seconds = 1)) == fromUnix(1)
|
||||||
addImpl[Time](a, b)
|
addImpl[Time](a, b)
|
||||||
|
|
||||||
proc `+=`*(a: var Time, b: Duration) {.operator.} =
|
|
||||||
## Modify ``a`` in place by subtracting ``b``.
|
|
||||||
runnableExamples:
|
|
||||||
var tm = fromUnix(0)
|
|
||||||
tm += initDuration(seconds = 1)
|
|
||||||
doAssert tm == fromUnix(1)
|
|
||||||
|
|
||||||
a = addImpl[Time](a, b)
|
|
||||||
|
|
||||||
proc `-`*(a: Time, b: Duration): Time {.operator, extern: "ntSubTime".} =
|
proc `-`*(a: Time, b: Duration): Time {.operator, extern: "ntSubTime".} =
|
||||||
## Subtracts a duration of time from a ``Time``.
|
## Subtracts a duration of time from a ``Time``.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
doAssert (fromUnix(0) - initDuration(seconds = 1)) == fromUnix(-1)
|
doAssert (fromUnix(0) - initDuration(seconds = 1)) == fromUnix(-1)
|
||||||
subImpl[Time](a, b)
|
subImpl[Time](a, b)
|
||||||
|
|
||||||
proc `-=`*(a: var Time, b: Duration) {.operator.} =
|
|
||||||
## Modify ``a`` in place by adding ``b``.
|
|
||||||
runnableExamples:
|
|
||||||
var tm = fromUnix(0)
|
|
||||||
tm -= initDuration(seconds = 1)
|
|
||||||
doAssert tm == fromUnix(-1)
|
|
||||||
|
|
||||||
a = subImpl[Time](a, b)
|
|
||||||
|
|
||||||
proc `<`*(a, b: Time): bool {.operator, extern: "ntLtTime".} =
|
proc `<`*(a, b: Time): bool {.operator, extern: "ntLtTime".} =
|
||||||
## Returns true iff ``a < b``, that is iff a happened before b.
|
## Returns true iff ``a < b``, that is iff a happened before b.
|
||||||
ltImpl(a, b)
|
ltImpl(a, b)
|
||||||
|
|
@ -1377,17 +1358,6 @@ proc `+`*(time: Time, interval: TimeInterval): Time =
|
||||||
else:
|
else:
|
||||||
toTime(time.local + interval)
|
toTime(time.local + interval)
|
||||||
|
|
||||||
proc `+=`*(time: var Time, interval: TimeInterval) =
|
|
||||||
## Modifies `time` by adding `interval`.
|
|
||||||
## If `interval` contains any years, months, weeks or days the operation
|
|
||||||
## is performed in the local timezone.
|
|
||||||
runnableExamples:
|
|
||||||
var tm = fromUnix(0)
|
|
||||||
tm += 5.seconds
|
|
||||||
doAssert tm == fromUnix(5)
|
|
||||||
|
|
||||||
time = time + interval
|
|
||||||
|
|
||||||
proc `-`*(time: Time, interval: TimeInterval): Time =
|
proc `-`*(time: Time, interval: TimeInterval): Time =
|
||||||
## Subtracts `interval` from Time `time`.
|
## Subtracts `interval` from Time `time`.
|
||||||
## If `interval` contains any years, months, weeks or days the operation
|
## If `interval` contains any years, months, weeks or days the operation
|
||||||
|
|
@ -1401,15 +1371,30 @@ proc `-`*(time: Time, interval: TimeInterval): Time =
|
||||||
else:
|
else:
|
||||||
toTime(time.local - interval)
|
toTime(time.local - interval)
|
||||||
|
|
||||||
proc `-=`*(time: var Time, interval: TimeInterval) =
|
proc `+=`*[T, U: TimesMutableTypes](a: var T, b: U) =
|
||||||
## Modifies `time` by subtracting `interval`.
|
## Modify ``a`` in place by adding ``b``.
|
||||||
## If `interval` contains any years, months, weeks or days the operation
|
runnableExamples:
|
||||||
## is performed in the local timezone.
|
var tm = fromUnix(0)
|
||||||
|
tm += initDuration(seconds = 1)
|
||||||
|
doAssert tm == fromUnix(1)
|
||||||
|
a = a + b
|
||||||
|
|
||||||
|
proc `-=`*[T, U: TimesMutableTypes](a: var T, b: U) =
|
||||||
|
## Modify ``a`` in place by subtracting ``b``.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
var tm = fromUnix(5)
|
var tm = fromUnix(5)
|
||||||
tm -= 5.seconds
|
tm -= initDuration(seconds = 5)
|
||||||
doAssert tm == fromUnix(0)
|
doAssert tm == fromUnix(0)
|
||||||
time = time - interval
|
a = a - b
|
||||||
|
|
||||||
|
proc `*=`*[T: TimesMutableTypes, U](a: var T, b: U) =
|
||||||
|
# Mutable type is often multiplied by number
|
||||||
|
runnableExamples:
|
||||||
|
var dur = initDuration(seconds = 1)
|
||||||
|
dur *= 5
|
||||||
|
doAssert dur == initDuration(seconds = 5)
|
||||||
|
|
||||||
|
a = a * b
|
||||||
|
|
||||||
proc formatToken(dt: DateTime, token: string, buf: var string) =
|
proc formatToken(dt: DateTime, token: string, buf: var string) =
|
||||||
## Helper of the format proc to parse individual tokens.
|
## Helper of the format proc to parse individual tokens.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue