@rvoh/dream
    Preparing search index...

    Class ClockTimeTz

    ClockTimeTz represents a time of day with timezone information.

    Useful for representing TIME WITH TIME ZONE fields from a Postgres database. All output methods include timezone offset information.

    Hierarchy

    • default
      • ClockTimeTz
    Index

    Constructors

    Properties

    _toSQL?: string
    dateTime: DateTime

    Accessors

    • get hour(): number

      Gets the hour (0-23).

      Returns number

      The hour number

      ClockTime/ClockTimeTz.fromObject({ hour: 14, minute: 30 }).hour  // 14
      
    • get microsecond(): number

      Gets the microsecond (0-999).

      Returns number

      The microsecond number

      ClockTime/ClockTimeTz.fromISO('14:30:45.123456').microsecond  // 456
      
    • get millisecond(): number

      Gets the millisecond (0-999).

      Returns number

      The millisecond number

      ClockTime/ClockTimeTz.fromObject({ hour: 14, minute: 30, millisecond: 123 }).millisecond  // 123
      
    • get minute(): number

      Gets the minute (0-59).

      Returns number

      The minute number

      ClockTime/ClockTimeTz.fromObject({ hour: 14, minute: 30 }).minute  // 30
      
    • get offset(): number

      Gets the timezone offset in minutes.

      Returns number

      The offset in minutes

      ClockTimeTz.fromISO('14:30:45-05:00').offset  // -300
      
    • get second(): number

      Gets the second (0-59).

      Returns number

      The second number

      ClockTime/ClockTimeTz.fromObject({ hour: 14, minute: 30, second: 45 }).second  // 45
      
    • get zoneName(): string

      Gets the timezone name.

      Returns string

      The timezone name

      ClockTimeTz.fromObject({ hour: 14 }, { zone: 'America/New_York' }).zoneName
      

    Methods

    • Returns the difference between this ClockTime and another in the specified unit(s). Supports microsecond precision when 'microseconds' is included in the unit parameter.

      Type Parameters

      • T extends BaseClockTime
      • U extends ClockTimeDurationUnit | ClockTimeDurationUnit[] | undefined = undefined

      Parameters

      • this: T
      • other: T

        ClockTime to compare against

      • Optionalunit: U

        Unit or units to return (hours, minutes, seconds, milliseconds, microseconds)

      Returns ClockTimeDiffResult<U>

      Object with only the specified units (or all units if not specified)

      const t1 = ClockTime.fromObject({ hour: 15, minute: 30 })
      const t2 = ClockTime.fromObject({ hour: 14, minute: 0 })
      t1.diff(t2, 'hours') // { hours: 1 }
      t1.diff(t2, ['hours', 'minutes']) // { hours: 1, minutes: 30 }
      t1.diff(t2) // { hours: 1, minutes: 30, seconds: 0, milliseconds: 0, microseconds: 0 }
    • Returns a new ClockTime at the end of the given period.

      Type Parameters

      • T extends BaseClockTime

      Parameters

      • this: T
      • period: ClockTimeUnit

        Unit to extend to end of ('hour', 'minute', or 'second')

      Returns T

      A ClockTime at the end of the period

      ClockTime.fromObject({ hour: 14, minute: 30 }).endOf('hour')
      // hour: 14, minute: 59, second: 59, millisecond: 999
    • Returns true if this ClockTime equals another ClockTime.

      Type Parameters

      • T extends BaseClockTime

      Parameters

      • this: T
      • otherClockTime: T

        ClockTime to compare

      Returns boolean

      true if times are equal

      const t1 = ClockTime.fromObject({ hour: 14, minute: 30 })
      const t2 = ClockTime.fromObject({ hour: 14, minute: 30 })
      t1.equals(t2) // true
    • Returns true if this and other are in the same unit of time.

      Type Parameters

      • T extends BaseClockTime

      Parameters

      • this: T
      • otherClockTime: T

        ClockTime to compare against

      • period: ClockTimeUnit

        Unit to check ('hour', 'minute', or 'second')

      Returns boolean

      true if same period

      const t1 = ClockTime.fromObject({ hour: 14, minute: 30 })
      const t2 = ClockTime.fromObject({ hour: 14, minute: 45 })
      t1.hasSame(t2, 'hour') // true
      t1.hasSame(t2, 'minute') // false
    • Returns a new ClockTime/ClockTimeTz with the given duration subtracted.

      Type Parameters

      • T extends BaseClockTime

      Parameters

      • this: T
      • duration: ClockTimeDurationLikeObject

        Duration to subtract (object with hours, minutes, seconds, etc.)

      Returns T

      A new ClockTime/ClockTimeTz

      ClockTime/ClockTimeTz.fromObject({ hour: 14, minute: 30 }).minus({ hours: 2, minutes: 15 })
      // hour: 12, minute: 15
    • Returns a new ClockTime/ClockTimeTz with the given duration added.

      Type Parameters

      • T extends BaseClockTime

      Parameters

      • this: T
      • duration: ClockTimeDurationLikeObject

        Duration to add (object with hours, minutes, seconds, etc.)

      Returns T

      A new ClockTime/ClockTimeTz

      ClockTime/ClockTimeTz.fromObject({ hour: 14, minute: 30 }).plus({ hours: 2, minutes: 15 })
      // hour: 16, minute: 45
    • Returns a new ClockTime with the given time units set.

      Type Parameters

      • T extends BaseClockTime

      Parameters

      • this: T
      • values: Partial<ClockTimeObject>

        Object with time units to set (hour, minute, second, millisecond, microsecond)

      Returns T

      A new ClockTime

      When the underlying DateTime operation fails

      ClockTime.fromObject({ hour: 10, minute: 30 }).set({ hour: 14, microsecond: 500 })
      // hour: 14, minute: 30, microsecond: 500
    • Returns a new ClockTimeTz with the timezone changed. The time value changes to reflect the same instant in the new timezone.

      Parameters

      • zone: string | Zone

        The timezone to convert to

      Returns ClockTimeTz

      A new ClockTimeTz in the specified timezone

      const utc = ClockTimeTz.fromObject({ hour: 14, minute: 30 }, { zone: 'UTC' })
      const ny = utc.setZone('America/New_York')
      // Time is converted to New York timezone (e.g., 09:30 EST)
    • Returns a new ClockTime at the start of the given period.

      Type Parameters

      • T extends BaseClockTime

      Parameters

      • this: T
      • period: ClockTimeUnit

        Unit to truncate to ('hour', 'minute', or 'second')

      Returns T

      A ClockTime at the start of the period

      ClockTime.fromObject({ hour: 14, minute: 30, second: 45 }).startOf('hour')
      // hour: 14, minute: 0, second: 0
    • Returns the underlying DateTime instance.

      Returns DateTime

      A DateTime representing this time with zone

      const dt = ClockTime/ClockTimeTz.now().toDateTime()
      
    • Returns the time as an ISO 8601 time string with timezone offset. Alias for toISOTime().

      Parameters

      • Optionalopts: {
            format?: "basic" | "extended";
            suppressMilliseconds?: boolean;
            suppressSeconds?: boolean;
        }

        Optional format options

        • Optionalformat?: "basic" | "extended"

          Format variant: 'basic' (compact) or 'extended' (default, with colons)

        • OptionalsuppressMilliseconds?: boolean

          If true, omits milliseconds/microseconds when they are zero

        • OptionalsuppressSeconds?: boolean

          If true, omits seconds when they are zero

      Returns string

      ISO time string with timezone offset (e.g., '14:30:45.123456-05:00')

      ClockTimeTz.fromObject({ hour: 14, minute: 30, second: 45 }).toISO()  // '14:30:45.000000+00:00'
      ClockTimeTz.fromISO('14:30:45-05:00').toISO() // '14:30:45.000000-05:00'
    • Returns the time as an ISO 8601 time string with timezone offset. Alias for toISO().

      Parameters

      • Optionalopts: {
            format?: "basic" | "extended";
            suppressMilliseconds?: boolean;
            suppressSeconds?: boolean;
        }

        Optional format options

        • Optionalformat?: "basic" | "extended"

          Format variant: 'basic' (compact) or 'extended' (default, with colons)

        • OptionalsuppressMilliseconds?: boolean

          If true, omits milliseconds/microseconds when they are zero

        • OptionalsuppressSeconds?: boolean

          If true, omits seconds when they are zero

      Returns string

      ISO time string with timezone offset (e.g., '14:30:45.123456-05:00')

      ClockTime/ClockTimeTz.fromObject({ hour: 14, minute: 30, second: 45 }).toISOTime()  // '14:30:45.000000+00:00'
      ClockTime/ClockTimeTz.fromISO('14:30:45-05:00').toISOTime() // '14:30:45.000000-05:00'
    • Returns the time as an ISO time string for JSON serialization.

      Returns string

      ISO time string

      JSON.stringify({ time: ClockTime.now() })
      
    • Returns a localized string representation of the time.

      Parameters

      • OptionalformatOpts: DateTimeFormatOptions

        Intl.DateTimeFormat options for formatting

      • Optionalopts: LocaleOptions

        Optional locale configuration

        • locale

          Locale string (e.g., 'en-US', 'fr-FR')

        • numberingSystem

          Numbering system (e.g., 'arab', 'beng')

        • outputCalendar

          Calendar system (e.g., 'islamic', 'hebrew')

      Returns string

      Localized time string

      ClockTime/ClockTimeTz.now().toLocaleString()
      ClockTime/ClockTimeTz.now().toLocaleString({ hour: 'numeric', minute: '2-digit' })
      ClockTime/ClockTimeTz.now().toLocaleString({ hour: '2-digit' }, { locale: 'fr-FR' })
    • Returns the SQL time string with timezone offset. Result is memoized for performance.

      Returns string

      SQL time string with timezone offset (e.g., '14:30:45.123456 -05:00')

      ClockTimeTz.fromISO('14:30:45-05:00').toSQL()  // '14:30:45.000000 -05:00'
      
    • Alias of toSQL. Returns the SQL time string without timezone offset. Result is memoized for performance.

      Returns string

      SQL time string without timezone offset (e.g., '14:30:45.123456')

    • Returns the time as an ISO string (same as toISO).

      Returns string

      ISO datetime string

      ClockTime.now().toString()
      
    • Create a ClockTimeTz from a DateTime instance.

      Type Parameters

      • T extends typeof default

      Parameters

      • this: T
      • dateTime: DateTime

        A DateTime instance

      Returns InstanceType<T>

      A ClockTimeTz for the time portion of the DateTime

      ClockTime/ClockTimeTz.fromDateTime(DateTime.now())
      
    • Create a ClockTimeTz from a custom format string. Uses Luxon format tokens (e.g., 'HH:mm:ss', 'hh:mm a').

      Parameters

      • text: string

        The string to parse

      • format: string

        Format string using Luxon tokens

      • Optionalopts: DateTimeOptions

        Optional configuration

        • zone

          Timezone to interpret the time in (IANA timezone name or Zone object)

        • locale

          Locale for parsing (e.g., 'en-US', 'fr-FR')

        • numberingSystem

          Numbering system (e.g., 'arab', 'beng')

        • outputCalendar

          Output calendar system (e.g., 'islamic', 'hebrew')

      Returns ClockTimeTz

      A ClockTimeTz for the parsed time

      When the string doesn't match the format or is invalid

      ClockTimeTz.fromFormat('14:30:45', 'HH:mm:ss')
      ClockTimeTz.fromFormat('2:30 PM', 'h:mm a')
      ClockTimeTz.fromFormat('14:30:45 -05:00', 'HH:mm:ss ZZ')
    • Create a ClockTimeTz from an ISO 8601 time string. If the string includes timezone information, it will be used. If no timezone is in the string, it will be interpreted as UTC.

      Parameters

      • str: string

        ISO time string (e.g., '14:30:45.123456-05:00')

      • opts: { zone?: string | Zone } = {}

      Returns ClockTimeTz

      A ClockTimeTz for the given time

      When the ISO string is invalid

      ClockTimeTz.fromISO('14:30:45.123456')        // Interpreted as UTC
      ClockTimeTz.fromISO('14:30:45.123456-05:00') // Uses timezone from string
    • Create a ClockTimeTz from a JavaScript Date.

      Parameters

      • javascriptDate: Date

        A JavaScript Date instance

      • opts: { zone?: string | Zone } = {}

      Returns ClockTimeTz

      A ClockTimeTz for the time portion

      ClockTimeTz.fromJSDate(new Date())
      ClockTimeTz.fromJSDate(new Date(), { zone: 'America/New_York' })
    • Create a ClockTimeTz from an object with time units.

      Parameters

      • obj: Partial<ClockTimeObject>

        Object with hour, minute, second, millisecond, microsecond properties

      • Optionalopts: DateTimeJSOptions

        Optional configuration

        • zone

          Timezone for the time (IANA timezone name or Zone object, defaults to UTC)

        • locale

          Locale (e.g., 'en-US', 'fr-FR')

        • numberingSystem

          Numbering system (e.g., 'arab', 'beng')

        • outputCalendar

          Output calendar system (e.g., 'islamic', 'hebrew')

      Returns ClockTimeTz

      A ClockTimeTz for the given components

      When time values are invalid

      ClockTimeTz.fromObject({ hour: 14, minute: 30, second: 45 })  // UTC by default

      // Note for when sending a named, non-UTC time zone, soch as 'America/New_York':
      // Sending a non-UTC time zone will interpret the time zone based on DateTime.now,
      // meaning the resulting ClockTimeTz will have a different time and offset when
      // generated during daylight savings time than not during daylight savings time
      ClockTimeTz.fromObject({ hour: 14, minute: 30 }, { zone: 'America/New_York' })
    • Create a ClockTimeTz from an SQL time string. If no zone option is provided, the time will be interpreted as UTC.

      Parameters

      • str: string

        SQL time string (e.g., '14:30:45.123456')

      • opts: { zone?: string | Zone } = {}

      Returns ClockTimeTz

      A ClockTimeTz for the given time

      When the SQL string is invalid

      ClockTimeTz.fromSQL('14:30:45.123456')                    // Interpreted as UTC
      ClockTimeTz.fromSQL('14:30:45.123456+05:30') // Uses timezone from string
      ClockTimeTz.fromSQL('14:30:45', { zone: 'America/Chicago' }) // Uses specified zone
    • Returns the latest ClockTime/ClockTimeTz from the given arguments.

      Type Parameters

      • T extends typeof default

      Parameters

      • this: T
      • ...clockTimes: InstanceType<T>[]

        ClockTime/ClockTimeTz instances to compare

      Returns InstanceType<T> | null

      The latest ClockTime/ClockTimeTz

      ClockTime/ClockTimeTz.max(time1, time2, time3)
      
    • Returns the earliest ClockTime/ClockTimeTz from the given arguments.

      Type Parameters

      • T extends typeof default

      Parameters

      • this: T
      • ...clockTimes: InstanceType<T>[]

        ClockTime/ClockTimeTz instances to compare

      Returns InstanceType<T> | null

      The earliest ClockTime/ClockTimeTz

      ClockTime/ClockTimeTz.min(time1, time2, time3)