Date and Duration
Dates, times, time zones and durations.
Always available
No import needed. These names are in scope in every file.
Duration struct
ts
struct DurationDuration.make
ts
static make(t: float): DurationInternal: the raw constructor (a struct literal must live inside its own struct).
Duration.days
ts
get days(): floatWhole days, floor (the part of us that is a multiple of a day).
Duration.micros
ts
get micros(): floatMicroseconds into that day, 0..86,399,999,999.
Duration.ofMicros
ts
static ofMicros(n: float): DurationA number of microseconds.
Duration.ofMs
ts
static ofMs(n: float): DurationA number of milliseconds.
Duration.ofSeconds
ts
static ofSeconds(n: float): DurationA number of seconds.
Duration.ofMinutes
ts
static ofMinutes(n: float): DurationA number of minutes.
Duration.ofHours
ts
static ofHours(n: float): DurationA number of hours.
Duration.ofDays
ts
static ofDays(n: float): DurationA number of days.
Duration.ofWeeks
ts
static ofWeeks(n: float): DurationA number of weeks.
Duration.parse
ts
static parse(s: string): DurationA duration text such as "1h30m"; throws RangeError when it is not one.
Other members of Duration
ts
us: float
static x_mkDur(days: float, us: float): Duration
static x_durFromMicros(us: float): Duration
static x_parseDurationText(s0: string): Duration | null
static readonly zero: Duration
static tryParse(s: string): Duration | null
get totalMicros(): float
get totalMs(): float
get totalSeconds(): float
get totalMinutes(): float
get totalHours(): float
get totalDays(): float
get totalWeeks(): float
get isNegative(): boolean
get isZero(): boolean
absParts(): Array<float>
signOf(v: float): float
get dayPart(): float
get hourPart(): float
get minutePart(): float
get secondPart(): float
get msPart(): float
get usPart(): float
plus(o: Duration): Duration
minus(o: Duration): Duration
times(k: float): Duration
over(k: float): Duration
negated(): Duration
absolute(): Duration
adopt(o: Duration): Duration
add(o: Duration): Duration
subtract(o: Duration): Duration
multiply(k: float): Duration
divide(k: float): Duration
negate(): Duration
abs(): Duration
round(unit: string): Duration
truncate(unit: string): Duration
rounded(unit: string, mode: int): Duration
compare(o: Duration): int
equals(o: Duration): boolean
toString(): string
toJSON(): string
format(pattern: string): string
operator lt(o: Duration): boolean
operator lte(o: Duration): boolean
operator gt(o: Duration): boolean
operator gte(o: Duration): boolean
operator eq(o: Duration): booleanDate struct
ts
struct DateDate.make
ts
static make(t: float, off: int, zone: int): DateInternal: the raw constructor (a struct literal must live inside its own struct).
Date.epochDay
ts
get epochDay(): floatFloor days since 1970-01-01 of the instant.
Date.microsOfDay
ts
get microsOfDay(): floatMicroseconds into that UTC day, 0..86,399,999,999.
Date.nowMs
ts
static nowMs(): floatEpoch milliseconds as a number (the JS Date.now()); Date.now() is the Date.
Example
ts
const started: float = Date.nowMs();
console.log(Date.nowMs() >= started); // trueDate.now
ts
static now(): DateThe current time, shown in the local zone.
Example
ts
const stamp: Date = Date.now();
console.log(stamp.year >= 2026); // trueDate.today
ts
static today(): DateMidnight at the start of today, in the local zone.
Date.fromEpochMicros
ts
static fromEpochMicros(us: float): DateEpoch microseconds.
Date.fromEpochMs
ts
static fromEpochMs(ms: float): DateEpoch milliseconds.
Date.fromEpochSeconds
ts
static fromEpochSeconds(s: float): DateEpoch seconds.
Date.from
ts
static from(y: int, mo: int, d: int, h: int = 0, mi: int = 0, s: int = 0, ms: int = 0, zone: any = "local"): DateCalendar fields, with an optional zone as the last argument.
Date.utc
ts
static utc(y: int, mo: int, d: int, h: int = 0, mi: int = 0, s: int = 0, ms: int = 0): DateCalendar fields read as UTC.
Date.parse
ts
static parse(s: string): DateA date string; throws RangeError when it is not a date.
Date.parseFormat
ts
static parseFormat(s: string, pattern: string, zone: any = "local"): DateA string in a format pattern; throws RangeError on a mismatch. Fields the pattern lacks default to 1970-01-01 00:00:00 in zone.
Date.epochMicrosExact
ts
get epochMicrosExact(): floatFloat alias for epoch microseconds. Exact to 1 us only within about +-285 years (2^53 us).
Date.fromEpochMicrosExact
ts
static fromEpochMicrosExact(t: float): DateFloat alias constructor. Exact to 1 us only within about +-285 years; RangeError outside the int64-us range.
Date.isZoneResolved
ts
get isZoneResolved(): booleanFalse when the zone name came from a loaded value and the tz database does not know it.
Date.addYears
ts
addYears(n: float, mode: string = "clamp"): Datemode "clamp" (default: Jan 31 + 1 month = Feb 28/29) or "overflow" (rolls: Mar 3).
Date.modify
ts
modify(relative: string): DateMutates by a relative phrase ("+1 week", "tomorrow", "next monday", "first day of next month", "noon", "2 days ago"); an unknown word throws.
Date.nextTransition
ts
nextTransition(): Date | nullThe next / previous DST or offset change in this Date's zone (null for a fixed offset or a zone without changes).
Date.toZone
ts
toZone(zone: any): DateSame instant, shown in another zone.
Date.withZoneKeepLocal
ts
withZoneKeepLocal(zone: any): DateSame wall-clock reading in another zone (the instant changes).
Date.diffIn
ts
diffIn(o: Date, unit: string): intWhole units from o to this, truncated toward zero (elapsed, not boundaries crossed).
Date.diffBoundaries
ts
diffBoundaries(o: Date, unit: string): intCalendar boundaries of unit crossed between o and this (VB DateDiff).
Other members of Date
ts
utcUs: float
offMin: int16
zoneId: uint16
static x_mk(day: float, us: float, off: int, zone: int): Date
static x_calendarAddMonths(d: Date, months: float, overflow: boolean = false): Date
static x_addUnit(d: Date, n0: float, unit: string, overflow: boolean = false): Date
static x_epochSecOf(d: Date): float
static x_wallDayOf(d: Date): float
static x_wallUsOf(d: Date): float
static x_reoffset(day: float, us: float, zone: int, fixedOff: int): Date
static x_fromWall(wallDay: float, wallUs: float, fixedOff: int, zone: int): Date
static x_addDuration(d: Date, du: Duration): Date
static x_startOfUnit(d: Date, unit: string, weekStart: int): Date
static x_setWall(d: Date, y: float, mo: float, dd: float, h: float, mi: float, s: float, us: float): Date
static x_weekInfo(d: Date): Array<float>
static x_zoneNameOf(d: Date): string
static x_abbrOf(d: Date): string
static x_formatDate(d: Date, pattern: string): string
static x_isoText(d: Date, digits: int): string
static x_parseIso(s0: string): Date | null
static x_parseRfc(s0: string): Date | null
static x_addWeekdaysOf(d: Date, n: int): Date
static x_nextWeekdayOf(d: Date, dow: int): Date
static x_prevWeekdayOf(d: Date, dow: int): Date
static x_modify(d0: Date, text: string): Date
static x_parseFormat(s: string, pattern: string, zone: any): Date | null
static x_transition(d: Date, dir: int): Date | null
static x_parseAny(s: string): Date | null
static readonly ISO: string
static readonly RFC3339: string
static readonly RFC2822: string
static readonly HTTP: string
static readonly DATE: string
static readonly TIME: string
static readonly DATETIME: string
static readonly KITCHEN: string
static readonly LONG_DATE: string
static readonly SHORT_DATE: string
static readonly LONG_TIME: string
static readonly SHORT_TIME: string
static readonly GENERAL: string
static readonly epoch: Date
static nowMicros(): float
static tryParse(s: string): Date | null
static tryParseFormat(s: string, pattern: string, zone: any = "local"): Date | null
static since(d: Date): Duration
static until(d: Date): Duration
static isLeapYear(y: int): boolean
static monthLength(y: int, m: int): int
static dayName(n: int): string
static monthName(n: int): string
static compareDates(a: Date, b: Date): int
static min(a: Date, b: Date): Date
static max(a: Date, b: Date): Date
static zones(): Array<string>
static localZone(): string
static isValidZone(name: string): boolean
static offsetAt(zone: string, instant: Date): int
get epochMicros(): float
get epochMs(): float
get epochSeconds(): float
get year(): int
get month(): int
get day(): int
get hour(): int
get minute(): int
get second(): int
get ms(): int
get us(): int
get microsOfSecond(): int
get dayOfWeek(): int
get dayOfWeekSun(): int
get dayOfYear(): int
get weekOfYear(): int
get isoYear(): int
get quarter(): int
get daysInMonth(): int
get daysInYear(): int
get inLeapYear(): boolean
get offsetMinutes(): int
get offset(): string
get zone(): string
get zoneAbbr(): string
get isDST(): boolean
get isUTC(): boolean
get isWeekend(): boolean
get isToday(): boolean
toOffsetOf(o: Date): Date
adopt(o: Date): Date
copy(): Date
addQuarters(n: float, mode: string = "clamp"): Date
addMonths(n: float, mode: string = "clamp"): Date
addWeeks(n: float): Date
addDays(n: float): Date
addHours(n: float): Date
addMinutes(n: float): Date
addSeconds(n: float): Date
addMs(n: float): Date
addMicros(n: float): Date
addWeekdays(n: int): Date
plusRelative(relative: string): Date
prevTransition(): Date | null
add(du: Duration): Date
subtract(du: Duration): Date
addUnit(n: float, unit: string, mode: string = "clamp"): Date
plus(du: Duration): Date
minus(du: Duration): Date
plusUnit(n: float, unit: string, mode: string = "clamp"): Date
minusUnit(n: float, unit: string, mode: string = "clamp"): Date
setYear(y: int, mo: int = 0, d: int = 0): Date
setMonth(mo: int, d: int = 0): Date
setDay(d: int): Date
setDate(y: int, mo: int, d: int): Date
setHour(h: int, mi: int = -1, s: int = -1, ms: int = -1): Date
setMinute(mi: int, s: int = -1, ms: int = -1): Date
setSecond(s: int, ms: int = -1): Date
setMs(ms: int): Date
setMicros(us: int): Date
setTime(h: int, mi: int = 0, s: int = 0, ms: int = 0): Date
setEpochMs(ms: float): Date
setEpochMicros(us: float): Date
withYear(n: int): Date
withMonth(n: int): Date
withDay(n: int): Date
withHour(n: int): Date
withMinute(n: int): Date
withSecond(n: int): Date
withMs(n: int): Date
withMicros(n: int): Date
toUTC(): Date
toLocal(): Date
toOffset(off: any): Date
compare(o: Date): int
equals(o: Date): boolean
isBefore(o: Date): boolean
isAfter(o: Date): boolean
isBetween(a: Date, b: Date): boolean
isSame(o: Date, unit: string): boolean
diff(o: Date): Duration
diffMs(o: Date): float
diffMicros(o: Date): float
age(): Duration
startOf(unit: string, weekStart: int = 1): Date
endOf(unit: string, weekStart: int = 1): Date
round(unit: string): Date
firstDayOfMonth(): Date
lastDayOfMonth(): Date
nextWeekday(dow: int): Date
prevWeekday(dow: int): Date
nthWeekdayOfMonth(n: int, dow: int): Date
format(pattern: string, zone: any = null): string
toISO(digits: int = 3): string
toString(): string
toJSON(): string
toDateString(): string
toTimeString(): string
toUTCString(): string
toUnix(): float
operator lt(o: Date): boolean
operator lte(o: Date): boolean
operator gt(o: Date): boolean
operator gte(o: Date): boolean
operator eq(o: Date): booleanGenerated from lang/date/index.tks in the ThicketScript repository.