Light Dark

Types

Day

Day time unit. Wraps an Int value.

Duration

fn (iso: Str): Duration
fn (components: Map): Duration
Duration type {
    years: Dec,
    months: Dec,
    weeks: Dec,
    days: Dec,
    hours: Dec,
    minutes: Dec,
    seconds: Dec,
    milliseconds: Dec,
    microseconds: Dec,
    nanoseconds: Dec
}

A length of time. Can be used to add/subtract from dates and times.

Example

d ::hot::time/days(7)              // 7-day duration
d Duration({"hours": 2, "minutes": 30})  // 2h 30m duration
Str(d)                             // "PT2H30M"

Hour

Hour time unit. Wraps an Int value.

Instant

fn (epoch-millis: Millisecond): Instant
fn (epoch-micros: Microsecond): Instant
fn (epoch-nanos: Nanosecond): Instant
fn (plain-date: PlainDate): Instant
fn (plain-time: PlainTime): Instant
fn (plain-date-time: PlainDateTime): Instant
Instant type {
    epochNanoseconds: Int
}

An exact moment in time (UTC). Based on Temporal.Instant.

Example

now ::hot::time/now()           // Current instant
Str(now)                        // "2024-12-04T15:30:00Z"
::hot::time/epoch-millis(now)   // 1733324400000

Microsecond

Microsecond time unit. Wraps an Int value.

Millisecond

Millisecond time unit. Wraps an Int value.

Minute

Minute time unit. Wraps an Int value.

Month

Month time unit. Wraps an Int value.

Nanosecond

Nanosecond time unit. Wraps an Int value.

PlainDate

fn (): PlainDate
fn (date: Str): PlainDate
fn (year: Int, month: Int, day: Int): PlainDate
PlainDate type {
    year: Int,
    month: Int,
    day: Int,
    calendar: Str
}

A calendar date without time or timezone. Based on Temporal.PlainDate.

Example

today PlainDate()                   // Today's date
christmas PlainDate(2024, 12, 25)   // Specific date
parsed PlainDate("2024-12-25")      // From ISO string
Str(christmas)                      // "2024-12-25"

PlainDateTime

fn (): PlainDateTime
fn (datetime: Str): PlainDateTime
fn (year: Int, month: Int, day: Int, hour: Int, minute: Int, second: Int): PlainDateTime
PlainDateTime type {
    year: Int,
    month: Int,
    day: Int,
    hour: Int,
    minute: Int,
    second: Int,
    millisecond: Int,
    microsecond: Int,
    nanosecond: Int,
    calendar: Str
}

A date and time without timezone. Based on Temporal.PlainDateTime.

Example

now PlainDateTime()                            // Current date/time
party PlainDateTime(2024, 12, 31, 23, 59, 0)   // New Year's Eve
parsed PlainDateTime("2024-12-31T23:59:00")    // From ISO string
Str(party)                                     // "2024-12-31T23:59:00"

PlainTime

fn (): PlainTime
fn (time: Str): PlainTime
fn (hour: Int, minute: Int, second: Int): PlainTime
PlainTime type {
    hour: Int,
    minute: Int,
    second: Int,
    millisecond: Int,
    microsecond: Int,
    nanosecond: Int
}

A wall-clock time without date or timezone. Based on Temporal.PlainTime.

Example

now PlainTime()                  // Current time
noon PlainTime(12, 0, 0)         // Specific time
parsed PlainTime("14:30:00")     // From ISO string
Str(noon)                        // "12:00:00"

Second

Second time unit. Wraps an Int value.

Week

Week time unit. Wraps an Int value.

Year

Year time unit. Wraps an Int value.

Functions

add

fn (temporal: PlainDateTime, duration: Duration): PlainDateTime

Add a Duration to a PlainDateTime.

Example


dt ::hot::time/PlainDateTime(2024, 12, 25, 10, 0, 0)
::hot::time/add(dt, ::hot::time/days(7))  // 2025-01-01T10:00:00

day

fn (date: PlainDate | PlainDateTime): Int

Extract the day of month component (1-31).

Example


date ::hot::time/PlainDate(2024, 12, 25)
::hot::time/day(date)  // 25

days

fn (amount: Any): Duration

Create a Duration representing amount days.

Example


::hot::time/days(30)  // Duration of 30 days

end-of-day

fn (date: PlainDate | PlainDateTime): PlainDateTime

Return a PlainDateTime at 23:59:59 for the given date.

Example


date ::hot::time/PlainDate(2024, 12, 25)
::hot::time/end-of-day(date)  // 2024-12-25T23:59:59

epoch-millis

fn (instant: Instant): Int

Get milliseconds since Unix epoch for instant.

Example


ms ::hot::time/epoch-millis(::hot::time/now())
// 1733312400000

epoch-nanos

fn (instant: Instant): Int

Get nanoseconds since Unix epoch for instant.

Example


ns ::hot::time/epoch-nanos(::hot::time/now())
// 1733312400000000000

hour

fn (time: PlainTime | PlainDateTime): Int

Extract the hour component (0-23).

Example


time ::hot::time/PlainTime(14, 30, 0)
::hot::time/hour(time)  // 14

hours

fn (amount: Any): Duration

Create a Duration representing amount hours.

Example


::hot::time/hours(24)  // Duration of 24 hours

microsecond

fn (time: PlainTime | PlainDateTime): Int

Extract the microsecond component (0-999).

Example


time ::hot::time/PlainTime("14:30:45.123456")
::hot::time/microsecond(time)  // 456

millisecond

fn (time: PlainTime | PlainDateTime): Int

Extract the millisecond component (0-999).

Example


time ::hot::time/PlainTime("14:30:45.123")
::hot::time/millisecond(time)  // 123

minute

fn (time: PlainTime | PlainDateTime): Int

Extract the minute component (0-59).

Example


time ::hot::time/PlainTime(14, 30, 45)
::hot::time/minute(time)  // 30

minutes

fn (amount: Any): Duration

Create a Duration representing amount minutes.

Example


::hot::time/minutes(30)  // Duration of 30 minutes

month

fn (date: PlainDate | PlainDateTime): Int

Extract the month component (1-12).

Example


date ::hot::time/PlainDate(2024, 12, 25)
::hot::time/month(date)  // 12

months

fn (amount: Any): Duration

Create a Duration representing amount months.

Example


::hot::time/months(6)  // Duration of 6 months

nanosecond

fn (time: PlainTime | PlainDateTime): Int

Extract the nanosecond component (0-999).

Example


time ::hot::time/PlainTime("14:30:45.123456789")
::hot::time/nanosecond(time)  // 789

now

fn (): Instant

Get the current instant.

Example


current ::hot::time/now()
Str(current)  // "2024-12-04T10:30:00Z"

parse

fn (date-string: Str): PlainDateTime | PlainDate | PlainTime

Parse an ISO-like date/time string into PlainDateTime, PlainDate or PlainTime.

Example


::hot::time/parse("2024-12-25")           // PlainDate
::hot::time/parse("14:30:00")             // PlainTime
::hot::time/parse("2024-12-25T14:30:00")  // PlainDateTime

second

fn (time: PlainTime | PlainDateTime): Int

Extract the second component (0-59).

Example


time ::hot::time/PlainTime(14, 30, 45)
::hot::time/second(time)  // 45

seconds

fn (amount: Any): Duration

Create a Duration representing amount seconds.

Example


::hot::time/seconds(60)  // Duration of 60 seconds

since

fn (start: PlainDateTime, end: PlainDateTime): Duration

Return the Duration from end to start.

Example


start ::hot::time/PlainDateTime(2024, 1, 1, 0, 0, 0)
end ::hot::time/PlainDateTime(2024, 12, 31, 23, 59, 59)
duration ::hot::time/since(start, end)
// duration.days = -365

start-of-day

fn (date: PlainDate | PlainDateTime): PlainDateTime

Return a PlainDateTime at 00:00:00 for the given date.

Example


date ::hot::time/PlainDate(2024, 12, 25)
::hot::time/start-of-day(date)  // 2024-12-25T00:00:00

subtract

fn (temporal: PlainDateTime, duration: Duration): PlainDateTime

Subtract a Duration from a PlainDateTime.

Example


dt ::hot::time/PlainDateTime(2024, 12, 25, 10, 0, 0)
::hot::time/subtract(dt, ::hot::time/days(25))  // 2024-11-30T10:00:00

until

fn (start: PlainDateTime, end: PlainDateTime): Duration

Return the Duration from start to end.

Example


start ::hot::time/PlainDateTime(2024, 1, 1, 0, 0, 0)
end ::hot::time/PlainDateTime(2024, 12, 31, 23, 59, 59)
duration ::hot::time/until(start, end)
// duration.days = 365

weeks

fn (amount: Any): Duration

Create a Duration representing amount weeks.

Example


::hot::time/weeks(2)  // Duration of 2 weeks

year

fn (date: PlainDate | PlainDateTime): Int

Extract the year component.

Example


date ::hot::time/PlainDate(2024, 12, 25)
::hot::time/year(date)  // 2024

years

fn (amount: Any): Duration

Create a Duration representing amount years.

Example


::hot::time/years(2)  // Duration of 2 years