Constructor
constructor(initialDate: TimeResolvable = new Date())
Creates a new HolyTime instance.
initialDate
TimeResolvable
default:"new Date()"
The initial date/time value. Can be a HolyTime instance, Date object, number (timestamp), or string.
Static Properties
Units
Object containing time unit constants in milliseconds.
TimeZones
static TimeZones = TIMEZONES
Array of all supported timezone strings.
Days
Array of day names: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
Months
static Months = MONTH_NAMES
Array of month names: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
Static Methods
now()
Creates a HolyTime instance representing the current moment.
New HolyTime instance with current date/time
isValid()
static isValid(time: TimeResolvable): boolean
Checks if a time value is valid.
The time value to validate
True if the time is valid, false otherwise
add()
static add(time: TimeResolvable, amount: number, unit: HumanUnit = 'milliseconds'): HolyTime
Adds time to a given date and returns a new HolyTime instance.
unit
HumanUnit
default:"'milliseconds'"
The unit of time (e.g., ‘seconds’, ‘minutes’, ‘hours’, ‘days’, ‘weeks’, ‘months’, ‘years’)
New HolyTime instance with the added time
subtract()
static subtract(time: TimeResolvable, amount: number, unit: HumanUnit = 'milliseconds'): HolyTime
Subtracts time from a given date and returns a new HolyTime instance.
unit
HumanUnit
default:"'milliseconds'"
The unit of time
New HolyTime instance with the subtracted time
in()
static in(amount: number, unit: HumanUnit = 'milliseconds'): HolyTime
Creates a HolyTime instance representing a time in the future from now.
The amount of time in the future
unit
HumanUnit
default:"'milliseconds'"
The unit of time
New HolyTime instance representing the future time
between()
static between(timeA: TimeResolvable, timeB: TimeResolvable): HolyDuration
Calculates the absolute duration between two times.
Duration between the two times
isSame()
static isSame(timeA: TimeResolvable, timeB: TimeResolvable, unit: IntervalUnit = 'millisecond'): boolean
Checks if two times are the same at the specified unit precision.
unit
IntervalUnit
default:"'millisecond'"
Unit of precision (‘millisecond’, ‘second’, ‘minute’, ‘hour’, ‘day’, ‘week’, ‘month’, ‘year’)
True if times are the same at the specified precision
isWeekend()
static isWeekend(time: TimeResolvable): boolean
Checks if a given time falls on a weekend (Saturday or Sunday).
True if the time is on a weekend
isLeapYear()
static isLeapYear(year: number): boolean
Checks if a given year is a leap year.
The year to check (must be a positive integer)
True if the year is a leap year
isAfter()
static isAfter(timeA: TimeResolvable, timeB: TimeResolvable): boolean
Checks if timeA is after timeB.
True if timeA is after timeB
isBefore()
static isBefore(timeA: TimeResolvable, timeB: TimeResolvable): boolean
Checks if timeA is before timeB.
True if timeA is before timeB
isFuture()
static isFuture(time: TimeResolvable): boolean
Checks if a time is in the future.
True if the time is in the future
isPast()
static isPast(time: TimeResolvable): boolean
Checks if a time is in the past.
True if the time is in the past
since()
static since(time: TimeResolvable): HolyDuration
Calculates the duration since a given time until now.
Duration from the given time to now
max()
static max(...times: TimeResolvable[]): HolyTime
Returns the latest time from the provided times.
Variable number of times to compare
min()
static min(...times: TimeResolvable[]): HolyTime
Returns the earliest time from the provided times.
Variable number of times to compare
startOf()
static startOf(unit: IntervalUnit, time: TimeResolvable = new Date(), timeZone?: TimeZone): HolyTime
Returns the start of the specified time unit.
The unit (‘millisecond’, ‘second’, ‘minute’, ‘hour’, ‘day’, ‘week’, ‘month’, ‘year’)
time
TimeResolvable
default:"new Date()"
The reference time
Time representing the start of the unit
endOf()
static endOf(unit: IntervalUnit, time: TimeResolvable = new Date(), timeZone?: TimeZone): HolyTime
Returns the end of the specified time unit.
time
TimeResolvable
default:"new Date()"
The reference time
Time representing the end of the unit
static format(time: TimeResolvable, format: string | ((time: HolyTime) => string), timeZone?: TimeZone): string
Formats a time according to the specified format string or function.
format
string | ((time: HolyTime) => string)
required
Format string (e.g., ‘YYYY-MM-DD HH:mm:ss’) or custom formatter function
Format Tokens:
YYYY - 4-digit year
YY - 2-digit year
MMMM - Full month name
MMM - Short month name
MM - 2-digit month
M - Month number
DD - 2-digit day
D - Day number
DDDD - Full day name
HH - 2-digit hour (24h)
H - Hour (24h)
hh - 2-digit hour (12h)
h - Hour (12h)
mm - 2-digit minutes
m - Minutes
ss - 2-digit seconds
s - Seconds
A - AM/PM (uppercase)
a - am/pm (lowercase)
O - GMT offset (short)
OO - GMT offset (long)
TZ - Timezone name
relativeFromTo()
static relativeFromTo(timeA: TimeResolvable, timeB: TimeResolvable): string
Returns a human-readable relative time string between two times.
Relative time string (e.g., ‘5 minutes ago’, ‘in 2 hours’)
next()
static next(unit: IntervalUnit, time: TimeResolvable = new Date(), timeZone?: TimeZone): HolyTime
Returns the start of the next time unit.
time
TimeResolvable
default:"new Date()"
The reference time
Time representing the start of the next unit
duration()
static duration(amount: number, unit: HumanUnit = 'milliseconds'): HolyDuration
Creates a HolyDuration instance.
unit
HumanUnit
default:"'milliseconds'"
The unit of time
New HolyDuration instance
getTimeZone()
static getTimeZone(): TimeZone
Returns the system’s current timezone.
Instance Methods
add()
add(amount: number, unit: HumanUnit = 'milliseconds'): this
Adds time to this instance (mutates).
unit
HumanUnit
default:"'milliseconds'"
The unit of time
This instance for chaining
subtract()
subtract(amount: number, unit: HumanUnit = 'milliseconds'): this
Subtracts time from this instance (mutates).
unit
HumanUnit
default:"'milliseconds'"
The unit of time
This instance for chaining
isSame()
isSame(time: TimeResolvable, unit: IntervalUnit = 'millisecond'): boolean
Checks if this time is the same as another time at the specified precision.
unit
IntervalUnit
default:"'millisecond'"
Unit of precision
True if times are the same
isWeekend()
Checks if this time falls on a weekend.
True if this time is on a weekend
isLeapYear()
isLeapYear(time: TimeResolvable): boolean
Checks if this time’s year is a leap year.
True if the year is a leap year
isAfter()
isAfter(time: TimeResolvable): boolean
Checks if this time is after another time.
True if this time is after the given time
isBefore()
isBefore(time: TimeResolvable): boolean
Checks if this time is before another time.
True if this time is before the given time
isFuture()
Checks if this time is in the future.
True if this time is in the future
isPast()
Checks if this time is in the past.
True if this time is in the past
startOf()
startOf(unit: IntervalUnit, timeZone?: TimeZone): HolyTime
Returns the start of the specified time unit for this instance.
Time representing the start of the unit
endOf()
endOf(unit: IntervalUnit, timeZone?: TimeZone): HolyTime
Returns the end of the specified time unit for this instance.
Time representing the end of the unit
format(format: string, timeZone?: TimeZone): string
Formats this time according to the specified format string.
next()
next(unit: IntervalUnit, timeZone?: TimeZone): HolyTime
Returns the start of the next time unit for this instance.
Time representing the start of the next unit
get()
get<T extends 'object' | GetUnit>(unit: T, timeZone?: TimeZone): T extends 'object' ? Record<GetUnit, number> : number
Gets a specific time component or all components as an object.
unit
'object' | GetUnit
required
The unit to get (‘millisecond’, ‘second’, ‘minute’, ‘hour’, ‘day’, ‘week’, ‘month’, ‘year’, or ‘object’ for all)
return
number | Record<GetUnit, number>
The component value or object with all components
set()
set(unit: GetUnit, value: number): this
Sets a specific time component (mutates).
This instance for chaining
getDate()
Returns the underlying Date object.
The underlying Date instance
getTime()
Returns the timestamp in milliseconds.
Timestamp in milliseconds
getUnixTime()
Returns the Unix timestamp in seconds.
Unix timestamp in seconds
getISOString()
Returns the ISO 8601 string representation.
ISO 8601 formatted string
clone()
Creates a copy of this HolyTime instance.
New HolyTime instance with the same time
getRelativeTo()
getRelativeTo(time: TimeResolvable): string
Returns a human-readable relative time string from this time to another time.
getRelativeFrom()
getRelativeFrom(time: TimeResolvable): string
Returns a human-readable relative time string from another time to this time.