Class TimeUtils

Constructors

Properties

bigIntDurationToHumanReadable: (start: bigint) => string = bigIntDurationToHumanReadable

Displays the duration of a bigInt since a given start time

Type declaration

    • (start: bigint): string
    • Parameters

      • start: bigint

        The start time as a bigInt

      Returns string

      The duration as a human-readable string

currentUTCDate: () => string = currentUTCDate

Returns the current date in UTC

Type declaration

    • (): string
    • Returns string

      The current date in UTC

currentUTCTime: () => string = currentUTCTime

Returns the current time in UTC

Type declaration

    • (): string
    • Returns string

      The current time in UTC

discordInfoTimestamp: (timestamp?: number) => string = discordInfoTimestamp

Returns a Discord-formatted timestamp with both relative and absolute time

Type declaration

    • (timestamp?: number): string
    • Parameters

      • timestamp: number = ...

        The timestamp to format

      Returns string

      The formatted timestamp string

discordTimestamp: (timestamp: number, style: TimestampStylesString) => string = discordTimestamp

Returns a Discord-formatted timestamp

Type declaration

    • (timestamp: number, style: TimestampStylesString): string
    • Parameters

      • timestamp: number

        The timestamp to format

      • style: TimestampStylesString

        The style of the timestamp

      Returns string

      The formatted timestamp string

discordTimestampNow: (style: TimestampStylesString) => string = discordTimestampNow

Returns the current time as a Discord-formatted timestamp

Type declaration

    • (style: TimestampStylesString): string
    • Parameters

      • style: TimestampStylesString

        The style of the timestamp

      Returns string

      The formatted timestamp string

formatterFromLocale: (
    locale: Locale,
    options?: DateTimeFormatOptions,
) => DateTimeFormat = formatterFromLocale

Returns a formatter for a given (discord.js) locale

Type declaration

    • (locale: Locale, options?: DateTimeFormatOptions): DateTimeFormat
    • Parameters

      • locale: Locale

        The locale to format the date for

      • Optionaloptions: DateTimeFormatOptions

        The formatting options, if any

      Returns DateTimeFormat

      The date formatter

hrTimeToMs: (hrTime: [number, number]) => number = hrTimeToMs

Converts a hrTime tuple to milliseconds

Type declaration

    • (hrTime: [number, number]): number
    • Parameters

      • hrTime: [number, number]

        The hrTime tuple

      Returns number

      The time in milliseconds

humanReadableMs: (
    ms: number,
    maxParts?: number,
    msDisplay?: string | (ms: number) => string,
) => string = humanReadableMs

Converts milliseconds to a human-readable format

Type declaration

    • (
          ms: number,
          maxParts?: number,
          msDisplay?: string | (ms: number) => string,
      ): string
    • Parameters

      • ms: number

        The time in milliseconds

      • maxParts: number = 2

        The maximum number of time units to include

      • msDisplay: string | (ms: number) => string = 'Just now'

      Returns string

      A human-readable string

occurrencesPerInterval: (dates: Date[], interval: number) => number = occurrencesPerInterval

Calculates the average number of occurrences per interval

Type declaration

    • (dates: Date[], interval: number): number
    • Parameters

      • dates: Date[]

        The dates to calculate the occurrences from

      • interval: number

        The interval to calculate the average for

      Returns number

      The average number of occurrences per interval

unix: (timestamp: number) => number = unix

Returns a Unix timestamp from a JavaScript timestamp

Type declaration

    • (timestamp: number): number
    • Parameters

      • timestamp: number

        The JavaScript timestamp

      Returns number

      The Unix timestamp

unixNow: () => number = unixNow

Returns the current time as a Unix timestamp

Type declaration

    • (): number
    • Returns number

      The current Unix timestamp