luxon

3.5.0

possiblyCachedWeekData

possiblyCachedWeekData(dt: DateTime)
Parameters
dt (DateTime)

possiblyCachedLocalWeekData

possiblyCachedLocalWeekData(dt: DateTime)
Parameters
dt (DateTime)

zoneOffsetTs

Timestamp to use for cached zone offset guesses (exposed for test)

zoneOffsetTs

zoneOffsetGuessCache

Cache for zone offset guesses (exposed for test).

This optimizes quickDT via guessOffsetForZone to avoid repeated calls of zone.offset().

zoneOffsetGuessCache

DateTime

A DateTime is an immutable data structure representing a specific date and time and accompanying methods. It contains class and instance methods for creating, parsing, interrogating, transforming, and formatting them.

A DateTime comprises of:

  • A timestamp. Each DateTime instance refers to a specific millisecond of the Unix epoch.
  • A time zone. Each instance is considered in the context of a specific zone (by default the local system's zone).
  • Configuration properties that effect how output strings are formatted, such as locale, numberingSystem, and outputCalendar.

Here is a brief overview of the most commonly used functionality it provides:

There's plenty others documented below. In addition, for more information on subtler topics like internationalization, time zones, alternative calendars, validity, and so on, see the external documentation.

new DateTime(config: any)
Parameters
config (any)
Static Members
now()
local(year?, month, day, hour, minute, second, millisecond)
utc(year?, month, day, hour, minute, second, millisecond, options)
fromJSDate(date, options)
fromMillis(milliseconds, options)
fromSeconds(seconds, options)
fromObject(obj, opts)
fromISO(text, opts)
fromRFC2822(text, opts)
fromHTTP(text, opts)
fromFormat(text, fmt, opts)
fromString(text, fmt, opts)
fromSQL(text, opts)
invalid(reason, explanation)
isDateTime(o)
parseFormatForOpts(formatOpts, localeOpts)
expandFormat(fmt, localeOpts)
min(dateTimes)
max(dateTimes)
fromFormatExplain(text, fmt, options)
fromStringExplain(text, fmt, options)
buildFormatParser(fmt, options)
fromFormatParser(text, formatParser, opts)
DATE_SHORT
DATE_MED
DATE_MED_WITH_WEEKDAY
DATE_FULL
DATE_HUGE
TIME_SIMPLE
TIME_WITH_SECONDS
TIME_WITH_SHORT_OFFSET
TIME_WITH_LONG_OFFSET
TIME_24_SIMPLE
TIME_24_WITH_SECONDS
TIME_24_WITH_SHORT_OFFSET
TIME_24_WITH_LONG_OFFSET
DATETIME_SHORT
DATETIME_SHORT_WITH_SECONDS
DATETIME_MED
DATETIME_MED_WITH_SECONDS
DATETIME_MED_WITH_WEEKDAY
DATETIME_FULL
DATETIME_FULL_WITH_SECONDS
DATETIME_HUGE
DATETIME_HUGE_WITH_SECONDS
Instance Members
get(unit)
isValid
invalidReason
invalidExplanation
locale
numberingSystem
outputCalendar
zone
zoneName
year
quarter
month
day
hour
minute
second
millisecond
weekYear
weekNumber
weekday
isWeekend
localWeekday
localWeekNumber
localWeekYear
ordinal
monthShort
monthLong
weekdayShort
weekdayLong
offset
offsetNameShort
offsetNameLong
isOffsetFixed
isInDST
getPossibleOffsets()
isInLeapYear
daysInMonth
daysInYear
weeksInWeekYear
weeksInLocalWeekYear
resolvedLocaleOptions(opts)
toUTC(offset, opts)
toLocal()
setZone(zone, opts)
reconfigure(properties)
setLocale(locale)
set(values)
plus(duration)
minus(duration)
startOf(unit, opts)
endOf(unit, opts)
toFormat(fmt, opts)
toLocaleString(formatOpts, opts)
toLocaleParts(opts)
toISO(opts)
toISODate(opts)
toISOWeekDate()
toISOTime(opts)
toRFC2822()
toHTTP()
toSQLDate()
toSQLTime(opts)
toSQL(opts)
toString()
for()
valueOf()
toMillis()
toSeconds()
toUnixInteger()
toJSON()
toBSON()
toObject(opts)
toJSDate()
diff(otherDateTime, unit, opts)
diffNow(unit, opts)
until(otherDateTime)
hasSame(otherDateTime, unit, opts)
equals(other)
toRelative(options)
toRelativeCalendar(options)

unitForToken

unitForToken(token: any, loc: Locale)
Parameters
token (any)
loc (Locale)

usesLocalWeekValues

Check if local week units like localWeekday are used in obj. If so, validates that they are not mixed with ISO week units and then copies them to the normal week unit properties. Modifies obj in-place!

usesLocalWeekValues(obj: any, loc: any)
Parameters
obj (any) the object values
loc (any)

Duration

A Duration object represents a period of time, like "2 months" or "1 day, 1 hour". Conceptually, it's just a map of units to their quantities, accompanied by some additional configuration and methods for creating, parsing, interrogating, transforming, and formatting them. They can be used on their own or in conjunction with other Luxon types; for example, you can use DateTime#plus to add a Duration object to a DateTime, producing another DateTime.

Here is a brief overview of commonly used methods and getters in Duration:

There's are more methods documented below. In addition, for more information on subtler topics like internationalization and validity, see the external documentation.

new Duration(config: any)
Parameters
config (any)
Static Members
fromMillis(count, opts)
fromObject(obj, opts)
fromDurationLike(durationLike)
fromISO(text, opts)
fromISOTime(text, opts)
invalid(reason, explanation)
isDuration(o)
Instance Members
locale
numberingSystem
toFormat(fmt, opts)
toHuman(opts)
toObject()
toISO()
toISOTime(opts)
toJSON()
toString()
for()
toMillis()
valueOf()
plus(duration)
minus(duration)
mapUnits(fn)
get(unit)
set(values)
reconfigure($0)
as(unit)
normalize()
rescale()
shiftTo(units)
shiftToAll()
negate()
years
quarters
months
weeks
days
hours
minutes
seconds
milliseconds
isValid
invalidReason
invalidExplanation
equals(other)

formatOffset

Returns the offset's value as a string

formatOffset(offset: any, format: string, ts: number): string
Parameters
offset (any)
format (string) What style of offset to return. Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
ts (number) Epoch milliseconds for which to get the offset
Returns
string:

Interval

An Interval object represents a half-open interval of time, where each endpoint is a DateTime. Conceptually, it's a container for those two endpoints, accompanied by methods for creating, parsing, interrogating, comparing, transforming, and formatting them.

Here is a brief overview of the most commonly used methods and getters in Interval:

new Interval(config: any)
Parameters
config (any)
Static Members
invalid(reason, explanation)
fromDateTimes(start, end)
after(start, duration)
before(end, duration)
fromISO(text, opts?)
isInterval(o)
merge(intervals)
xor(intervals)
Instance Members
start
end
lastDateTime
isValid
invalidReason
invalidExplanation
length(unit)
count(unit, opts)
hasSame(unit)
isEmpty()
isAfter(dateTime)
isBefore(dateTime)
contains(dateTime)
set(values)
splitAt(dateTimes)
splitBy(duration)
divideEqually(numberOfParts)
overlaps(other)
abutsStart(other)
abutsEnd(other)
engulfs(other)
equals(other)
intersection(other)
union(other)
difference(intervals)
toString()
for()
toLocaleString(formatOpts, opts)
toISO(opts)
toISODate()
toISOTime(opts)
toFormat(dateFormat, opts)
toDuration(unit, opts)
mapEndpoints(mapFn)

Info

The Info class contains static methods for retrieving general time and date related data. For example, it has methods for finding out if a time zone has a DST, for listing the months in any supported locale, and for discovering which of Luxon features are available in the current environment.

new Info()
Static Members
hasDST(zone)
isValidIANAZone(zone)
normalizeZone(input?)
getStartOfWeek(opts)
getMinimumDaysInFirstWeek(opts)
getWeekendWeekdays(opts)
months(length, opts)
monthsFormat(length, opts)
weekdays(length, opts)
weekdaysFormat(length, opts)
meridiems(opts)
eras(length, opts)
features()

Zone

Zone
Instance Members
type
name
ianaName
isUniversal
offsetName(ts, opts)
formatOffset(ts, format)
offset(ts)
equals(otherZone)
isValid

FixedOffsetZone

A zone with a fixed offset (meaning no DST)

new FixedOffsetZone(offset: any)

Extends Zone

Parameters
offset (any)
Static Members
utcInstance
instance(offset)
parseSpecifier(s)
Instance Members
type
name
ianaName
offsetName()
formatOffset(ts, format)
isUniversal
offset()
equals(otherZone)
isValid

IANAZone

A zone identified by an IANA identifier, like America/New_York

new IANAZone(name: any)

Extends Zone

Parameters
name (any)
Static Members
create(name)
resetCache()
isValidSpecifier(s)
isValidZone(zone)
Instance Members
type
name
isUniversal
offsetName(ts, opts)
formatOffset(ts, format)
offset(ts)
equals(otherZone)
isValid

InvalidZone

A zone that failed to parse. You should never need to instantiate this.

new InvalidZone(zoneName: any)

Extends Zone

Parameters
zoneName (any)
Instance Members
type
name
isUniversal
offsetName()
formatOffset()
offset()
equals()
isValid

SystemZone

Represents the local zone for this JavaScript environment.

new SystemZone()

Extends Zone

Static Members
instance
Instance Members
type
name
isUniversal
offsetName(ts, $1)
formatOffset(ts, format)
offset(ts)
equals(otherZone)
isValid

Settings

Settings contains static getters and setters that control Luxon's overall behavior. Luxon is a simple library with few options, but the ones it does have live here.

new Settings()
Static Members
now
now
defaultZone
defaultZone
defaultLocale
defaultLocale
defaultNumberingSystem
defaultNumberingSystem
defaultOutputCalendar
defaultOutputCalendar
defaultWeekSettings
defaultWeekSettings
twoDigitCutoffYear
twoDigitCutoffYear
throwOnInvalid
throwOnInvalid
resetCaches()

WeekSettings

WeekSettings

Type: Object

Properties
firstDay (number)
minimalDays (number)
weekend (Array<number>)