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
|
|
@ -238,11 +238,11 @@ proc utcZoneInfoFromUtc(time: Time): ZonedTime {.tags: [], raises: [], benign .}
|
||||||
proc utcZoneInfoFromTz(adjTime: Time): ZonedTime {.tags: [], raises: [], benign .}
|
proc utcZoneInfoFromTz(adjTime: Time): ZonedTime {.tags: [], raises: [], benign .}
|
||||||
proc localZoneInfoFromUtc(time: Time): ZonedTime {.tags: [], raises: [], benign .}
|
proc localZoneInfoFromUtc(time: Time): ZonedTime {.tags: [], raises: [], benign .}
|
||||||
proc localZoneInfoFromTz(adjTime: Time): ZonedTime {.tags: [], raises: [], benign .}
|
proc localZoneInfoFromTz(adjTime: Time): ZonedTime {.tags: [], raises: [], benign .}
|
||||||
proc initTime*(unix: int64, nanosecond: NanosecondRange): Time
|
proc initTime*(unix: int64, nanosecond: NanosecondRange): Time
|
||||||
{.tags: [], raises: [], benign noSideEffect.}
|
{.tags: [], raises: [], benign noSideEffect.}
|
||||||
|
|
||||||
proc initDuration*(nanoseconds, microseconds, milliseconds,
|
proc initDuration*(nanoseconds, microseconds, milliseconds,
|
||||||
seconds, minutes, hours, days, weeks: int64 = 0): Duration
|
seconds, minutes, hours, days, weeks: int64 = 0): Duration
|
||||||
{.tags: [], raises: [], benign noSideEffect.}
|
{.tags: [], raises: [], benign noSideEffect.}
|
||||||
|
|
||||||
proc nanosecond*(time: Time): NanosecondRange =
|
proc nanosecond*(time: Time): NanosecondRange =
|
||||||
|
|
@ -531,7 +531,7 @@ proc `$`*(dur: Duration): string =
|
||||||
let quantity = numParts[unit]
|
let quantity = numParts[unit]
|
||||||
if quantity != 0.int64:
|
if quantity != 0.int64:
|
||||||
parts.add(stringifyUnit(quantity, $unit))
|
parts.add(stringifyUnit(quantity, $unit))
|
||||||
|
|
||||||
result = humanizeParts(parts)
|
result = humanizeParts(parts)
|
||||||
|
|
||||||
proc `+`*(a, b: Duration): Duration {.operator.} =
|
proc `+`*(a, b: Duration): Duration {.operator.} =
|
||||||
|
|
@ -1243,23 +1243,23 @@ proc evaluateStaticInterval(interval: TimeInterval): Duration =
|
||||||
minutes = interval.minutes,
|
minutes = interval.minutes,
|
||||||
hours = interval.hours)
|
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
|
## Evaluate difference between two dates in ``TimeInterval`` format, so, it
|
||||||
## will be relative.
|
## will be relative.
|
||||||
##
|
##
|
||||||
## **Warning:** It's not recommended to use ``between`` for ``DateTime's`` in
|
## **Warning:** It's not recommended to use ``between`` for ``DateTime's`` in
|
||||||
## different ``TimeZone's``.
|
## different ``TimeZone's``.
|
||||||
## ``a + between(a, b) == b`` is only guaranteed when ``a`` and ``b`` are in UTC.
|
## ``a + between(a, b) == b`` is only guaranteed when ``a`` and ``b`` are in UTC.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
var a = initDateTime(year = 2018, month = Month(3), monthday = 25,
|
var a = initDateTime(year = 2018, month = Month(3), monthday = 25,
|
||||||
hour = 0, minute = 59, second = 59, nanosecond = 1,
|
hour = 0, minute = 59, second = 59, nanosecond = 1,
|
||||||
zone = utc()).local
|
zone = utc()).local
|
||||||
var b = initDateTime(year = 2018, month = Month(3), monthday = 25,
|
var b = initDateTime(year = 2018, month = Month(3), monthday = 25,
|
||||||
hour = 1, minute = 1, second = 1, nanosecond = 0,
|
hour = 1, minute = 1, second = 1, nanosecond = 0,
|
||||||
zone = utc()).local
|
zone = utc()).local
|
||||||
doAssert between(a, b) == initTimeInterval(
|
doAssert between(a, b) == initTimeInterval(
|
||||||
nanoseconds=999, milliseconds=999, microseconds=999, seconds=1, minutes=1)
|
nanoseconds=999, milliseconds=999, microseconds=999, seconds=1, minutes=1)
|
||||||
|
|
||||||
a = parse("2018-01-09T00:00:00+00:00", "yyyy-MM-dd'T'HH:mm:sszzz", utc())
|
a = parse("2018-01-09T00:00:00+00:00", "yyyy-MM-dd'T'HH:mm:sszzz", utc())
|
||||||
b = parse("2018-01-10T23:00:00-02:00", "yyyy-MM-dd'T'HH:mm:sszzz")
|
b = parse("2018-01-10T23:00:00-02:00", "yyyy-MM-dd'T'HH:mm:sszzz")
|
||||||
doAssert between(a, b) == initTimeInterval(hours=1, days=2)
|
doAssert between(a, b) == initTimeInterval(hours=1, days=2)
|
||||||
|
|
@ -1526,7 +1526,6 @@ proc formatToken(dt: DateTime, token: string, buf: var string) =
|
||||||
else:
|
else:
|
||||||
raise newException(ValueError, "Invalid format string: " & token)
|
raise newException(ValueError, "Invalid format string: " & token)
|
||||||
|
|
||||||
|
|
||||||
proc format*(dt: DateTime, f: string): string {.tags: [].}=
|
proc format*(dt: DateTime, f: string): string {.tags: [].}=
|
||||||
## This procedure formats `dt` as specified by `f`. The following format
|
## This procedure formats `dt` as specified by `f`. The following format
|
||||||
## specifiers are available:
|
## specifiers are available:
|
||||||
|
|
@ -1601,18 +1600,14 @@ proc format*(dt: DateTime, f: string): string {.tags: [].}=
|
||||||
inc(i)
|
inc(i)
|
||||||
formatToken(dt, currentF, result)
|
formatToken(dt, currentF, result)
|
||||||
|
|
||||||
proc format*(time: Time, f: string, zone_info: proc(t: Time): DateTime): string {.tags: [].} =
|
proc format*(time: Time, f: string, zone: Timezone = local()): string {.tags: [].} =
|
||||||
## converts a `Time` value to a string representation. It will use format from
|
## Converts a `Time` value to a string representation. It will use format from
|
||||||
## ``format(dt: DateTime, f: string)``.
|
## ``format(dt: DateTime, f: string)``.
|
||||||
runnableExamples:
|
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()
|
var tm = dt.toTime()
|
||||||
doAssert format(tm, "yyyy-MM-dd'T'HH:mm:ss", local) == "1970-01-01T00:00:00"
|
doAssert format(tm, "yyyy-MM-dd'T'HH:mm:ss", utc()) == "1970-01-01T00:00:00"
|
||||||
dt = initDateTime(01, mJan, 1970, 00, 00, 00, utc())
|
time.inZone(zone).format(f)
|
||||||
tm = dt.toTime()
|
|
||||||
doAssert format(tm, "yyyy-MM-dd'T'HH:mm:ss", utc) == "1970-01-01T00:00:00"
|
|
||||||
|
|
||||||
zone_info(time).format(f)
|
|
||||||
|
|
||||||
proc `$`*(dt: DateTime): string {.tags: [], raises: [], benign.} =
|
proc `$`*(dt: DateTime): string {.tags: [], raises: [], benign.} =
|
||||||
## Converts a `DateTime` object to a string representation.
|
## 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 =
|
proc toTimeInterval*(time: Time): TimeInterval =
|
||||||
## Converts a Time to a TimeInterval.
|
## Converts a Time to a TimeInterval.
|
||||||
##
|
##
|
||||||
## To be used when diffing times.
|
## To be used when diffing times. Consider using `between` instead.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
let a = fromUnix(10)
|
let a = fromUnix(10)
|
||||||
let dt = initDateTime(01, mJan, 1970, 00, 00, 00, local())
|
let b = fromUnix(1_500_000_000)
|
||||||
doAssert a.toTimeInterval() == initTimeInterval(
|
let ti = b.toTimeInterval() - a.toTimeInterval()
|
||||||
years=1970, days=1, seconds=10, hours=convert(
|
doAssert a + ti == b
|
||||||
Seconds, Hours, -dt.utcOffset
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
var dt = time.local
|
var dt = time.local
|
||||||
initTimeInterval(dt.nanosecond, 0, 0, dt.second, dt.minute, dt.hour,
|
initTimeInterval(dt.nanosecond, 0, 0, dt.second, dt.minute, dt.hour,
|
||||||
dt.monthday, 0, dt.month.ord - 1, dt.year)
|
dt.monthday, 0, dt.month.ord - 1, dt.year)
|
||||||
|
|
@ -2150,7 +2141,7 @@ proc timeToTimeInterval*(t: Time): TimeInterval {.deprecated.} =
|
||||||
t.toTimeInterval()
|
t.toTimeInterval()
|
||||||
|
|
||||||
proc getDayOfWeek*(day, month, year: int): WeekDay {.tags: [], raises: [], benign, deprecated.} =
|
proc getDayOfWeek*(day, month, year: int): WeekDay {.tags: [], raises: [], benign, deprecated.} =
|
||||||
## **Deprecated since v0.18.0:** use
|
## **Deprecated since v0.18.0:** use
|
||||||
## ``getDayOfWeek(monthday: MonthdayRange; month: Month; year: int)`` instead.
|
## ``getDayOfWeek(monthday: MonthdayRange; month: Month; year: int)`` instead.
|
||||||
getDayOfWeek(day, month.Month, year)
|
getDayOfWeek(day, month.Month, year)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue