Change inconsistent paramaters in times.nim (#8091)
This commit is contained in:
parent
0c683d28bb
commit
371f87e962
1 changed files with 19 additions and 28 deletions
|
|
@ -1243,7 +1243,7 @@ proc evaluateStaticInterval(interval: TimeInterval): Duration =
|
|||
minutes = interval.minutes,
|
||||
hours = interval.hours)
|
||||
|
||||
proc between*(startDt, endDt:DateTime): TimeInterval =
|
||||
proc between*(startDt, endDt: DateTime): TimeInterval =
|
||||
## Evaluate difference between two dates in ``TimeInterval`` format, so, it
|
||||
## will be relative.
|
||||
##
|
||||
|
|
@ -1526,7 +1526,6 @@ proc formatToken(dt: DateTime, token: string, buf: var string) =
|
|||
else:
|
||||
raise newException(ValueError, "Invalid format string: " & token)
|
||||
|
||||
|
||||
proc format*(dt: DateTime, f: string): string {.tags: [].}=
|
||||
## This procedure formats `dt` as specified by `f`. The following format
|
||||
## specifiers are available:
|
||||
|
|
@ -1601,18 +1600,14 @@ proc format*(dt: DateTime, f: string): string {.tags: [].}=
|
|||
inc(i)
|
||||
formatToken(dt, currentF, result)
|
||||
|
||||
proc format*(time: Time, f: string, zone_info: proc(t: Time): DateTime): string {.tags: [].} =
|
||||
## converts a `Time` value to a string representation. It will use format from
|
||||
proc format*(time: Time, f: string, zone: Timezone = local()): string {.tags: [].} =
|
||||
## Converts a `Time` value to a string representation. It will use format from
|
||||
## ``format(dt: DateTime, f: string)``.
|
||||
runnableExamples:
|
||||
var dt = initDateTime(01, mJan, 1970, 00, 00, 00, local())
|
||||
var dt = initDateTime(01, mJan, 1970, 00, 00, 00, utc())
|
||||
var tm = dt.toTime()
|
||||
doAssert format(tm, "yyyy-MM-dd'T'HH:mm:ss", local) == "1970-01-01T00:00:00"
|
||||
dt = initDateTime(01, mJan, 1970, 00, 00, 00, utc())
|
||||
tm = dt.toTime()
|
||||
doAssert format(tm, "yyyy-MM-dd'T'HH:mm:ss", utc) == "1970-01-01T00:00:00"
|
||||
|
||||
zone_info(time).format(f)
|
||||
doAssert format(tm, "yyyy-MM-dd'T'HH:mm:ss", utc()) == "1970-01-01T00:00:00"
|
||||
time.inZone(zone).format(f)
|
||||
|
||||
proc `$`*(dt: DateTime): string {.tags: [], raises: [], benign.} =
|
||||
## Converts a `DateTime` object to a string representation.
|
||||
|
|
@ -1984,16 +1979,12 @@ proc countYearsAndDays*(daySpan: int): tuple[years: int, days: int] =
|
|||
proc toTimeInterval*(time: Time): TimeInterval =
|
||||
## Converts a Time to a TimeInterval.
|
||||
##
|
||||
## To be used when diffing times.
|
||||
## To be used when diffing times. Consider using `between` instead.
|
||||
runnableExamples:
|
||||
let a = fromUnix(10)
|
||||
let dt = initDateTime(01, mJan, 1970, 00, 00, 00, local())
|
||||
doAssert a.toTimeInterval() == initTimeInterval(
|
||||
years=1970, days=1, seconds=10, hours=convert(
|
||||
Seconds, Hours, -dt.utcOffset
|
||||
)
|
||||
)
|
||||
|
||||
let b = fromUnix(1_500_000_000)
|
||||
let ti = b.toTimeInterval() - a.toTimeInterval()
|
||||
doAssert a + ti == b
|
||||
var dt = time.local
|
||||
initTimeInterval(dt.nanosecond, 0, 0, dt.second, dt.minute, dt.hour,
|
||||
dt.monthday, 0, dt.month.ord - 1, dt.year)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue