@rvoh/dream
    Preparing search index...

    Class ClockTime

    ClockTime represents a time of day without timezone information.

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

    Hierarchy

    • default
      • ClockTime
    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 second(): number

      Gets the second (0-59).

      Returns number

      The second number

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

    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 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 without 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 without timezone offset (e.g., '14:30:45.123456')

      ClockTime.fromObject({ hour: 14, minute: 30, second: 45 }).toISO()  // '14:30:45.000000'
      ClockTime.fromISO('14:30:45-05:00').toISO() // '14:30:45.000000' (timezone stripped)
    • 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 without timezone offset. Result is memoized for performance.

      Returns string

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

      ClockTime.fromISO('14:30:45').toSQL()  // '14:30:45.000000'
      
    • 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 ClockTime 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: LocaleOptions

        Optional configuration

        • 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 ClockTime

      A ClockTime for the parsed time

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

      ClockTime.fromFormat('14:30:45', 'HH:mm:ss')
      ClockTime.fromFormat('2:30 PM', 'h:mm a')
    • Create a ClockTime from an ISO 8601 time string. Preserves the time values as-is, regardless of any timezone info in the string.

      Parameters

      • str: string

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

      Returns ClockTime

      A ClockTime for the given time

      When the ISO string is invalid

      ClockTime.fromISO('14:30:45.123456')      // stores 14:30:45.123456
      ClockTime.fromISO('14:30:45.123456-05:00') // stores 14:30:45.123456 (timezone ignored)
    • Create a ClockTime from a JavaScript Date.

      Parameters

      • javascriptDate: Date

        A JavaScript Date instance

      Returns ClockTime

      A ClockTime for the time portion

      ClockTime.fromJSDate(new Date())
      
    • Create a ClockTime from an object with time units.

      Parameters

      • obj: Partial<ClockTimeObject>

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

      • Optionalopts: LocaleOptions

        Optional configuration

        • locale

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

        • numberingSystem

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

        • outputCalendar

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

      Returns ClockTime

      A ClockTime for the given components

      When time values are invalid

      ClockTime.fromObject({ hour: 14, minute: 30, second: 45 })
      ClockTime.fromObject({ hour: 14, minute: 30 })
    • Create a ClockTime from an SQL time string. Preserves the time values as-is, regardless of any timezone info in the string.

      Parameters

      • str: string

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

      Returns ClockTime

      A ClockTime for the given time

      When the SQL string is invalid

      ClockTime.fromSQL('14:30:45.123456')       // stores 14:30:45.123456
      ClockTime.fromSQL('14:30:45.123456+05:30') // stores 14:30:45.123456 (timezone ignored)
    • 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)