# times

- マニュアル
- 標準ライブラリ
- 索引

検索
分類:

The `times` module contains routines and types for dealing with time using the proleptic Gregorian calendar. It's also available for the JavaScript target.

Although the `times` module supports nanosecond time resolution, the resolution used by `getTime()` depends on the platform and backend (JS is limited to millisecond precision).

# Examples

    import times, os
    # Simple benchmarking
    let time = cpuTime()
    sleep(100) # Replace this with something to be timed
    echo "Time taken: ", cpuTime() - time

    # Current date & time
    let now1 = now()     # Current timestamp as a DateTime in local time
    let now2 = now().utc # Current timestamp as a DateTime in UTC
    let now3 = getTime() # Current timestamp as a Time

    # Arithmetic using Duration
    echo "One hour from now      : ", now() + initDuration(hours = 1)
    # Arithmetic using TimeInterval
    echo "One year from now      : ", now() + 1.years
    echo "One month from now     : ", now() + 1.months

# Parsing and Formatting Dates

The `DateTime` type can be parsed and formatted using the different `parse` and `format` procedures.

    let dt = parse("2000-01-01", "yyyy-MM-dd")
    echo dt.format("yyyy-MM-dd")

The different format patterns that are supported are documented below.

Pattern | Description | Example
--- | --- | ---
`d` | Numeric value representing the day of the month, it will be either one or two digits long. | `1/04/2012 -> 1` `21/04/2012 -> 21`
`dd` | Same as above, but is always two digits. | `1/04/2012 -> 01` `21/04/2012 -> 21`
`ddd` | Three letter string which indicates the day of the week. | `Saturday -> Sat` `Monday -> Mon`
`dddd` | Full string for the day of the week. | `Saturday -> Saturday` `Monday -> Monday`
`h` | The hours in one digit if possible. Ranging from 1-12. | `5pm -> 5` `2am -> 2`
`hh` | The hours in two digits always. If the hour is one digit, 0 is prepended. | `5pm -> 05` `11am -> 11`
`H` | The hours in one digit if possible, ranging from 0-23. | `5pm -> 17` `2am -> 2`
`HH` | The hours in two digits always. 0 is prepended if the hour is one digit. | `5pm -> 17` `2am -> 02`
`m` | The minutes in one digit if possible. | `5:30 -> 30` `2:01 -> 1`
`mm` | Same as above but always two digits, 0 is prepended if the minute is one digit. | `5:30 -> 30` `2:01 -> 01`
`M` | The month in one digit if possible. | `September -> 9` `December -> 12`
`MM` | The month in two digits always. 0 is prepended if the month value is one digit. | `September -> 09` `December -> 12`
`MMM` | Abbreviated three-letter form of the month. | `September -> Sep` `December -> Dec`
`MMMM` | Full month string, properly capitalized. | `September -> September`
`s` | Seconds as one digit if possible. | `00:00:06 -> 6`
`ss` | Same as above but always two digits. 0 is prepended if the second is one digit. | `00:00:06 -> 06`
`t` | `A` when time is in the AM. `P` when time is in the PM. | `5pm -> P` `2am -> A`
`tt` | Same as above, but `AM` and `PM` instead of `A` and `P` respectively. | `5pm -> PM` `2am -> AM`
`yy` | The last two digits of the year. When parsing, the current century is assumed. | `2012 AD -> 12`
`yyyy` | The year, padded to at least four digits. Is always positive, even when the year is BC. When the year is more than four digits, '+' is prepended. | `2012 AD -> 2012` `24 AD -> 0024` `24 BC -> 00024` `12345 AD -> +12345`
`YYYY` | The year without any padding. Is always positive, even when the year is BC. | `2012 AD -> 2012` `24 AD -> 24` `24 BC -> 24` `12345 AD -> 12345`
`uuuu` | The year, padded to at least four digits. Will be negative when the year is BC. When the year is more than four digits, '+' is prepended unless the year is BC. | `2012 AD -> 2012` `24 AD -> 0024` `24 BC -> -0023` `12345 AD -> +12345`
`UUUU` | The year without any padding. Will be negative when the year is BC. | `2012 AD -> 2012` `24 AD -> 24` `24 BC -> -23` `12345 AD -> 12345`
`z` | Displays the timezone offset from UTC. | `UTC+7 -> +7` `UTC-5 -> -5`
`zz` | Same as above but with leading 0. | `UTC+7 -> +07` `UTC-5 -> -05`
`zzz` | Same as above but with `:mm` where mm represents minutes. | `UTC+7 -> +07:00` `UTC-5 -> -05:00`
`zzzz` | Same as above but with `:ss` where ss represents seconds. | `UTC+7 -> +07:00:00` `UTC-5 -> -05:00:00`
`g` | Era: AD or BC | `300 AD -> AD` `300 BC -> BC`
`fff` | Milliseconds display | `1000000 nanoseconds -> 1`
`ffffff` | Microseconds display | `1000000 nanoseconds -> 1000`
`fffffffff` | Nanoseconds display | `1000000 nanoseconds -> 1000000`

Other strings can be inserted by putting them in `''`. For example `hh'->'mm` will give `01->56`. The following characters can be inserted without quoting them: `:` `-` `(` `)` `/` `[` `]` `,`. A literal `'` can be specified with `''`.

However you don't need to necessarily separate format patterns, as an unambiguous format string like `yyyyMMddhhmmss` is also valid (although only for years in the range 1..9999).

# Duration vs TimeInterval

The `times` module exports two similar types that are both used to represent some amount of time: Duration and TimeInterval. This section explains how they differ and when one should be preferred over the other (short answer: use `Duration` unless support for months and years is needed).

## Duration

A `Duration` represents a duration of time stored as seconds and nanoseconds. A `Duration` is always fully normalized, so `initDuration(hours = 1)` and `initDuration(minutes = 60)` are equivalent.

Arithmetic with a `Duration` is very fast, especially when used with the `Time` type, since it only involves basic arithmetic. Because `Duration` is more performant and easier to understand it should generally preferred.

## TimeInterval

A `TimeInterval` represents an amount of time expressed in calendar units, for example "1 year and 2 days". Since some units cannot be normalized (the length of a year is different for leap years for example), the `TimeInterval` type uses separate fields for every unit. The `TimeInterval`'s returned from this module generally don't normalize anything, so even units that could be normalized (like seconds, milliseconds and so on) are left untouched.

Arithmetic with a `TimeInterval` can be very slow, because it requires timezone information.

Since it's slower and more complex, the `TimeInterval` type should be avoided unless the program explicitly needs the features it offers that `Duration` doesn't have.

## How long is a day?

It should be especially noted that the handling of days differs between `TimeInterval` and `Duration`. The `Duration` type always treats a day as exactly 86400 seconds. For `TimeInterval`, it's more complex.

As an example, consider the amount of time between these two timestamps, both in the same timezone:

> - 2018-03-25T12:00+02:00
> - 2018-03-26T12:00+01:00

If only the date & time is considered, it appears that exactly one day has passed. However, the UTC offsets are different, which means that the UTC offset was changed somewhere in between. This happens twice each year for timezones that use daylight savings time. Because of this change, the amount of time that has passed is actually 25 hours.

The `TimeInterval` type uses calendar units, and will say that exactly one day has passed. The `Duration` type on the other hand normalizes everything to seconds, and will therefore say that 90000 seconds has passed, which is the same as 25 hours.

# 関連

- monotimes module

# インポート

strutils, math, options, winlean, time_t

# 型

    Month = enum
      mJan = (1, "January"), mFeb = "February", mMar = "March", mApr = "April", mMay = "May",
      mJun = "June", mJul = "July", mAug = "August", mSep = "September", mOct = "October",
      mNov = "November", mDec = "December"

  Represents a month. Note that the enum starts at `1`, so `ord(month)` will give the month number in the range `1..12`. ソース 編集

    WeekDay = enum
      dMon = "Monday", dTue = "Tuesday", dWed = "Wednesday", dThu = "Thursday", dFri = "Friday",
      dSat = "Saturday", dSun = "Sunday"

  Represents a weekday. ソース 編集

    DateTimeLocale = object
      MMM*: array[mJan .. mDec, string]
      MMMM*: array[mJan .. mDec, string]
      ddd*: array[dMon .. dSun, string]
      dddd*: array[dMon .. dSun, string]

  ソース 編集

    MonthdayRange = range[1 .. 31]

  ソース 編集

    HourRange = range[0 .. 23]

  ソース 編集

    MinuteRange = range[0 .. 59]

  ソース 編集

    SecondRange = range[0 .. 60]

  ソース 編集

    YeardayRange = range[0 .. 365]

  ソース 編集

    NanosecondRange = range[0 .. 999999999]

  ソース 編集

    Time = object
      seconds: int64
      nanosecond: NanosecondRange

  Represents a point in time. ソース 編集

    DateTime = object of RootObj
      nanosecond*: NanosecondRange ## The number of nanoseconds after the second,
                                 ## in the range 0 to 999_999_999.
      second*: SecondRange         ## The number of seconds after the minute,
                         ## normally in the range 0 to 59, but can
                         ## be up to 60 to allow for a leap second.
      minute*: MinuteRange         ## The number of minutes after the hour,
                         ## in the range 0 to 59.
      hour*: HourRange             ## The number of hours past midnight,
                     ## in the range 0 to 23.
      monthday*: MonthdayRange     ## The day of the month, in the range 1 to 31.
      month*: Month                ## The month.
      year*: int                   ## The year, using astronomical year numbering
               ## (meaning that before year 1 is year 0,
               ## then year -1 and so on).
      weekday*: WeekDay            ## The day of the week.
      yearday*: YeardayRange       ## The number of days since January 1,
                           ## in the range 0 to 365.
      isDst*: bool                 ## Determines whether DST is in effect.
                 ## Always false for the JavaScript backend.
      timezone*: Timezone          ## The timezone represented as an implementation
                        ## of ``Timezone``.
      utcOffset*: int              ## The offset in seconds west of UTC, including
                    ## any offset due to DST. Note that the sign of
                    ## this number is the opposite of the one in a
                    ## formatted offset string like ``+01:00`` (which
                    ## would be equivalent to the UTC offset
                    ## ``-3600``).

  Represents a time in different parts. Although this type can represent leap seconds, they are generally not supported in this module. They are not ignored, but the `DateTime`'s returned by procedures in this module will never have a leap second.

  Warning: even though the fields of `DateTime` are exported, they should never be mutated directly. Doing so is unsafe and will result in the `DateTime` ending up in an invalid state.

  Instead of mutating the fields directly, use the Duration and TimeInterval types for arithmetic and use the initDateTime proc for changing a specific field.

  ソース 編集

    Duration = object
      seconds: int64
      nanosecond: NanosecondRange

  Represents a fixed duration of time, meaning a duration that has constant length independent of the context.

  To create a new `Duration`, use initDuration proc.

  ソース 編集

    TimeUnit = enum
      Nanoseconds, Microseconds, Milliseconds, Seconds, Minutes, Hours, Days, Weeks, Months,
      Years

  Different units of time. ソース 編集

    FixedTimeUnit = range[Nanoseconds .. Weeks]

  Subrange of `TimeUnit` that only includes units of fixed duration. These are the units that can be represented by a `Duration`. ソース 編集

    TimeInterval = object
      nanoseconds*: int            ## The number of nanoseconds
      microseconds*: int           ## The number of microseconds
      milliseconds*: int           ## The number of milliseconds
      seconds*: int                ## The number of seconds
      minutes*: int                ## The number of minutes
      hours*: int                  ## The number of hours
      days*: int                   ## The number of days
      weeks*: int                  ## The number of weeks
      months*: int                 ## The number of months
      years*: int                  ## The number of years

  Represents a non-fixed duration of time. Can be used to add and subtract non-fixed time units from a DateTime or Time.

  Create a new `TimeInterval` with initTimeInterval proc.

  Note that `TimeInterval` doesn't represent a fixed duration of time, since the duration of some units depend on the context (e.g a year can be either 365 or 366 days long). The non-fixed time units are years, months, days and week.

  Note that `TimeInterval`'s returned from the `times` module are never normalized. If you want to normalize a time unit, Duration should be used instead.

  ソース 編集

    Timezone = ref object
      zonedTimeFromTimeImpl: proc (x: Time): ZonedTime {...}{.tags: [], raises: [], gcsafe,
          locks: 0.}
      zonedTimeFromAdjTimeImpl: proc (x: Time): ZonedTime {...}{.tags: [], raises: [], gcsafe,
          locks: 0.}
      name: string

  Timezone interface for supporting DateTimes of arbitrary timezones. The `times` module only supplies implementations for the systems local time and UTC. Source Edit

    ZonedTime = object
      time*: Time                  ## The point in time being represented.
      utcOffset*: int              ## The offset in seconds west of UTC,
                    ## including any offset due to DST.
      isDst*: bool                 ## Determines whether DST is in effect.

  Represents a point in time with an associated UTC offset and DST flag. This type is only used for implementing timezones. ソース 編集

    DurationParts = array[FixedTimeUnit, int64]

  ソース 編集

    TimeIntervalParts = array[TimeUnit, int]

  ソース 編集

    TimeFormat = object
      patterns: seq[byte] ## \
                        ## Contains the patterns encoded as bytes.
                        ## Literal values are encoded in a special way.
                        ## They start with ``Lit.byte``, then the length of the literal, then the
                        ## raw char values of the literal. For example, the literal `foo` would
                        ## be encoded as ``@[Lit.byte, 3.byte, 'f'.byte, 'o'.byte, 'o'.byte]``.
      formatStr: string

  Represents a format for parsing and printing time types.

  To create a new `TimeFormat` use initTimeFormat proc.

  ソース 編集

    TimeParseError = object of ValueError

  Raised when parsing input using a `TimeFormat` fails. ソース 編集

    TimeFormatParseError = object of ValueError

  Raised when parsing a `TimeFormat` string fails. ソース 編集

# 定数

    DefaultLocale = (MMM: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
                        "Nov", "Dec"], MMMM: ["January", "February", "March", "April",
                                           "May", "June", "July", "August", "September",
                                           "October", "November", "December"],
                   ddd: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], dddd: ["Monday",
        "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"])

  ソース 編集

    DurationZero = (seconds: 0, nanosecond: 0)

  Zero value for durations. Useful for comparisons.

      doAssert initDuration(seconds = 1) > DurationZero
      doAssert initDuration(seconds = 0) == DurationZero

  ソース 編集

# プロシージャ

    proc convert[T: SomeInteger](unitFrom, unitTo: FixedTimeUnit; quantity: T): T {...}{.inline.}

  Convert a quantity of some duration unit to another duration unit. This proc only deals with integers, so the result might be truncated.

  用例:

      doAssert convert(Days, Hours, 2) == 48
      doAssert convert(Days, Weeks, 13) == 1
      doAssert convert(Seconds, Milliseconds, -1) == -1000

  ソース 編集

    proc nanosecond(time: Time): NanosecondRange {...}{.raises: [], tags: [].}

  Get the fractional part of a `Time` as the number of nanoseconds of the second. ソース 編集

    proc initDuration(nanoseconds, microseconds, milliseconds, seconds, minutes, hours,
                     days, weeks: int64 = 0): Duration {...}{.raises: [], tags: [].}

  Create a new Duration.

  用例:

      let dur = initDuration(seconds = 1, milliseconds = 1)
      doAssert dur.milliseconds == 1
      doAssert dur.seconds == 1

  ソース 編集

    proc inWeeks(dur: Duration): int64 {...}{.raises: [], tags: [].}

  Convert the duration to the number of whole weeks.

  用例:

      let dur = initDuration(days = 8)
      doAssert dur.inWeeks == 1

  ソース 編集

    proc inDays(dur: Duration): int64 {...}{.raises: [], tags: [].}

  Convert the duration to the number of whole days.

  用例:

      let dur = initDuration(hours = -50)
      doAssert dur.inDays == -2

  ソース 編集

    proc inHours(dur: Duration): int64 {...}{.raises: [], tags: [].}

  Convert the duration to the number of whole hours.

  用例:

      let dur = initDuration(minutes = 60, days = 2)
      doAssert dur.inHours == 49

  ソース 編集

    proc inMinutes(dur: Duration): int64 {...}{.raises: [], tags: [].}

  Convert the duration to the number of whole minutes.

  用例:

      let dur = initDuration(hours = 2, seconds = 10)
      doAssert dur.inMinutes == 120

  ソース 編集

    proc inSeconds(dur: Duration): int64 {...}{.raises: [], tags: [].}

  Convert the duration to the number of whole seconds.

  用例:

      let dur = initDuration(hours = 2, milliseconds = 10)
      doAssert dur.inSeconds == 2 * 60 * 60

  ソース 編集

    proc inMilliseconds(dur: Duration): int64 {...}{.raises: [], tags: [].}

  Convert the duration to the number of whole milliseconds.

  用例:

      let dur = initDuration(seconds = -2)
      doAssert dur.inMilliseconds == -2000

  ソース 編集

    proc inMicroseconds(dur: Duration): int64 {...}{.raises: [], tags: [].}

  Convert the duration to the number of whole microseconds.

  用例:

      let dur = initDuration(seconds = -2)
      doAssert dur.inMicroseconds == -2000000

  ソース 編集

    proc inNanoseconds(dur: Duration): int64 {...}{.raises: [], tags: [].}

  Convert the duration to the number of whole nanoseconds.

  用例:

      let dur = initDuration(seconds = -2)
      doAssert dur.inNanoseconds == -2000000000

  ソース 編集

    proc fromUnix(unix: int64): Time {...}{.gcsafe, locks: 0, tags: [], raises: [], noSideEffect.}

  Convert a unix timestamp (seconds since `1970-01-01T00:00:00Z`) to a `Time`.

  用例:

      doAssert $fromUnix(0).utc == "1970-01-01T00:00:00Z"

  ソース 編集

    proc toUnix(t: Time): int64 {...}{.gcsafe, locks: 0, tags: [], raises: [], noSideEffect.}

  Convert `t` to a unix timestamp (seconds since `1970-01-01T00:00:00Z`).

  用例:

      doAssert fromUnix(0).toUnix() == 0

  ソース 編集

    proc fromWinTime(win: int64): Time {...}{.raises: [], tags: [].}

  Convert a Windows file time (100-nanosecond intervals since `1601-01-01T00:00:00Z`) to a `Time`. ソース 編集

    proc toWinTime(t: Time): int64 {...}{.raises: [], tags: [].}

  Convert `t` to a Windows file time (100-nanosecond intervals since `1601-01-01T00:00:00Z`). ソース 編集

    proc isLeapYear(year: int): bool {...}{.raises: [], tags: [].}

  Returns true if `year` is a leap year.

  用例:

      doAssert isLeapYear(2000)
      doAssert not isLeapYear(1900)

  ソース 編集

    proc getDaysInMonth(month: Month; year: int): int {...}{.raises: [], tags: [].}

  Get the number of days in `month` of `year`.

  用例:

      doAssert getDaysInMonth(mFeb, 2000) == 29
      doAssert getDaysInMonth(mFeb, 2001) == 28

  ソース 編集

    proc getDaysInYear(year: int): int {...}{.raises: [], tags: [].}

  Get the number of days in a `year`

  用例:

      doAssert getDaysInYear(2000) == 366
      doAssert getDaysInYear(2001) == 365

  ソース 編集

    proc getDayOfYear(monthday: MonthdayRange; month: Month; year: int): YeardayRange {...}{.
        tags: [], raises: [], gcsafe, locks: 0.}

  Returns the day of the year. Equivalent with `initDateTime(monthday, month, year, 0, 0, 0).yearday`.

  用例:

      doAssert getDayOfYear(1, mJan, 2000) == 0
      doAssert getDayOfYear(10, mJan, 2000) == 9
      doAssert getDayOfYear(10, mFeb, 2000) == 40

  ソース 編集

    proc getDayOfWeek(monthday: MonthdayRange; month: Month; year: int): WeekDay {...}{.tags: [],
        raises: [], gcsafe, locks: 0.}

  Returns the day of the week enum from day, month and year. Equivalent with `initDateTime(monthday, month, year, 0, 0, 0).weekday`.

  用例:

      doAssert getDayOfWeek(13, mJun, 1990) == dWed
      doAssert $getDayOfWeek(13, mJun, 1990) == "Wednesday"

  ソース 編集

    proc toParts(dur: Duration): DurationParts {...}{.raises: [], tags: [].}

  Converts a duration into an array consisting of fixed time units.

  Each value in the array gives information about a specific unit of time, for example `result[Days]` gives a count of days.

  This procedure is useful for converting `Duration` values to strings.

  用例:

      var dp = toParts(initDuration(weeks = 2, days = 1))
      doAssert dp[Days] == 1
      doAssert dp[Weeks] == 2
      doAssert dp[Minutes] == 0
      dp = toParts(initDuration(days = -1))
      doAssert dp[Days] == -1

  ソース 編集

    proc `$`(dur: Duration): string {...}{.raises: [], tags: [].}

  Human friendly string representation of a `Duration`.

  用例:

      doAssert $initDuration(seconds = 2) == "2 seconds"
      doAssert $initDuration(weeks = 1, days = 2) == "1 week and 2 days"
      doAssert $initDuration(hours = 1, minutes = 2, seconds = 3) ==
          "1 hour, 2 minutes, and 3 seconds"
      doAssert $initDuration(milliseconds = -1500) == "-1 second and -500 milliseconds"

  ソース 編集

    proc `+`(a, b: Duration): Duration {...}{.gcsafe, noSideEffect, gcsafe, locks: 0,
                                    extern: "ntAddDuration", raises: [], tags: [].}

  Add two durations together.

  用例:

      doAssert initDuration(seconds = 1) + initDuration(days = 1) ==
          initDuration(seconds = 1, days = 1)

  ソース 編集

    proc `-`(a, b: Duration): Duration {...}{.gcsafe, noSideEffect, gcsafe, locks: 0,
                                    extern: "ntSubDuration", raises: [], tags: [].}

  Subtract a duration from another.

  用例:

      doAssert initDuration(seconds = 1, days = 1) - initDuration(seconds = 1) ==
          initDuration(days = 1)

  ソース 編集

    proc `-`(a: Duration): Duration {...}{.gcsafe, noSideEffect, gcsafe, locks: 0,
                                  extern: "ntReverseDuration", raises: [], tags: [].}

  Reverse a duration.

  用例:

      doAssert -initDuration(seconds = 1) == initDuration(seconds = -1)

  ソース 編集

    proc `<`(a, b: Duration): bool {...}{.gcsafe, noSideEffect, gcsafe, locks: 0,
                                extern: "ntLtDuration", raises: [], tags: [].}

  Note that a duration can be negative, so even if `a < b` is true `a` might represent a larger absolute duration. Use `abs(a) < abs(b)` to compare the absolute duration.

  用例:

      doAssert initDuration(seconds = 1) < initDuration(seconds = 2)
      doAssert initDuration(seconds = -2) < initDuration(seconds = 1)
      doAssert initDuration(seconds = -2).abs < initDuration(seconds = 1).abs == false

  ソース 編集

    proc `<=`(a, b: Duration): bool {...}{.gcsafe, noSideEffect, gcsafe, locks: 0,
                                 extern: "ntLeDuration", raises: [], tags: [].}

  ソース 編集

    proc `==`(a, b: Duration): bool {...}{.gcsafe, noSideEffect, gcsafe, locks: 0,
                                 extern: "ntEqDuration", raises: [], tags: [].}

  用例:

      let
        d1 = initDuration(weeks = 1)
        d2 = initDuration(days = 7)
      doAssert d1 == d2

  ソース 編集

    proc `*`(a: int64; b: Duration): Duration {...}{.gcsafe, noSideEffect, gcsafe, locks: 0,
                                          extern: "ntMulInt64Duration", raises: [],
                                          tags: [].}

  Multiply a duration by some scalar.

  用例:

      doAssert 5 * initDuration(seconds = 1) == initDuration(seconds = 5)
      doAssert 3 * initDuration(minutes = 45) == initDuration(hours = 2, minutes = 15)

  ソース 編集

    proc `*`(a: Duration; b: int64): Duration {...}{.gcsafe, noSideEffect, gcsafe, locks: 0,
                                          extern: "ntMulDuration", raises: [], tags: [].}

  Multiply a duration by some scalar.

  用例:

      doAssert initDuration(seconds = 1) * 5 == initDuration(seconds = 5)
      doAssert initDuration(minutes = 45) * 3 == initDuration(hours = 2, minutes = 15)

  ソース 編集

    proc `div`(a: Duration; b: int64): Duration {...}{.gcsafe, noSideEffect, gcsafe, locks: 0,
                                            extern: "ntDivDuration", raises: [],
                                            tags: [].}

  Integer division for durations.

  用例:

      doAssert initDuration(seconds = 3) div 2 == initDuration(milliseconds = 1500)
      doAssert initDuration(minutes = 45) div 30 ==
          initDuration(minutes = 1, seconds = 30)
      doAssert initDuration(nanoseconds = 3) div 2 == initDuration(nanoseconds = 1)

  ソース 編集

    proc initTime(unix: int64; nanosecond: NanosecondRange): Time {...}{.tags: [], raises: [],
        gcsafe, locks: 0, noSideEffect.}

  Create a Time from a unix timestamp and a nanosecond part. ソース 編集

    proc `-`(a, b: Time): Duration {...}{.gcsafe, noSideEffect, gcsafe, locks: 0,
                                extern: "ntDiffTime", raises: [], tags: [].}

  Computes the duration between two points in time.

  用例:

      doAssert initTime(1000, 100) - initTime(500, 20) ==
          initDuration(minutes = 8, seconds = 20, nanoseconds = 80)

  ソース 編集

    proc `+`(a: Time; b: Duration): Time {...}{.gcsafe, noSideEffect, gcsafe, locks: 0,
                                     extern: "ntAddTime", raises: [], tags: [].}

  Add a duration of time to a `Time`.

  用例:

      doAssert (fromUnix(0) + initDuration(seconds = 1)) == fromUnix(1)

  ソース 編集

    proc `-`(a: Time; b: Duration): Time {...}{.gcsafe, noSideEffect, gcsafe, locks: 0,
                                     extern: "ntSubTime", raises: [], tags: [].}

  Subtracts a duration of time from a `Time`.

  用例:

      doAssert (fromUnix(0) - initDuration(seconds = 1)) == fromUnix(-1)

  ソース 編集

    proc `<`(a, b: Time): bool {...}{.gcsafe, noSideEffect, gcsafe, locks: 0, extern: "ntLtTime",
                            raises: [], tags: [].}

  Returns true if `a < b`, that is if `a` happened before `b`.

  用例:

      doAssert initTime(50, 0) < initTime(99, 0)

  ソース 編集

    proc `<=`(a, b: Time): bool {...}{.gcsafe, noSideEffect, gcsafe, locks: 0, extern: "ntLeTime",
                             raises: [], tags: [].}

  Returns true if `a <= b`. ソース 編集

    proc `==`(a, b: Time): bool {...}{.gcsafe, noSideEffect, gcsafe, locks: 0, extern: "ntEqTime",
                             raises: [], tags: [].}

  Returns true if `a == b`, that is if both times represent the same point in time. ソース 編集

    proc high(typ: typedesc[Time]): Time

  ソース 編集

    proc low(typ: typedesc[Time]): Time

  ソース 編集

    proc high(typ: typedesc[Duration]): Duration

  Get the longest representable duration. ソース 編集

    proc low(typ: typedesc[Duration]): Duration

  Get the longest representable duration of negative direction. ソース 編集

    proc abs(a: Duration): Duration {...}{.raises: [], tags: [].}

  用例:

      doAssert initDuration(milliseconds = -1500).abs ==
          initDuration(milliseconds = 1500)

  ソース 編集

    proc toTime(dt: DateTime): Time {...}{.tags: [], raises: [], gcsafe, locks: 0.}

  Converts a `DateTime` to a `Time` representing the same point in time. ソース 編集

    proc newTimezone(name: string; zonedTimeFromTimeImpl: proc (time: Time): ZonedTime {...}{.
        tags: [], raises: [], gcsafe, locks: 0.}; zonedTimeFromAdjTimeImpl: proc (
        adjTime: Time): ZonedTime {...}{.tags: [], raises: [], gcsafe, locks: 0.}): owned Timezone {...}{.
        raises: [], tags: [].}

  Create a new `Timezone`.

  `zonedTimeFromTimeImpl` and `zonedTimeFromAdjTimeImpl` is used as the underlying implementations for `zonedTimeFromTime` and `zonedTimeFromAdjTime`.

  If possible, the name parameter should match the name used in the tz database. If the timezone doesn't exist in the tz database, or if the timezone name is unknown, then any string that describes the timezone unambiguously can be used. Note that the timezones name is used for checking equality!

  用例:

      proc utcTzInfo(time: Time): ZonedTime =
        ZonedTime(utcOffset: 0, isDst: false, time: time)

      let utc = newTimezone("Etc/UTC", utcTzInfo, utcTzInfo)

  ソース 編集

    proc name(zone: Timezone): string {...}{.raises: [], tags: [].}

  The name of the timezone.

  If possible, the name will be the name used in the tz database. If the timezone doesn't exist in the tz database, or if the timezone name is unknown, then any string that describes the timezone unambiguously might be used. For example, the string "LOCAL" is used for the systems local timezone.

  See also: https://en.wikipedia.org/wiki/Tz_database

  ソース 編集

    proc zonedTimeFromTime(zone: Timezone; time: Time): ZonedTime {...}{.raises: [], tags: [].}

  Returns the `ZonedTime` for some point in time. ソース 編集

    proc zonedTimeFromAdjTime(zone: Timezone; adjTime: Time): ZonedTime {...}{.raises: [],
        tags: [].}

  Returns the `ZonedTime` for some local time.

  Note that the `Time` argument does not represent a point in time, it represent a local time! E.g if `adjTime` is `fromUnix(0)`, it should be interpreted as 1970-01-01T00:00:00 in the `zone` timezone, not in UTC.

  ソース 編集

    proc `$`(zone: Timezone): string {...}{.raises: [], tags: [].}

  Returns the name of the timezone. ソース 編集

    proc `==`(zone1, zone2: Timezone): bool {...}{.raises: [], tags: [].}

  Two `Timezone`'s are considered equal if their name is equal.

  用例:

      doAssert local() == local()
      doAssert local() != utc()

  ソース 編集

    proc inZone(time: Time; zone: Timezone): DateTime {...}{.tags: [], raises: [], gcsafe, locks: 0.}

  Convert `time` into a `DateTime` using `zone` as the timezone. ソース 編集

    proc inZone(dt: DateTime; zone: Timezone): DateTime {...}{.tags: [], raises: [], gcsafe,
        locks: 0.}

  Returns a `DateTime` representing the same point in time as `dt` but using `zone` as the timezone. ソース 編集

    proc utc(): Timezone {...}{.raises: [], tags: [].}

  Get the `Timezone` implementation for the UTC timezone.

  用例:

      doAssert now().utc.timezone == utc()
      doAssert utc().name == "Etc/UTC"

  ソース 編集

    proc local(): Timezone {...}{.raises: [], tags: [].}

  Get the `Timezone` implementation for the local timezone.

  用例:

      doAssert now().timezone == local()
      doAssert local().name == "LOCAL"

  ソース 編集

    proc utc(dt: DateTime): DateTime {...}{.raises: [], tags: [].}

  Shorthand for `dt.inZone(utc())`. ソース 編集

    proc local(dt: DateTime): DateTime {...}{.raises: [], tags: [].}

  Shorthand for `dt.inZone(local())`. ソース 編集

    proc utc(t: Time): DateTime {...}{.raises: [], tags: [].}

  Shorthand for `t.inZone(utc())`. ソース 編集

    proc local(t: Time): DateTime {...}{.raises: [], tags: [].}

  Shorthand for `t.inZone(local())`. ソース 編集

    proc getTime(): Time {...}{.tags: [TimeEffect], gcsafe, locks: 0, raises: [].}

  Gets the current time as a `Time` with up to nanosecond resolution. ソース 編集

    proc now(): DateTime {...}{.tags: [TimeEffect], gcsafe, locks: 0, raises: [].}

  Get the current time as a `DateTime` in the local timezone.

  Shorthand for `getTime().local`.

  ソース 編集

    proc initTimeInterval(nanoseconds, microseconds, milliseconds, seconds, minutes,
                         hours, days, weeks, months, years: int = 0): TimeInterval {...}{.
        raises: [], tags: [].}

  Creates a new TimeInterval.

  This proc doesn't perform any normalization! For example, `initTimeInterval(hours = 24)` and `initTimeInterval(days = 1)` are not equal.

  You can also use the convenience procedures called `milliseconds`, `seconds`, `minutes`, `hours`, `days`, `months`, and `years`.

  用例:

      let day = initTimeInterval(hours = 24)
      let dt = initDateTime(1, mJan, 2000, 12, 0, 0, utc())
      doAssert $(dt + day) == "2000-01-02T12:00:00Z"
      doAssert initTimeInterval(hours = 24) != initTimeInterval(days = 1)

  ソース 編集

    proc `+`(ti1, ti2: TimeInterval): TimeInterval {...}{.raises: [], tags: [].}

  Adds two `TimeInterval` objects together. ソース 編集

    proc `-`(ti: TimeInterval): TimeInterval {...}{.raises: [], tags: [].}

  Reverses a time interval

  用例:

      let day = -initTimeInterval(hours = 24)
      doAssert day.hours == -24

  ソース 編集

    proc `-`(ti1, ti2: TimeInterval): TimeInterval {...}{.raises: [], tags: [].}

  Subtracts TimeInterval `ti1` from `ti2`.

  Time components are subtracted one-by-one, see output:

  用例:

      let ti1 = initTimeInterval(hours = 24)
      let ti2 = initTimeInterval(hours = 4)
      doAssert (ti1 - ti2) == initTimeInterval(hours = 20)

  ソース 編集

    proc getDateStr(dt = now()): string {...}{.gcsafe, extern: "nt$1", tags: [TimeEffect],
                                     raises: [].}

  Gets the current local date as a string of the format `YYYY-MM-DD`.

  用例:

      echo getDateStr(now() - 1.months)

  ソース 編集

    proc getClockStr(dt = now()): string {...}{.gcsafe, extern: "nt$1", tags: [TimeEffect],
                                      raises: [].}

  Gets the current local clock time as a string of the format `HH:mm:ss`.

  用例:

      echo getClockStr(now() - 1.hours)

  ソース 編集

    proc toParts(ti: TimeInterval): TimeIntervalParts {...}{.raises: [], tags: [].}

  Converts a `TimeInterval` into an array consisting of its time units, starting with nanoseconds and ending with years.

  This procedure is useful for converting `TimeInterval` values to strings. E.g. then you need to implement custom interval printing

  用例:

      var tp = toParts(initTimeInterval(years = 1, nanoseconds = 123))
      doAssert tp[Years] == 1
      doAssert tp[Nanoseconds] == 123

  ソース 編集

    proc `$`(ti: TimeInterval): string {...}{.raises: [], tags: [].}

  Get string representation of `TimeInterval`.

  用例:

      doAssert $initTimeInterval(years = 1, nanoseconds = 123) ==
          "1 year and 123 nanoseconds"
      doAssert $initTimeInterval() == "0 nanoseconds"

  ソース 編集

    proc nanoseconds(nanos: int): TimeInterval {...}{.inline, raises: [], tags: [].}

  TimeInterval of `nanos` nanoseconds. ソース 編集

    proc microseconds(micros: int): TimeInterval {...}{.inline, raises: [], tags: [].}

  TimeInterval of `micros` microseconds. ソース 編集

    proc milliseconds(ms: int): TimeInterval {...}{.inline, raises: [], tags: [].}

  TimeInterval of `ms` milliseconds. ソース 編集

    proc seconds(s: int): TimeInterval {...}{.inline, raises: [], tags: [].}

  TimeInterval of `s` seconds.

  `echo getTime() + 5.seconds`

  ソース 編集

    proc minutes(m: int): TimeInterval {...}{.inline, raises: [], tags: [].}

  TimeInterval of `m` minutes.

  `echo getTime() + 5.minutes`

  ソース 編集

    proc hours(h: int): TimeInterval {...}{.inline, raises: [], tags: [].}

  TimeInterval of `h` hours.

  `echo getTime() + 2.hours`

  ソース 編集

    proc days(d: int): TimeInterval {...}{.inline, raises: [], tags: [].}

  TimeInterval of `d` days.

  `echo getTime() + 2.days`

  ソース 編集

    proc weeks(w: int): TimeInterval {...}{.inline, raises: [], tags: [].}

  TimeInterval of `w` weeks.

  `echo getTime() + 2.weeks`

  ソース 編集

    proc months(m: int): TimeInterval {...}{.inline, raises: [], tags: [].}

  TimeInterval of `m` months.

  `echo getTime() + 2.months`

  ソース 編集

    proc years(y: int): TimeInterval {...}{.inline, raises: [], tags: [].}

  TimeInterval of `y` years.

  `echo getTime() + 2.years`

  ソース 編集

    proc initDateTime(monthday: MonthdayRange; month: Month; year: int; hour: HourRange;
                     minute: MinuteRange; second: SecondRange;
                     nanosecond: NanosecondRange; zone: Timezone = local()): DateTime {...}{.
        raises: [], tags: [].}

  Create a new DateTime in the specified timezone.

  用例:

      let dt1 = initDateTime(30, mMar, 2017, 0, 0, 0, 0, utc())
      doAssert $dt1 == "2017-03-30T00:00:00Z"

  ソース 編集

    proc initDateTime(monthday: MonthdayRange; month: Month; year: int; hour: HourRange;
                     minute: MinuteRange; second: SecondRange; zone: Timezone = local()): DateTime {...}{.
        raises: [], tags: [].}

  Create a new DateTime in the specified timezone.

  用例:

      let dt1 = initDateTime(30, mMar, 2017, 0, 0, 0, utc())
      doAssert $dt1 == "2017-03-30T00:00:00Z"

  ソース 編集

    proc `+`(dt: DateTime; interval: TimeInterval): DateTime {...}{.raises: [], tags: [].}

  Adds `interval` to `dt`. Components from `interval` are added in the order of their size, i.e. first the `years` component, then the `months` component and so on. The returned `DateTime` will have the same timezone as the input.

  Note that when adding months, monthday overflow is allowed. This means that if the resulting month doesn't have enough days it, the month will be incremented and the monthday will be set to the number of days overflowed. So adding one month to `31 October` will result in `31 November`, which will overflow and result in `1 December`.

  用例:

      let dt = initDateTime(30, mMar, 2017, 0, 0, 0, utc())
      doAssert $(dt + 1.months) == "2017-04-30T00:00:00Z"
      doAssert $(dt - 1.months) == "2017-03-02T00:00:00Z"

  ソース 編集

    proc `-`(dt: DateTime; interval: TimeInterval): DateTime {...}{.raises: [], tags: [].}

  Subtract `interval` from `dt`. Components from `interval` are subtracted in the order of their size, i.e. first the `years` component, then the `months` component and so on. The returned `DateTime` will have the same timezone as the input.

  用例:

      let dt = initDateTime(30, mMar, 2017, 0, 0, 0, utc())
      doAssert $(dt - 5.days) == "2017-03-25T00:00:00Z"

  ソース 編集

    proc `+`(dt: DateTime; dur: Duration): DateTime {...}{.raises: [], tags: [].}

  用例:

      let dt = initDateTime(30, mMar, 2017, 0, 0, 0, utc())
      let dur = initDuration(hours = 5)
      doAssert $(dt + dur) == "2017-03-30T05:00:00Z"

  ソース 編集

    proc `-`(dt: DateTime; dur: Duration): DateTime {...}{.raises: [], tags: [].}

  用例:

      let dt = initDateTime(30, mMar, 2017, 0, 0, 0, utc())
      let dur = initDuration(days = 5)
      doAssert $(dt - dur) == "2017-03-25T00:00:00Z"

  ソース 編集

    proc `-`(dt1, dt2: DateTime): Duration {...}{.raises: [], tags: [].}

  Compute the duration between `dt1` and `dt2`.

  用例:

      let dt1 = initDateTime(30, mMar, 2017, 0, 0, 0, utc())
      let dt2 = initDateTime(25, mMar, 2017, 0, 0, 0, utc())
      doAssert dt1 - dt2 == initDuration(days = 5)

  ソース 編集

    proc `<`(a, b: DateTime): bool {...}{.raises: [], tags: [].}

  Returns true if `a` happened before `b`. ソース 編集

    proc `<=`(a, b: DateTime): bool {...}{.raises: [], tags: [].}

  Returns true if `a` happened before or at the same time as `b`. ソース 編集

    proc `==`(a, b: DateTime): bool {...}{.raises: [], tags: [].}

  Returns true if `a` and `b` represent the same point in time. ソース 編集

    proc between(startDt, endDt: DateTime): TimeInterval {...}{.raises: [], tags: [].}

  Gives the difference between `startDt` and `endDt` as a `TimeInterval`. The following guarantees about the result is given:
  - All fields will have the same sign.
  - If `startDt.timezone == endDt.timezone`, it is guaranteed that `startDt + between(startDt, endDt) == endDt`.
  - If `startDt.timezone != endDt.timezone`, then the result will be equivalent to `between(startDt.utc, endDt.utc)`.

  用例:

      var a = initDateTime(25, mMar, 2015, 12, 0, 0, utc())
      var b = initDateTime(1, mApr, 2017, 15, 0, 15, utc())
      var ti = initTimeInterval(years = 2, weeks = 1, hours = 3, seconds = 15)
      doAssert between(a, b) == ti
      doAssert between(a, b) == -between(b, a)

  ソース 編集

    proc `+`(time: Time; interval: TimeInterval): Time {...}{.raises: [], tags: [].}

  Adds `interval` to `time`. If `interval` contains any years, months, weeks or days the operation is performed in the local timezone.

  用例:

      let tm = fromUnix(0)
      doAssert tm + 5.seconds == fromUnix(5)

  ソース 編集

    proc `-`(time: Time; interval: TimeInterval): Time {...}{.raises: [], tags: [].}

  Subtracts `interval` from Time `time`. If `interval` contains any years, months, weeks or days the operation is performed in the local timezone.

  用例:

      let tm = fromUnix(5)
      doAssert tm - 5.seconds == fromUnix(0)

  ソース 編集

    proc `+=`[T, U: TimesMutableTypes](a: var T; b: U)

  Modify `a` in place by adding `b`.

  用例:

      var tm = fromUnix(0)
      tm += initDuration(seconds = 1)
      doAssert tm == fromUnix(1)

  ソース 編集

    proc `-=`[T, U: TimesMutableTypes](a: var T; b: U)

  Modify `a` in place by subtracting `b`.

  用例:

      var tm = fromUnix(5)
      tm -= initDuration(seconds = 5)
      doAssert tm == fromUnix(0)

  ソース 編集

    proc `*=`[T: TimesMutableTypes; U](a: var T; b: U)

  用例:

      var dur = initDuration(seconds = 1)
      dur *= 5
      doAssert dur == initDuration(seconds = 5)

  ソース 編集

    proc `$`(f: TimeFormat): string {...}{.raises: [], tags: [].}

  Returns the format string that was used to construct `f`.

  用例:

      let f = initTimeFormat("yyyy-MM-dd")
      doAssert $f == "yyyy-MM-dd"

  ソース 編集

    proc initTimeFormat(format: string): TimeFormat {...}{.raises: [TimeFormatParseError],
        tags: [].}

  Construct a new time format for parsing & formatting time types.

  See Parsing and formatting dates for documentation of the `format` argument.

  用例:

      let f = initTimeFormat("yyyy-MM-dd")
      doAssert "2000-01-01" == "2000-01-01".parse(f).format(f)

  ソース 編集

    proc format(dt: DateTime; f: TimeFormat; loc: DateTimeLocale = DefaultLocale): string {...}{.
        raises: [], tags: [].}

  Format `dt` using the format specified by `f`.

  用例:

      let f = initTimeFormat("yyyy-MM-dd")
      let dt = initDateTime(1, mJan, 2000, 0, 0, 0, utc())
      doAssert "2000-01-01" == dt.format(f)

  ソース 編集

    proc format(dt: DateTime; f: string; loc: DateTimeLocale = DefaultLocale): string {...}{.
        raises: [TimeFormatParseError], tags: [].}

  Shorthand for constructing a `TimeFormat` and using it to format `dt`.

  See Parsing and formatting dates for documentation of the `format` argument.

  用例:

      let dt = initDateTime(1, mJan, 2000, 0, 0, 0, utc())
      doAssert "2000-01-01" == format(dt, "yyyy-MM-dd")

  ソース 編集

    proc format(dt: DateTime; f: static[string]): string {...}{.raises: [].}

  Overload that validates `format` at compile time. ソース 編集

    proc formatValue(result: var string; value: DateTime; specifier: string) {...}{.
        raises: [TimeFormatParseError], tags: [].}

  adapter for strformat. Not intended to be called directly. ソース 編集

    proc format(time: Time; f: string; zone: Timezone = local()): string {...}{.
        raises: [TimeFormatParseError], tags: [].}

  Shorthand for constructing a `TimeFormat` and using it to format `time`. Will use the timezone specified by `zone`.

  See Parsing and formatting dates for documentation of the `f` argument.

  用例:

      var dt = initDateTime(1, mJan, 1970, 0, 0, 0, utc())
      var tm = dt.toTime()
      doAssert format(tm, "yyyy-MM-dd\'T\'HH:mm:ss", utc()) == "1970-01-01T00:00:00"

  ソース 編集

    proc format(time: Time; f: static[string]; zone: Timezone = local()): string {...}{.raises: [].}

  Overload that validates `f` at compile time. ソース 編集

    proc parse(input: string; f: TimeFormat; zone: Timezone = local();
              loc: DateTimeLocale = DefaultLocale): DateTime {...}{.
        raises: [TimeParseError, Defect], tags: [TimeEffect].}

  Parses `input` as a `DateTime` using the format specified by `f`. If no UTC offset was parsed, then `input` is assumed to be specified in the `zone` timezone. If a UTC offset was parsed, the result will be converted to the `zone` timezone.

  Month and day names from the passed in `loc` are used.

  用例:

      let f = initTimeFormat("yyyy-MM-dd")
      let dt = initDateTime(1, mJan, 2000, 0, 0, 0, utc())
      doAssert dt == "2000-01-01".parse(f, utc())

  ソース 編集

    proc parse(input, f: string; tz: Timezone = local(); loc: DateTimeLocale = DefaultLocale): DateTime {...}{.
        raises: [TimeParseError, TimeFormatParseError, Defect], tags: [TimeEffect].}

  Shorthand for constructing a `TimeFormat` and using it to parse `input` as a `DateTime`.

  See Parsing and formatting dates for documentation of the `f` argument.

  用例:

      let dt = initDateTime(1, mJan, 2000, 0, 0, 0, utc())
      doAssert dt == parse("2000-01-01", "yyyy-MM-dd", utc())

  ソース 編集

    proc parse(input: string; f: static[string]; zone: Timezone = local();
              loc: DateTimeLocale = DefaultLocale): DateTime {...}{.
        raises: [TimeParseError, Defect].}

  Overload that validates `f` at compile time. ソース 編集

    proc parseTime(input, f: string; zone: Timezone): Time {...}{.
        raises: [TimeParseError, TimeFormatParseError, Defect], tags: [TimeEffect].}

  Shorthand for constructing a `TimeFormat` and using it to parse `input` as a `DateTime`, then converting it a `Time`.

  See Parsing and formatting dates for documentation of the `format` argument.

  用例:

      let tStr = "1970-01-01T00:00:00+00:00"
      doAssert parseTime(tStr, "yyyy-MM-dd\'T\'HH:mm:sszzz", utc()) == fromUnix(0)

  ソース 編集

    proc parseTime(input: string; f: static[string]; zone: Timezone): Time {...}{.
        raises: [TimeParseError, Defect].}

  Overload that validates `format` at compile time. ソース 編集

    proc `$`(dt: DateTime): string {...}{.tags: [], raises: [], gcsafe, locks: 0.}

  Converts a `DateTime` object to a string representation. It uses the format `yyyy-MM-dd'T'HH:mm:sszzz`.

  用例:

      let dt = initDateTime(1, mJan, 2000, 12, 0, 0, utc())
      doAssert $dt == "2000-01-01T12:00:00Z"

  ソース 編集

    proc `$`(time: Time): string {...}{.tags: [], raises: [], gcsafe, locks: 0.}

  Converts a `Time` value to a string representation. It will use the local time zone and use the format `yyyy-MM-dd'T'HH-mm-sszzz`.

  用例:

      let dt = initDateTime(1, mJan, 1970, 0, 0, 0, local())
      let tm = dt.toTime()
      doAssert $tm == "1970-01-01T00:00:00" & format(dt, "zzz")

  ソース 編集

    proc countLeapYears(yearSpan: int): int {...}{.deprecated, raises: [], tags: [].}

  廃止予定

  Returns the number of leap years spanned by a given number of years.

  Note: For leap years, start date is assumed to be 1 AD. counts the number of leap years up to January 1st of a given year. Keep in mind that if specified year is a leap year, the leap day has not happened before January 1st of that year.

  Deprecated since v0.20.0.

  ソース 編集

    proc countDays(yearSpan: int): int {...}{.deprecated, raises: [], tags: [].}

  廃止予定

  Returns the number of days spanned by a given number of years.

  Deprecated since v0.20.0.

  ソース 編集

    proc countYears(daySpan: int): int {...}{.deprecated, raises: [], tags: [].}

  廃止予定

  Returns the number of years spanned by a given number of days.

  Deprecated since v0.20.0.

  ソース 編集

    proc countYearsAndDays(daySpan: int): tuple[years: int, days: int] {...}{.deprecated,
        raises: [], tags: [].}

  廃止予定

  Returns the number of years spanned by a given number of days and the remainder as days.

  Deprecated since v0.20.0.

  ソース 編集

    proc toTimeInterval(time: Time): TimeInterval {...}{.deprecated: "Use `between` instead",
        raises: [], tags: [].}

  Deprecated: Use `between` instead

  Converts a Time to a TimeInterval. To be used when diffing times.

  Deprecated since version 0.20.0: Use the between proc instead.

  用例:

      let a = fromUnix(10)
      let b = fromUnix(1500000000)
      let ti = b.toTimeInterval() - a.toTimeInterval()
      doAssert a + ti == b

  ソース 編集

    proc cpuTime(): float {...}{.tags: [TimeEffect], raises: [].}

  gets time spent that the CPU spent to run the current process in seconds. This may be more useful for benchmarking than `epochTime`. However, it may measure the real time instead (depending on the OS). The value of the result has no meaning. To generate useful timing values, take the difference between the results of two `cpuTime` calls:

  用例:

      var t0 = cpuTime()
      var fib = @[0, 1, 1]
      for i in 1 .. 10:
        fib.add(fib[^1] + fib[^2])
      echo "CPU time [s] ", cpuTime() - t0
      echo "Fib is [s] ", fib

  ソース 編集

    proc epochTime(): float {...}{.tags: [TimeEffect], raises: [].}

  gets time after the UNIX epoch (1970) in seconds. It is a float because sub-second resolution is likely to be supported (depending on the hardware/OS).

  `getTime` should generally be preferred over this proc.

  ソース 編集

    proc weeks(dur: Duration): int64 {...}{.inline, deprecated: "Use `inWeeks` instead",
                                   raises: [], tags: [].}

  Deprecated: Use `inWeeks` instead

  Number of whole weeks represented by the duration.

  Deprecated since version v0.20.0: Use the inWeeks proc instead.

  用例:

      let dur = initDuration(weeks = 1, days = 2, hours = 3, minutes = 4)
      doAssert dur.weeks == 1

  ソース 編集

    proc days(dur: Duration): int64 {...}{.inline, deprecated: "Use `inDays` instead",
                                  raises: [], tags: [].}

  Deprecated: Use `inDays` instead

  Number of whole days represented by the duration.

  Deprecated since version v0.20.0: Use the inDays proc instead.

  用例:

      let dur = initDuration(weeks = 1, days = 2, hours = 3, minutes = 4)
      doAssert dur.days == 9

  ソース 編集

    proc hours(dur: Duration): int64 {...}{.inline, deprecated: "Use `inHours` instead",
                                   raises: [], tags: [].}

  Deprecated: Use `inHours` instead

  Number of whole hours represented by the duration.

  Deprecated since version v0.20.0: Use the inHours proc instead.

  用例:

      let dur = initDuration(days = 1, hours = 2, minutes = 3)
      doAssert dur.hours == 26

  ソース 編集

    proc minutes(dur: Duration): int64 {...}{.inline, deprecated: "Use `inMinutes` instead",
                                     raises: [], tags: [].}

  Deprecated: Use `inMinutes` instead

  Number of whole minutes represented by the duration.

  Deprecated since version v0.20.0: Use the inMinutes proc instead.

  用例:

      let dur = initDuration(days = 1, hours = 2, minutes = 3)
      doAssert dur.minutes == 1563

  ソース 編集

    proc seconds(dur: Duration): int64 {...}{.inline, deprecated: "Use `inSeconds` instead",
                                     raises: [], tags: [].}

  Deprecated: Use `inSeconds` instead

  Number of whole seconds represented by the duration.

  Deprecated since version v0.20.0: Use the inSeconds proc instead.

  用例:

      let dur = initDuration(minutes = 10, seconds = 30)
      doAssert dur.seconds == 630

  ソース 編集

    proc milliseconds(dur: Duration): int {...}{.inline, deprecated, raises: [], tags: [].}

  廃止予定

  Number of whole milliseconds represented by the fractional part of the duration.

  Deprecated since version v0.20.0.

  用例:

      let dur = initDuration(minutes = 5, seconds = 6, milliseconds = 7, microseconds = 8,
                          nanoseconds = 9)
      doAssert dur.milliseconds == 7

  ソース 編集

    proc microseconds(dur: Duration): int {...}{.inline, deprecated, raises: [], tags: [].}

  廃止予定

  Number of whole microseconds represented by the fractional part of the duration.

  Deprecated since version v0.20.0.

  用例:

      let dur = initDuration(minutes = 5, seconds = 6, milliseconds = 7, microseconds = 8,
                          nanoseconds = 9)
      doAssert dur.microseconds == 7008

  ソース 編集

    proc nanoseconds(dur: Duration): NanosecondRange {...}{.inline, deprecated, raises: [],
        tags: [].}

  廃止予定

  Number of whole microseconds represented by the fractional part of the duration.

  Deprecated since version v0.20.0.

  用例:

      let dur = initDuration(minutes = 5, seconds = 6, milliseconds = 7, microseconds = 8,
                          nanoseconds = 9)
      doAssert dur.nanoseconds == 7008009

  ソース 編集

    proc fractional(dur: Duration): Duration {...}{.inline, deprecated, raises: [], tags: [].}

  廃止予定

  The fractional part of `dur`, as a duration.

  Deprecated since version v0.20.0.

  用例:

      let dur = initDuration(minutes = 5, seconds = 6, milliseconds = 7, microseconds = 8,
                          nanoseconds = 9)
      doAssert dur.fractional ==
          initDuration(milliseconds = 7, microseconds = 8, nanoseconds = 9)

  ソース 編集

    proc unixTimeToWinTime(time: CTime): int64 {...}{.deprecated: "Use toWinTime instead",
        raises: [], tags: [].}

  Deprecated: Use toWinTime instead

  Converts a UNIX `Time` (`time_t`) to a Windows file time

  Deprecated: use `toWinTime` instead.

  ソース 編集

    proc winTimeToUnixTime(time: int64): CTime {...}{.deprecated: "Use fromWinTime instead",
        raises: [], tags: [].}

  Deprecated: Use fromWinTime instead

  Converts a Windows time to a UNIX `Time` (`time_t`)

  Deprecated: use `fromWinTime` instead.

  ソース 編集

    proc initInterval(seconds, minutes, hours, days, months, years: int = 0): TimeInterval {...}{.
        deprecated, raises: [], tags: [].}

  廃止予定
  Deprecated since v0.18.0: use `initTimeInterval` instead. Source Edit

    proc fromSeconds(since1970: float): Time {...}{.tags: [], raises: [], gcsafe, locks: 0,
                                           deprecated.}

  廃止予定

  Takes a float which contains the number of seconds since the unix epoch and returns a time object.

  Deprecated since v0.18.0: use `fromUnix` instead

  ソース 編集

    proc fromSeconds(since1970: int64): Time {...}{.tags: [], raises: [], gcsafe, locks: 0,
                                           deprecated.}

  廃止予定

  Takes an int which contains the number of seconds since the unix epoch and returns a time object.

  Deprecated since v0.18.0: use `fromUnix` instead

  ソース 編集

    proc toSeconds(time: Time): float {...}{.tags: [], raises: [], gcsafe, locks: 0, deprecated.}

  廃止予定

  Returns the time in seconds since the unix epoch.

  Deprecated since v0.18.0: use `toUnix` instead

  ソース 編集

    proc getLocalTime(time: Time): DateTime {...}{.tags: [], raises: [], gcsafe, locks: 0,
                                          deprecated.}

  廃止予定

  Converts the calendar time `time` to broken-time representation, expressed relative to the user's specified time zone.

  Deprecated since v0.18.0: use `local` instead

  ソース 編集

    proc getGMTime(time: Time): DateTime {...}{.tags: [], raises: [], gcsafe, locks: 0, deprecated.}

  廃止予定

  Converts the calendar time `time` to broken-down time representation, expressed in Coordinated Universal Time (UTC).

  Deprecated since v0.18.0: use `utc` instead

  ソース 編集

    proc getTimezone(): int {...}{.tags: [TimeEffect], raises: [], gcsafe, locks: 0, deprecated.}

  廃止予定

  Returns the offset of the local (non-DST) timezone in seconds west of UTC.

  Deprecated since v0.18.0: use `now().utcOffset` to get the current utc offset (including DST).

  ソース 編集

    proc getDayOfWeek(day, month, year: int): WeekDay {...}{.tags: [], raises: [], gcsafe, locks: 0,
        deprecated.}

  廃止予定
  Deprecated since v0.18.0: use `getDayOfWeek(monthday: MonthdayRange; month: Month; year: int)` instead. Source Edit

    proc getDayOfWeekJulian(day, month, year: int): WeekDay {...}{.deprecated, raises: [],
        tags: [].}

  廃止予定
  Returns the day of the week enum from day, month and year, according to the Julian calendar. Deprecated since v0.18.0 Source Edit

    proc adjTime(zt: ZonedTime): Time {...}{.deprecated: "Use zt.time instead", raises: [],
                                    tags: [].}

  Deprecated: Use zt.time instead
  Deprecated since v0.19.0: use the `time` field instead. Source Edit

    proc adjTime=(zt: var ZonedTime; adjTime: Time) {...}{.deprecated: "Use zt.time instead",
        raises: [], tags: [].}

  Deprecated: Use zt.time instead
  Deprecated since v0.19.0: use the `time` field instead. Source Edit

    proc zoneInfoFromUtc(zone: Timezone; time: Time): ZonedTime {...}{.
        deprecated: "Use zonedTimeFromTime instead", raises: [], tags: [].}

  Deprecated: Use zonedTimeFromTime instead
  Deprecated since v0.19.0: use `zonedTimeFromTime` instead. Source Edit

    proc zoneInfoFromTz(zone: Timezone; adjTime: Time): ZonedTime {...}{.
        deprecated: "Use zonedTimeFromAdjTime instead", raises: [], tags: [].}

  Deprecated: Use zonedTimeFromAdjTime instead
  Deprecated since v0.19.0: use the `zonedTimeFromAdjTime` instead. Source Edit

# テンプレート

    template formatValue(result: var string; value: Time; specifier: string)

  adapter for `strformat`. Not intended to be called directly. ソース 編集