Options
All
  • Public
  • Public/Protected
  • All
Menu

@jetblack/date-tz

Index

Enumerations

Classes Calendars

Classes Duration

Classes Other

Classes Timezone

Interfaces Other

Interfaces Timezone

Type aliases

Variables Calendars

Variables Timezone

Functions Anchors

Functions Arithmetic

Functions Calendars

Functions Comparisons

Functions Comparisons ```js import { DateTz, isDateBefore } from '@jetblack/date-tz' console.log(isDateBefore(new DateTz('2000-01-02'), new DateTz('2000-01-01'))) // returns false console.log(isDateBefore(new DateTz('2000-01-01'), new DateTz('2000-01-02'))) // returns true console.log(isDateBefore(new DateTz('2000-01-01'), new DateTz('2000-01-01'))) // returns false ```

Functions Comparisons ```js import { DateTz, isDateEqual } '@jetblack/date-tz' console.log(isDateEqual(new DateTz('2000-01-02'), new DateTz('2000-01-01'))) // returns false console.log(isDateEqual(new DateTz('2000-01-01'), new DateTz('2000-01-02'))) // returns false console.log(isDateEqual(new DateTz('2000-01-01'), new DateTz('2000-01-01'))) // returns true ```

Functions Differences

Functions Formatting

Functions Miscellaneous

Functions Other

Functions Ranges

Functions Timezone

Type aliases

DayPeriods: [string, string]

Day periods: morning, afternoon.

Days: [string, string, string, string, string, string, string]

The 7 days of the week

Months: [string, string, string, string, string, string, string, string, string, string, string, string]

The 12 months of the year

NameStyle: "narrow" | "short" | "long"

The Intl name style.

Periodicity: "daily" | "weekly" | "monthly" | "quarterly" | "yearly"

Calendars Variables

calWeekends: WeekendCalendar = ...

The default calendar where Saturday and Sunday are considered holidays.

Timezone Variables

tzLocal: LocalTimezone = ...

The local timezone.

tzUtc: UtcTimezone = ...

The timezone for UTC.

Anchors Functions

  • Return the end of the day for the given date.

    import { DateTz, endOfDay, tzUtc } from '@jetblack/date-tz'

    const d1 = new DateTz(2000, 1, 1, tzUtc)
    const d2 = endOfDay(d1)
    console.log(d2.toISOString())
    // 2000-02-01T23:59:59.999Z

    Parameters

    • dateTz: DateTz

      The start date.

    Returns DateTz

    A new date which is the end of the day.

  • Return the end of the hour for the given date.

    import { DateTz, endOfHour, tzUtc } from '@jetblack/date-tz'

    const d1 = new DateTz(2000, 1, 1, tzUtc)
    const d2 = endOfHour(d1)
    console.log(d2.toISOString())
    // 2000-02-01T00:59:59.999Z

    Parameters

    • dateTz: DateTz

      The start date.

    Returns DateTz

    A new date which is the end of the hour.

  • Return the end of the minute for the given date.

    import { DateTz, endOfMinute, tzUtc } from '@jetblack/date-tz'

    const d1 = new DateTz(2000, 1, 1, tzUtc)
    const d2 = endOfMinute(d1)
    console.log(d2.toISOString())
    // 2000-02-01T00:00:59.999Z

    Parameters

    • dateTz: DateTz

      The start date.

    Returns DateTz

    A new date which is the end of the minute.

  • Calculate the last moment of the month.

    import { DateTz, endOfMonth, tzUtc } from '@jetblack/date-tz'

    const days1 = endOfMonth(new DateTz(2022, 3, 25, tzUtc))
    console.log(days1.toISOString())
    // 2022-03-31T23:59:59.999Z

    // Compare with lastDayOfMonth.
    const days2 = lastDayOfMonth(new DateTz(2022, 3, 25, tzUtc))
    console.log(days2.toISOString())
    // 2022-03-31T00:00:00.000Z

    Parameters

    • dateTz: DateTz

      The start date.

    Returns DateTz

    A date which is the last day of the month for the given year and month.

  • Return the end of the second for the given date.

    import { DateTz, endOfSecond, tzUtc } from '@jetblack/date-tz'

    const d1 = new DateTz(2000, 1, 1, tzUtc)
    const d2 = endOfSecond(d1)
    console.log(d2.toISOString())
    // 2000-02-01T00:00:00.999Z

    Parameters

    • dateTz: DateTz

      The start date.

    Returns DateTz

    A new date which is the end of the second.

  • The end of today.

    Parameters

    • tz: Timezone = tzLocal

      An optional timezone. Defaults to the local timezone.

    Returns DateTz

    The end of the current day.

  • Find the last moment of the week for a given date.

    Weeks start on Sunday and end on Saturday.

    import { DateTz, endOfWeek, tzUtc } from '@jetblack/date-tz'

    const days1 = endOfWeek(new DateTz(2022, 3, 25, tzUtc))
    console.log(days1.toISOString())
    // 2022-03-26T23:59:59.999Z

    // Compare to lastDayOfWeek
    const days2 = lastDayOfWeek(new DateTz(2022, 3, 25, tzUtc))
    console.log(days2.toISOString())
    // 2022-03-26T00:00:00.000Z

    Parameters

    Returns DateTz

    The end of the week.

  • Find the last moment of the week for a given date and first day of week.

    import { DateTz, endOfWeekday, tzUtc } from '@jetblack/date-tz'

    const days1 = endOfWeekday(new DateTz(2022, 3, 25, tzUtc), 1)
    console.log(days1.toISOString())
    // 2022-03-27T23:59:59.999Z

    // Compare to lastDayOfWeekday
    const days2 = lastDayOfWeekday(new DateTz(2022, 3, 25, tzUtc), 1)
    console.log(days2.toISOString())
    // 2022-03-27T00:00:00.000Z

    Parameters

    • dateTz: DateTz

      A date.

    • weekStartsOn: number

      The first day of the week where 0 is Sunday.

    Returns DateTz

    The end of the week.

  • Find the last moment of the year.

    import { DateTz, endOfYear, tzUtc } from '@jetblack/date-tz'

    const days1 = endOfYear(new DateTz(2022, 3, 25, tzUtc))
    console.log(days1.toISOString())
    // 2022-12-31T23:59:59.999Z

    // Compare with lastDayOfYear.
    const days2 = lastDayOfYear(new DateTz(2022, 3, 25, tzUtc))
    console.log(days2.toISOString())
    // 2022-12-31T00:00:00.000Z

    Parameters

    Returns DateTz

    The last moment of the year.

  • Find the last day of the month.

    import { DateTz, lastDayOfMonth, tzUtc } from '@jetblack/date-tz'

    const days2 = lastDayOfMonth(new DateTz(2022, 3, 25, tzLocal))
    console.log(days2.toISOString())
    // 2022-03-31T00:00:00.000Z

    // Compare with endOfMonth.
    const days1 = endOfMonth(new DateTz(2022, 3, 25, tzUtc))
    console.log(days1.toISOString())
    // 2022-03-31T23:59:59.999Z

    Parameters

    • dateTz: DateTz

      The start date.

    Returns DateTz

    A date which is the last day of the month.

  • Find the last day of the quarter.

    import { DateTz, lastDayOfQuarter, tzLocal } from '@jetblack/date-tz'

    console.log(
    lastDayOfQuarter(new DateTz(2000, 1, 2, tzLocal)).toISOString()
    )
    // returns 2000-03-31T00:00:00-??:??

    Parameters

    Returns DateTz

    A date which is the last day of the quarter.

  • Find the last day of the week for a given date.

    Note: weeks start on Sunday and end on Saturday.

    import { DateTz, lastDayOfWeek, tzUtc } from '@jetblack/date-tz'

    const days2 = lastDayOfWeek(new DateTz(2022, 3, 25, tzUtc))
    console.log(days2.toISOString())
    // 2022-03-26T00:00:00.000Z

    // Compare to endOfWeek
    const days1 = endOfWeek(new DateTz(2022, 3, 25, tzUtc))
    console.log(days1.toISOString())
    // 2022-03-26T23:59:59.999Z

    Parameters

    Returns DateTz

    A date which is the last day of the week.

  • lastDayOfWeekday(dateTz: DateTz, weekStartsOn: number): DateTz
  • Find the last day of the week for a given date and first day of week.

    import { DateTz, endOfWeekday, lastDayOfWeekday, tzUtc } from '@jetblack/date-tz'

    const days2 = lastDayOfWeekday(new DateTz(2022, 3, 25, tzUtc), 1)
    console.log(days2.toISOString())
    // 2022-03-27T00:00:00.000Z

    // Compare to endOfWeekday
    const days1 = endOfWeekday(new DateTz(2022, 3, 25, tzUtc), 1)
    console.log(days1.toISOString())
    // 2022-03-27T23:59:59.999Z

    Parameters

    • dateTz: DateTz

      A date.

    • weekStartsOn: number

      The first day of the week where 0 is Sunday.

    Returns DateTz

    A date which is the last day of the week.

  • Find the last day of the year.

    import { DateTz, endOfYear, lastDayOfYear, tzUtc } from '@jetblack/date-tz'

    const days2 = lastDayOfYear(new DateTz(2022, 3, 25, tzUtc))
    console.log(days2.toISOString())
    // 2022-12-31T00:00:00.000Z

    // Compare with endOfYear.
    const days1 = endOfYear(new DateTz(2022, 3, 25, tzUtc))
    console.log(days1.toISOString())
    // 2022-12-31T23:59:59.999Z

    Parameters

    • dateTz: DateTz

      The start date.

    Returns DateTz

    A date which is the last day of the year.

  • Find the start of the current month.

    Parameters

    • tz: Timezone = tzLocal

      An optional timezone. Defaults to the local timezone.

    Returns DateTz

    The start of the current month.

  • Find the start of the current year.

    Parameters

    • tz: Timezone = tzLocal

      An optional timezone. Defaults to the local timezone.

    Returns DateTz

    The start of the current year.

  • Find the start of the day.

    import { DateTz, startOfDay, tzLocal } from '@jetblack/date-tz'

    const date = new DateTz(2000, 0, 1, 10, 30, tzLocal)
    console.log(startOfDay(date).toISOString)
    // returns "2000-01-01T00:00:00+??:??"

    Parameters

    Returns DateTz

    The start of the day.

  • Find the start of an ISO week for a given date.

    ISO weeks start on a Monday.

    Parameters

    Returns DateTz

    The start of the week.

  • Find the start of today.

    Parameters

    • tz: Timezone = tzLocal

      An optional timezone. Defaults to the local timezone.

    Returns DateTz

    The start of today.

  • Find the first week of the year for the week year of a given date.

    Parameters

    Returns DateTz

    The date of the first week of the year.

  • startOfWeekday(dateTz: DateTz, weekStartsOn: number): DateTz
  • Find the start of the week for a given date and first day of week.

    Parameters

    • dateTz: DateTz

      A date.

    • weekStartsOn: number

      The first day of the week where 0 is Sunday.

    Returns DateTz

    The start of the week.

  • Find the start of the year for a given date.

    Parameters

    Returns DateTz

    The start of the year.

Arithmetic Functions

  • Add business days to a date (or subtract if negative).

    If a calendar is not specified the calWeekends calendar is used.

    import { addBusinessDays, DateTz } from '@jetblack/date-tz'

    // Fri 7 Jan 2000
    const date = addBusinessDays(new DateTz(2000, 1, 7), 1)
    console.log(date.getTime() === new Date(2000, 1, 10).getTime())

    Parameters

    • dateTz: DateTz

      The start date.

    • count: number

      The number of days to add (or subtract if negative).

    • cal: Calendar = calWeekends

      The calendar to use to identify dates which are holidays. Defaults to the calWeekends calendar.

    Returns DateTz

    A new date adjusted by business days.

  • Add days to a date (or subtract if negative)

    Daylight savings time (DST) presents an issue for date arithmetic.

    The following example adds three days to the Saturday before the clocks change using the local timezone (London) and UTC (which does not have DST).

    When using the local timezone the "naturally correct" answer is returned. However, the elapsed time will be an hour less than when using UTC.

    Keeping the time change constant (as with UTC) can be useful when plotting data, or doing time series calculations (rolling averages, resampling, etc.).

    import { addDays, tzLocal, tzUtc, DateTz } from '@jetblack/date-tz'

    // The local timezone here is London.
    // In London on Sunday March 26 2000 the clocks go forward 1 hour.
    const d1 = new Date('2000-03-25T12:00:00')
    const d2 = addDays(new DateTz(d1, tzLocal), 3)
    const d3 = addDays(new DateTz(d1, tzUtc), 3)
    console.log(d1.toString()) // Sat Mar 25 2000 12:00:00 GMT+0000 (Greenwich Mean Time)
    console.log(d2.date.toString()) // Tue Mar 28 2000 12:00:00 GMT+0100 (British Summer Time)
    console.log(d3.date.toString()) // Tue Mar 28 2000 13:00:00 GMT+0100 (British Summer Time)

    Parameters

    • dateTz: DateTz

      The start date.

    • numberOfDays: number

      The number of days to add (or subtract if negative).

    Returns DateTz

    A new date adjusted by the number of days.

  • Add a duration to a date.

    import { DateTz, Duration, tzLocal } from '@jetblack/date-tz'

    const duration = new Duration('P1DT3H')
    const date = addDuration(new DateTz(2000, 0, 1, tzLocal), duration)

    Parameters

    • dateTz: DateTz

      The start date.

    • duration: Duration

      The duration to add.

    Returns DateTz

    A new date adjusted by adding the duration.

  • Add hours to a date (or subtract if negative).

    Daylight savings time is handled appropriately.

    import { addHours, DateTz } from '@jetblack/date-tz'

    // The local timezone here is London.
    // In London on Sunday March 26 2000 the clocks go forward 1 hour.
    const d1 = new DateTz(2000, 3, 26)
    console.log(d1)
    // Sun Mar 26 2000 00:00:00 GMT+0000 (Greenwich Mean Time)
    const d2 = addHours(d1, 1)
    console.log(d2)
    // Sun Mar 26 2000 02:00:00 GMT+0100 (British Summer Time)

    Parameters

    • dateTz: DateTz

      The start date.

    • numberOfHours: number

      The number of hours to add (or subtract if negative).

    Returns DateTz

    A new date adjusted by the number of hours.

  • addMilliseconds(dateTz: DateTz, numberOfMilliseconds: number): DateTz
  • Adds milliseconds to a date (or subtracts if negative).

    import { addMilliseconds, DateTz } from '@jetblack/date-tz'

    const d1 = addMilliseconds(new DateTz(2000, 1, 1, 111)
    console.log(d1.toISOString())
    // 2000-01-01T00:00:00.111Z

    Parameters

    • dateTz: DateTz

      The start date.

    • numberOfMilliseconds: number

      The number of milliseconds to add (or subtract if negative).

    Returns DateTz

    A new date adjusted by the number of milliseconds.

  • Adds minutes to a date (or subtracts if negative).

    import { addMinutes, DateTz } from '@jetblack/date-tz'

    const d1 = addMinutes(new DateTz(2000, 1, 1), 5)
    console.log(d1.toISOString())
    // 2000-01-01T00:05:00.000Z

    Parameters

    • dateTz: DateTz

      The start date.

    • numberOfMinutes: number

      The number of minutes to ad (or subtract if negative).

    Returns DateTz

    A new date adjusted by the number of minutes.

  • Add months to a date (or subtract if negative).

    The day of the month is kept constant if possible. Where the destination has less days at the end of the month, the surplus days are added.

    import { addMonths, tzUtc, DateTz } from '@jetblack/date-tz'

    // The day of the month is kept constant if possible.
    const d1 = new DateTz(2000, 1, 12, tzUtc)
    console.log(d1.toString())
    // Wed Jan 12 2000 00:00:00 GMT+0000 (Greenwich Mean Time)
    const d2 = addMonths(d1, 1)
    console.log(d2.toString())
    // Sat Feb 12 2000 00:00:00 GMT+0000 (Greenwich Mean Time)

    // If there are less days in the following month the surplus days are added.
    const d3 = new DateTz(2000, 1, 31, tzUtc)
    console.log(d3.toString())
    // Mon Jan 31 2000 00:00:00 GMT+0000 (Greenwich Mean Time)
    const d4 = addMonths(d3, 1)
    console.log(d4.toString())
    // Thu Mar 02 2000 00:00:00 GMT+0000 (Greenwich Mean Time)

    Parameters

    • dateTz: DateTz

      The start date.

    • numberOfMonths: number

      The number of months to add (or subtract if negative)

    Returns DateTz

    A new date adjusted by the number of months.

  • addNthDayOfWeek(dateTz: DateTz, nth: number, dow: number, strictlyDifferent: boolean): DateTz
  • Add or subtract days of the week.

    If the start date lies on the specified day of the week and the strictly different flag is false, the current date would be considered the first day of the week.

    Note that the JavaScript Date object treats 0 as Sunday and 6 as Saturday.

    import { addNthDayOfWeek, DateTz } from '@jetblack/date-tz'

    // Saturday 1 January 1990
    const d1 = new DateTz(2000, 1, 1)

    // The third Thursday of the month.
    const d2 = addNthDayOfWeek(d1, 3, 4, false)
    console.log(d2)
    // Thu Jan 20 2000 00:00:00 GMT+0000 (Greenwich Mean Time)

    // The last Friday of the month
    const d3 = addNthDayOfWeek(endOfMonth(d1), -1, 5, false)
    console.log(d3)
    // Fri Jan 28 2000 00:00:00 GMT+0000 (Greenwich Mean Time)

    Parameters

    • dateTz: DateTz

      The start date.

    • nth: number

      The number of week days.

    • dow: number

      The day of the week where Sunday is 0.

    • strictlyDifferent: boolean

      When true the returned date must be different to the start date.

    Returns DateTz

    The nth week day.

  • addQuarters(dateTz: DateTz, numberOfQuarters: number): DateTz
  • Add quarters to a date (or subtract if negative).

    The day of the quarter is kept constant if possible. Where the destination has less days at the end of the month, the surplus days are added.

    Parameters

    • dateTz: DateTz

      The start date.

    • numberOfQuarters: number

      The number of quarters to add (or subtract if negative)

    Returns DateTz

    A new date adjusted by the number of quarters.

  • Adds seconds to a date (or subtracts if negative).

    import { addSeconds, DateTz } from '@jetblack/date-tz'

    const d1 = addSeconds(new DateTz(2000, 1, 1), 61)
    console.log(d1.toISOString())
    // 2000-01-01T00:01:01.000Z

    Parameters

    • dateTz: DateTz

      The start date.

    • numberOfSeconds: number

      The number of seconds to add.

    Returns DateTz

    A new date adjusted by the number of seconds.

  • Add years to a date (or subtract if negative).

    Note how surplus days for a leap year are added.

    import { addYears, tzUtc, DateTz } from '@jetblack/date-tz'

    // There is no 29 February in 2001.
    const d1 = addYears(new DateTz('2000-02-29', tzUtc), 1)
    console.log(d1.toString())
    // Thu Mar 01 2001 00:00:00 GMT+0000 (Greenwich Mean Time)

    // 2004 is also a leap year.
    const d2 = addYears(new DateTz(2000, 2, 29, tzUtc), 4)
    console.log(d2.toString())
    // Sun Feb 29 2004 00:00:00 GMT+0000 (Greenwich Mean Time)

    Parameters

    • dateTz: DateTz

      The start date.

    • numberOfYears: number

      The number of years to add (or subtract if negative).

    Returns DateTz

    A new date adjusted by the number of years.

  • Subtract a duration from a date.

    Parameters

    • dateTz: DateTz

      The start date.

    • duration: Duration

      The duration to subtract.

    Returns DateTz

    A new date adjusted by subtracting the duration.

Calendars Functions

  • daysInMonth(year: number, month: number): number
  • Find the number of days in a month for a given year.

    import { daysInMonth } from '@jetblack/date-tz'

    console.log(daysInMonth(2000, 0))
    // 31

    console.log(daysInMonth(2000, 1))
    // 29

    console.log(daysInMonth(2001, 1))
    // 28

    Parameters

    • year: number

      The year.

    • month: number

      The month where January is 1.

    Returns number

    The number of days in the month for the given year.

  • daysInYear(year: number): number
  • Find the number of days in a year.

    import { daysInYear } from '@jetblack/date-tz'

    console.log(daysInYear(2000))
    // 366

    console.log(daysInYear(2001))
    // 365

    Parameters

    • year: number

      The year.

    Returns number

    The number of days in the year.

  • Calculates Easter in the Gregorian calendar.

    Parameters

    • year: number

      The year.

    • tz: Timezone = tzLocal

      An optional timezone. Defaults to the local timezone.

    Returns DateTz

    The date for easter in the given year.

  • isLastDayOfMonth(date: DateTz): boolean
  • Check if the date is the last day of the month.

    The time component is ignored.

    Parameters

    • date: DateTz

      The date to check.

    Returns boolean

    True if the date is the last day of the month.

  • isLastDayOfQuarter(date: DateTz): boolean
  • Check if the date is the last day of the quarter.

    Any time component is ignored.

    import { DateTz, tzLocal, isLastDayOfQuarter } from '@jetblack/date-tz'

    const jan30 = new DateTz(2008, 1, 30, tzLocal)
    console.log(isLastDayOfQuarter(jan30))
    // returns false

    const mar31 = new DateTz(2008, 3, 31, tzLocal)
    console.log(isLastDayOfQuarter(mar31))
    // returns true

    Parameters

    • date: DateTz

      The date to check.

    Returns boolean

    True if the date is the last day of the quarter.

  • isLeapYear(year: number): boolean
  • Check if the year is a leap year.

    import { isLeapYear } from '@jetblack/date-tz'

    // 2000 was a century leap year.
    console.log(isLeapYear(2000) === true)

    // 1900 was not.
    console.log(isLeapYear(1900) !== true)

    Parameters

    • year: number

      The year.

    Returns boolean

    True if the year is a leap year, otherwise false.

  • quarterOfYear(dateTz: DateTz): number
  • Find the quarter for a given date.

    import { DateTz, quarterOfYear } from '@jetblack/date-tz'

    console.log(quarterOfYear(new DateTz(2000, 4, 1)))
    // 2

    Parameters

    Returns number

    The quarter of the year.

Comparisons Functions

  • Compare two dates to see if they are in the same quarter of the year.

    import { areInSameQuarter, DateTz } from '@jetblack/date-tz'

    console.log(areInSameQuarter(new DateTz(2000, 1, 1), new DateTz(2000, 2, 1)))
    // true
    console.log(areInSameQuarter(new DateTz(2000, 1, 1), new DateTz(2000, 4, 1)))
    // false

    Parameters

    • first: DateTz

      The first date.

    • second: DateTz

      The second date.

    Returns boolean

    True if the dates are in the same quarter, otherwise false.

  • Compares two dates ascending.

    import { compareDateAsc, DateTz } from '@jetblack/date-tz'

    const a = [
    new DateTz(2000, 7, 1),
    new DateTz(2000, 5, 1),
    new DateTz(2000, 6, 1)
    ]
    console.log(a.sort(compareDateAsc))
    // 0: Mon May 01 2000 01:00:00 GMT+0100 (British Summer Time)
    // 1: Thu Jun 01 2000 01:00:00 GMT+0100 (British Summer Time)
    // 2: Sat Jul 01 2000 01:00:00 GMT+0100 (British Summer Time)

    Parameters

    Returns number

    1 if the first date is greater than the second date, -1 if the first date is less than the last date, otherwise 0.

  • Compares two dates descending.

    import { compareDateDesc, DateTz } from '@jetblack/date-tz'

    const a = [
    new DateTz(2000, 7, 1),
    new DateTz(2000, 5, 1),
    new DateTz(2000, 6, 1)
    ]
    console.log(a.sort(compareDateDesc))
    // 0: Sat Jul 01 2000 01:00:00 GMT+0100 (British Summer Time)
    // 1: Thu Jun 01 2000 01:00:00 GMT+0100 (British Summer Time)
    // 2: Mon May 01 2000 01:00:00 GMT+0100 (British Summer Time)

    Parameters

    Returns number

    1 if the second date is greater than the first date, -1 if the second date is less than the first date, otherwise 0.

  • Checks if the left date is after the right date.

    import { DateTz, isDateAfter } from '@jetblack/date-tz'

    console.log(isDateAfter(new DateTz('2000-01-02'), new DateTz('2000-01-01')))
    // returns true
    console.log(isDateAfter(new DateTz('2000-01-01'), new DateTz('2000-01-02')))
    // returns false
    console.log(isDateAfter(new DateTz('2000-01-01'), new DateTz('2000-01-01')))
    // returns false

    Parameters

    Returns boolean

    True if the left date is after the right date, otherwise false.

  • Checks if the dates are not equal.

    import { DateTz, isDateNotEqual } from '@jetblack/date-tz'

    console.log(isDateNotEqual(new DateTz('2000-01-02'), new DateTz('2000-01-01')))
    // returns true
    console.log(isDateNotEqual(new DateTz('2000-01-01'), new DateTz('2000-01-02')))
    // returns true
    console.log(isDateNotEqual(new DateTz('2000-01-01'), new DateTz('2000-01-01')))
    // returns false

    Parameters

    Returns boolean

    True if the dates are not equal, otherwise false.

  • Checks if the left date is on or after the right date.

    import { DateTz, isDateOnOrAfter } from '@jetblack/date-tz'

    console.log(isDateOnOrAfter(new DateTz('2000-01-02'), new DateTz('2000-01-01')))
    // returns true
    console.log(isDateOnOrAfter(new DateTz('2000-01-01'), new DateTz('2000-01-02')))
    // returns false
    console.log(isDateOnOrAfter(new DateTz('2000-01-01'), new DateTz('2000-01-01')))
    // returns true

    Parameters

    Returns boolean

    True if the left date is on or after the right date, otherwise false.

  • Checks if the left date is on or before the right date.

    import { DateTz, isDateOnOrBefore } from '@jetblack/date-tz'

    console.log(isDateOnOrBefore(new DateTz('2000-01-02'), new DateTz('2000-01-01')))
    // returns false
    console.log(isDateOnOrBefore(new DateTz('2000-01-01'), new DateTz('2000-01-02')))
    // returns true
    console.log(isDateOnOrBefore(new DateTz('2000-01-01'), new DateTz('2000-01-01')))
    // returns true

    Parameters

    Returns boolean

    True if the left date is on or before the right date, otherwise false.

  • Find the largest date.

    import { DateTz, maxDate } from '@jetblack/date-tz'

    const d1 = maxDate(
    new DateTz(2000, 1, 31),
    new DateTz(2000, 1, 1),
    new DateTz(2000, 1, 10)
    )
    console.log(d1.toISOString())
    // 2000-01-31T00:00:00.000Z

    const dates = [
    new DateTz(2000, 1, 31),
    new DateTz(2000, 1, 1),
    new DateTz(2000, 1, 10)
    ]
    const d2 = maxDate(...dates) // use the spread operator for an array.
    console.log(d2.toISOString())
    // 2000-01-31T00:00:00.000Z

    Parameters

    • Rest ...dates: DateTz[]

      The dates to check.

    Returns DateTz

    The largest date.

  • Find the smallest date.

    import { DateTz, minDate } from '@jetblack/date-tz'

    const d1 = minDate(
    new DateTz(2000, 1, 31),
    new DateTz(2000, 1, 1),
    new DateTz(2000, 1, 1)
    )
    console.log(d1.toISOString())
    // 2000-01-01T00:00:00.000Z

    const dates = [
    new DateTz(2000, 1, 31),
    new DateTz(2000, 1, 1),
    new DateTz(2000, 1, 10)
    ]
    const d2 = minDate(...dates) // use the spread operator for an array
    console.log(d2.toISOString())
    // 2000-01-01T00:00:00.000Z

    Parameters

    • Rest ...dates: DateTz[]

      The dates to check.

    Returns DateTz

    The smallest date.

Comparisons ```js import { DateTz, isDateBefore } from '@jetblack/date-tz' console.log(isDateBefore(new DateTz('2000-01-02'), new DateTz('2000-01-01'))) // returns false console.log(isDateBefore(new DateTz('2000-01-01'), new DateTz('2000-01-02'))) // returns true console.log(isDateBefore(new DateTz('2000-01-01'), new DateTz('2000-01-01'))) // returns false ``` Functions

  • Checks if the left date is before the right date.

    Parameters

    Returns boolean

    True if the left date is before the right date, otherwise false.

Comparisons ```js import { DateTz, isDateEqual } '@jetblack/date-tz' console.log(isDateEqual(new DateTz('2000-01-02'), new DateTz('2000-01-01'))) // returns false console.log(isDateEqual(new DateTz('2000-01-01'), new DateTz('2000-01-02'))) // returns false console.log(isDateEqual(new DateTz('2000-01-01'), new DateTz('2000-01-01'))) // returns true ``` Functions

  • Checks if the dates are equal.

    Parameters

    Returns boolean

    True if the left date equals the right date, otherwise false.

Differences Functions

  • Find the number of whole days between two dates, discarding any time component.

    import { DateTz, diffInCalDays, tzUtc } from '@jetblack/date-tz'

    const days1 = diffInCalDays(
    new DateTz(2022, 3, 25, tzUtc),
    new DateTz(2022, 1, 25, tzUtc)
    )
    console.log(days1)
    // 59

    // The time part is discarded.
    const days2 = diffInCalDays(
    new DateTz(2022, 3, 25),
    new DateTz(2022, 1, 25)
    )
    console.log(days2)
    // 59

    Parameters

    • leftDate: DateTz

      The left date.

    • rightDate: DateTz

      The right date.

    Returns number

    The number of days between the start of day on the start and end dates.

  • diffInCalMonths(leftDate: DateTz, rightDate: DateTz): number
  • Find the number of whole months between two dates.

    Parameters

    • leftDate: DateTz

      The left date.

    • rightDate: DateTz

      The right date.

    Returns number

    The number of months between two dates.

  • Find the number of whole years between two dates.

    Parameters

    • leftDate: DateTz

      The left date.

    • rightDate: DateTz

      The right date.

    Returns number

    The number of years between two dates.

  • Find the number of days between two dates including the fractional component.

    import { DateTz, diffInDays, tzUtc } from '@jetblack/date-tz'

    const days1 = diffInDays(
    new DateTz(2022, 3, 25, tzUtc),
    new DateTz(2022, 1, 25, tzUtc)
    )
    console.log(days1)
    // 59

    // The time part is retained.
    const days2 = diffInDays(
    new DateTz(2022, 3, 25, 12, tzUtc),
    new DateTz(2022, 1, 25, tzUtc)
    )
    console.log(days2)
    // 59.5

    Parameters

    • leftDate: DateTz

      The left date.

    • rightDate: DateTz

      The right date.

    Returns number

    The number of days between the start of day on the start and end dates.

  • Find the number of hours between two dates including fractional minutes.

    Parameters

    • leftDate: DateTz

      The left date.

    • rightDate: DateTz

      The right date.

    Returns number

    The number of days between the start of day on the start and end dates.

  • diffInMilliseconds(leftDate: DateTz, rightDate: DateTz): number
  • Find the number of milliseconds between two dates.

    Parameters

    • leftDate: DateTz

      The left date.

    • rightDate: DateTz

      The right date.

    Returns number

    The number of days milliseconds between the left and right date.

  • Find the number of minutes between two dates including fractional seconds.

    Parameters

    • leftDate: DateTz

      The left date.

    • rightDate: DateTz

      The right date.

    Returns number

    The number of days between the start of day on the start and end dates.

  • Find the number of seconds between two dates including fractional milliseconds.

    Parameters

    • leftDate: DateTz

      The left date.

    • rightDate: DateTz

      The right date.

    Returns number

    The number of days between the start of day on the start and end dates.

Formatting Functions

  • formatDate(dateTz: DateTz, pattern?: string, locale?: undefined | string | I18nSettings): string
  • Format a date with a pattern.

    import { DateTz, formatDate } from '@jetblack/date-tz'

    const d = new DateTz(2000, 1, 1)
    const s = formatDate(d, "d-mmm-yy")
    console.log(s)
    > 1-Jan-00

    Pattern items

    Value Description
    d Day of the month as digits; no leading zero for single-digit days.
    dd Day of the month as digits; leading zero for single-digit days.
    ddd Day of the week as the short representation (for en a three-letter abbreviation).
    dddd Day of the week as its full name.
    DD Day of the month with the plural suffix.
    DDD Day of the week as the narrow representation.
    m Month as digits; no leading zero for single-digit months.
    mm Month as digits; leading zero for single-digit months.
    mmm Month as a three-letter abbreviation.
    mmmm Month as its full name.
    yy Year as last two digits; leading zero for years less than 10.
    yyyy Year represented by four digits.
    h Hours; no leading zero for single-digit hours (12-hour clock).
    hh Hours; leading zero for single-digit hours (12-hour clock).
    H Hours; no leading zero for single-digit hours (24-hour clock).
    HH Hours; leading zero for single-digit hours (24-hour clock).
    M Minutes; no leading zero for single-digit minutes.
    MM Minutes; leading zero for single-digit minutes.
    S Seconds; no leading zero for single-digit seconds.
    SS Seconds; leading zero for single-digit seconds.
    F Hundreds of milliseconds.
    FF Tens of milliseconds with a leading zero for single-digit values.
    FFF Milliseconds: zero padded.
    t Narrow dayPeriod from locale.
    tt Short dayPeriod from locale.
    ttt Long dayPeriod from locale.
    Z Timezone name.
    o GMT/UTC timezone offset, e.g. -0500 or +0230.
    '...' or "..." Literal character sequence. Surrounding quotes are removed.

    Parameters

    • dateTz: DateTz

      A date.

    • pattern: string = "yyyy-mm-dd'T'HH:MM:SSo"

      The format pattern.

    • locale: undefined | string | I18nSettings = undefined

      An optional locale. Defaults to the current browser locale.

    Returns string

    The formatted date string.

  • Parse a date string into a Javascript Date object.

    If the timezone offset is absent the dates will be according to the local timezone.

    import { parseDate } from '@jetblack/date-tz'

    const d = parseDate('12 March, 1998', 'dd mmm, yyyy')

    Pattern items

    Value Description
    d Day of the month as digits; no leading zero for single-digit days.
    dd Day of the month as digits; leading zero for single-digit days.
    ddd Day of the week as a three-letter abbreviation.
    dddd Day of the week as its full name.
    DD Day of the month with the plural suffix.
    m Month as digits; no leading zero for single-digit months.
    mm Month as digits; leading zero for single-digit months.
    mmm Month as a three-letter abbreviation.
    mmmm Month as its full name.
    yy Year as last two digits; leading zero for years less than 10.
    yyyy Year represented by four digits.
    h Hours; no leading zero for single-digit hours (12-hour clock).
    hh Hours; leading zero for single-digit hours (12-hour clock).
    H Hours; no leading zero for single-digit hours (24-hour clock).
    HH Hours; leading zero for single-digit hours (24-hour clock).
    M Minutes; no leading zero for single-digit minutes.
    MM Minutes; leading zero for single-digit minutes.
    S Seconds; no leading zero for single-digit seconds.
    SS Seconds; leading zero for single-digit seconds.
    F Hundreds of milliseconds.
    FF Tens of milliseconds with a leading zero for single-digit values.
    FFF Milliseconds: zero padded.
    t Narrow dayPeriod from locale.
    tt Short dayPeriod from locale.
    ttt Long dayPeriod from locale.
    Z Timezone offset.
    [dhM] Literal characters.

    Parameters

    • text: string

      Date string

    • format: string

      Date parse format

    • tz: Timezone = tzLocal

      An optional timezone. Defaults to the local timezone.

    • locale: undefined | string | I18nSettings = undefined

      An optional locale. Defaults to the current locale.

    Returns DateTz | null

    The date, or null if parsing failed.

Miscellaneous Functions

  • Find the nearest business date.

    Parameters

    • dateTz: DateTz

      The start date.

    • preferForward: boolean = true

      If true a future date is preferred if both directions have the same cost. Defaults to true.

    • cal: Calendar = calWeekends

      The calendar to use to identify business days. Defaults to the weekend calendar.

    Returns DateTz

    The nearest business date.

  • weekOfYear(dateTz: DateTz): number
  • Find the week of the year for a given date.

    Weeks start on 1 January of any given year.

    import { DateTz, weekOfYear, tzUtc } from '@jetblack/date-tz'

    console.log(weekOfYear(new DateTz(1999, 12, 31, tzUtc)))
    // 53
    console.log(weekOfYear(new DateTz(2000, 1, 1, tzUtc)))
    // 1
    console.log(weekOfYear(new DateTz(2000, 1, 7, tzUtc)))
    // 1
    console.log(weekOfYear(new DateTz(2000, 1, 8, tzUtc)))
    // 2
    console.log(weekOfYear(new DateTz(2000, 12, 31, tzUtc)))
    // 53

    Parameters

    Returns number

    The week of the year.

  • weekYear(dateTz: DateTz): number
  • Find the week year for a given date.

    Parameters

    Returns number

    The week year.

Other Functions

  • Adjusts a non-business day to the appropriate nearest business day.

    import { adjustBusinessDay, BusinessDayConvention, DateTz } from '@jetblack/date-tz'

    const d1 = new DateTz(2000, 1, 1)
    console.log(d1)
    // Sat Jan 01 2000 00:00:00 GMT+0000 (Greenwich Mean Time)

    const d2 = adjustBusinessDay(d1, BusinessDayConvention.FOLLOWING)
    console.log(d2.toString())
    // Mon Jan 03 2000 00:00:00 GMT+0000 (Greenwich Mean Time)

    const d3 = adjustBusinessDay(d1, BusinessDayConvention.PRECEDING)
    console.log(d3.toString())
    // Fri Dec 31 1999 00:00:00 GMT+0000 (Greenwich Mean Time)

    Parameters

    • dateTz: DateTz

      The date.

    • convention: BusinessDayConvention = BusinessDayConvention.FOLLOWING

      The business day conventions. Defaults to BusinessDayConvention.FOLLOWING.

    • prefer_forward: boolean = true

      If true prefer the nearest business day in the future. Defaults to true.

    • cal: Calendar = calWeekends

      An optional holiday calendar. Defaults to calWeekend.

    Returns DateTz

    The adjusted date.

  • dateFormat(dateTz: DateTz, pattern?: string, locale?: undefined | string | I18nSettings): string
  • dayOfYear(dateTz: DateTz): number
  • Find the day of the year.

    import { DateTz, dayOfYear, tzUtc } from '@jetblack/date-tz'

    const d = new DateTz(2020, 7, 12)
    const day = dayOfYear(d, tzUtc)
    console.log(day)
    // 94

    Parameters

    Returns number

    The day of the year

  • findDayIndex(dates: DateTz[], day: number): number
  • Find the index of the first date with the given day of the month.

    Parameters

    • dates: DateTz[]

      The dates

    • day: number

      The day of the month to check

    Returns number

    The index of the first match, or -1.

  • findEndOfMonthIndex(dates: DateTz[]): number
  • Find the index of the first date that is the end of the month.

    Parameters

    Returns number

    The index of the first match, or -1.

  • findLastDayIndex(dates: DateTz[], day: number): number
  • Find the index of the last date with the given day of the month.

    Parameters

    • dates: DateTz[]

      The dates

    • day: number

      The day of the month to check

    Returns number

    The index of the last match, or -1.

  • findLastEndOfMonthIndex(dates: DateTz[]): number
  • Find the index of the last date that is the end of the month.

    Parameters

    Returns number

    The index of the last match, or -1.

  • findLastStartOfMonthIndex(dates: DateTz[]): number
  • Find the index of the last date that is the start of the month.

    Parameters

    Returns number

    The index of the last match, or -1.

  • findLastWeekdayIndex(dates: DateTz[], weekday: number): number
  • Find the index of the last date with the given weekday.

    Parameters

    • dates: DateTz[]

      The dates

    • weekday: number

      The weekday to check

    Returns number

    The index of the last match, or -1.

  • findStartOfMonthIndex(dates: DateTz[]): number
  • Find the index of the first date that is the start of the month.

    Parameters

    Returns number

    The index of the first match, or -1.

  • findWeekdayIndex(dates: DateTz[], weekday: number): number
  • Find the index of the first date with the given weekday.

    Parameters

    • dates: DateTz[]

      The dates

    • weekday: number

      The weekday to check

    Returns number

    The index of the first match, or -1.

  • isValidDate(value: any): boolean
  • Check if a value is a valid date.

    import { DateTz, isValidDate } from '@jetblack/date-tz'

    > const value = new DateTz("foo")
    > console.log(isValidDate(value))
    false

    Parameters

    • value: any

      The value to check.

    Returns boolean

    True if the value is a valid date.

  • isoWeekDate(dateTz: DateTz): number[]
  • Find the ISO week date.

    import { DateTz, isoWeekDate } from '@jetblack/date-tz'

    console.log(isoWeekDate(new DateTz(2000, 1, 1)))
    // [1999, 52, 6]

    Parameters

    Returns number[]

    The ISO date as a year, week, and day.

  • isoWeekOfYear(dateTz: DateTz): number
  • Find the ISO week of the year.

    Parameters

    Returns number

    The ISO week.

  • Find the number of leap seconds between the dates (inclusive).

    import { DateTz, endOfYear, leapSeconds, tzUtc } from '@jetblack/date-tz'

    const d1 = new DateTz(1972, 1, 1, tzUtc)
    const d2 = endOfYear(d1)
    // There were two leap seconds in 1972
    console.log(leapSeconds(d1, d2) == 2)

    const d3 = new DateTz(2000, 1, 1, tzUtc)
    const d4 = endOfYear(new DateTz(2005, 1, 1, tzUtc))
    // There were no leap seconds in between 2000 and 2005
    console.log(leapSeconds(d3, d4) == 0)

    Parameters

    • firstDate: DateTz

      The first date.

    • secondDate: DateTz

      The second date.

    Returns number

    The number of leap seconds

  • Round a date to the start of the current day if before noon; otherwise the start of the next day.

    import { DateTz, roundDate, tzLocal } from '@jetblack/date-tz'

    const morning = new DateTz(2000, 0, 1, 10, 30, tzLocal)
    console.log(roundDate(morning).toISOString())
    // returns "2000-01-01T00:00:00+??:??"

    const afternoon = new DateTz(2000, 0, 1, 18, 30, tzLocal)
    console.log(roundDate(afternoon).toISOString())
    // returns "2000-01-02T00:00:00+??:??"

    const noon = new DateTz(2000, 0, 1, 12, 0, tzLocal)
    console.log(roundDate(noon).toISOString())
    // returns "2000-01-02T00:00:00+??:??"

    Parameters

    • date: DateTz

      The date to round

    Returns DateTz

    The start of the day of the rounded date.

Ranges Functions

  • Creates a range of dates by day.

    import { dateRangeByDay, tzUtc, DateTz } from '@jetblack/date-tz'

    const dates = dateRangeByDay(
    new DateTz(2000, 1, 1, 12, 0, 0), // Sets to start of day.
    new DateTz(2000, 1, 10, 12, 0, 0),
    1,
    tzUtc
    )
    dates.forEach(date => console.log(date.toISOString()))
    // 2000-01-01T00:00:00.000Z
    // 2000-01-02T00:00:00.000Z
    // 2000-01-03T00:00:00.000Z
    // 2000-01-04T00:00:00.000Z
    // 2000-01-05T00:00:00.000Z
    // 2000-01-06T00:00:00.000Z
    // 2000-01-07T00:00:00.000Z
    // 2000-01-08T00:00:00.000Z
    // 2000-01-09T00:00:00.000Z
    // 2000-01-10T00:00:00.000Z

    Parameters

    • startDate: DateTz

      The start date.

    • endDate: DateTz

      The end date.

    • step: number = 1

      The day step count.

    Returns DateTz[]

    The range of dates separated by step days from the start to the end date.

  • Creates a range of dates by hours.

    Parameters

    • startDate: DateTz

      The start date.

    • endDate: DateTz

      The end date.

    • step: number = 1

      The hour step count.

    Returns DateTz[]

    The range of dates separated by step hours from the start to the end hour.

  • Creates a range of dates by minutes.

    Parameters

    • startDate: DateTz

      The start date.

    • endDate: DateTz

      The end date.

    • step: number = 1

      The minute step count.

    Returns DateTz[]

    The range of dates separated by step hours from the start to the end minute.

  • Creates a range of dates by month.

    Parameters

    • startDate: DateTz

      The start date.

    • endDate: DateTz

      The end date.

    • step: number = 1

      The month step count.

    Returns DateTz[]

    The range of dates separated by step months from the start to the end date.

  • Creates a range of dates by quarters.

    Parameters

    • startDate: DateTz

      The start date.

    • endDate: DateTz

      The end date.

    • step: number = 1

      The quarter step count. Defaults to 1.

    Returns DateTz[]

    The range of dates separated by step months from the start to the end date.

  • Creates a range of dates by seconds.

    Parameters

    • startDate: DateTz

      The start date.

    • endDate: DateTz

      The end date.

    • step: number = 1

      The second step count.

    Returns DateTz[]

    The range of dates separated by step hours from the start to the end second.

  • Creates a range of dates by week.

    Parameters

    • startDate: DateTz

      The start date.

    • endDate: DateTz

      The end date.

    • step: number = 1

      The week step count.

    Returns DateTz[]

    The range of dates separated by step weeks from the start to the end date.

  • Creates a range of dates by year.

    Parameters

    • startDate: DateTz

      The start date.

    • endDate: DateTz

      The end date.

    • step: number = 1

      The year step count.

    Returns DateTz[]

    The range of dates separated by step years from the start to the end date.

  • Creates a schedule of dates for a periodicity.

    Parameters

    • periodicity: Periodicity

      The periodicity.

    • dateTz: DateTz

      The start date.

    • start: number

      Start offset periods.

    • stop: number

      The number of periods.

    • step: number = 1

      The period step count.

    Returns DateTz[]

    The schedule of dates.

  • dateScheduleByDay(dateTz: DateTz, start: number, stop: number, step?: number): DateTz[]
  • Creates a schedule of dates by day.

    import { DateTz, dateScheduleByDay, tzLocal } from '@jetblack/date-tz'

    console.log(
    dateScheduleByDay(tzLocal.makeDate(2000, 0, 1), 0, 7).map(x =>
    tzLocal.toISOString(x)
    )
    )
    // returns (7) ['2000-01-01T00:00:00+??:??', '2000-01-02T00:00:00+??:??', '2000-01-03T00:00:00+??:??', '2000-01-04T00:00:00+??:??', '2000-01-05T00:00:00+??:??', '2000-01-06T00:00:00+??:??', '2000-01-07T00:00:00+??:??']

    Parameters

    • dateTz: DateTz

      The start date.

    • start: number

      Start offset days.

    • stop: number

      The number of days.

    • step: number = 1

      The days step count.

    Returns DateTz[]

    The schedule of dates separated by step days.

  • dateScheduleByMonth(dateTz: DateTz, start: number, stop: number, step?: number): DateTz[]
  • Creates a schedule of dates by month.

    import { DateTz, dateScheduleByMonth, tzLocal } from '@jetblack/date-tz'

    console.log(
    dateScheduleByMonth(new DateTz(2000, 1, 1), 0, 6).map(x =>
    tzLocal.toISOString(x)
    )
    )
    // returns (6) ['2000-01-01T00:00:00+??:??', '2000-02-01T00:00:00+??:??', '2000-03-01T00:00:00+??:??', '2000-04-01T00:00:00+??:??', '2000-05-01T00:00:00+??:??', '2000-06-01T00:00:00+??:??']

    Parameters

    • dateTz: DateTz

      The start date.

    • start: number

      Start offset months.

    • stop: number

      The number of months.

    • step: number = 1

      The months step count.

    Returns DateTz[]

    The schedule of dates separated by step months.

  • dateScheduleByQuarter(dateTz: DateTz, start: number, stop: number, step?: number): DateTz[]
  • Creates a schedule of dates by quarter.

    import { DateTz, dateScheduleByQuarter, tzLocal } from '@jetblack/date-tz'

    console.log(
    dateScheduleByQuarter(new DateTz(2000, 1, 1), 0, 4).map(x =>
    tzLocal.toISOString(x)
    )
    )
    // returns (4) ['2000-01-01T00:00:00+??:??', '2000-04-01T00:00:00+??:??', '2000-07-01T00:00:00+??:??', '2000-10-01T00:00:00+??:??']

    Parameters

    • dateTz: DateTz

      The start date.

    • start: number

      Start offset quarters.

    • stop: number

      The number of quarters.

    • step: number = 1

      The quarters step count.

    Returns DateTz[]

    The schedule of dates separated by step quarter.

  • dateScheduleByWeek(dateTz: DateTz, start: number, stop: number, step?: number): DateTz[]
  • Creates a schedule of dates by week.

    import { DateTz, dateScheduleByWeek, tzLocal } from '@jetblack/date-tz'

    console.log(
    dateScheduleByWeek(new DateTz(2000, 1, 1), 0, 4).map(x =>
    tzLocal.toISOString(x)
    )
    )
    // returns (4) ['2000-01-01T00:00:00+??:??', '2000-01-08T00:00:00+??:??', '2000-01-15T00:00:00+??:??', '2000-01-22T00:00:00+??:??']

    Parameters

    • dateTz: DateTz

      The start date.

    • start: number

      Start offset weeks.

    • stop: number

      The number of weeks.

    • step: number = 1

      The weeks step count.

    Returns DateTz[]

    The schedule of dates separated by step weeks.

  • dateScheduleByYear(dateTz: DateTz, start: number, stop: number, step?: number): DateTz[]
  • Creates a schedule of dates by year.

    import { DateTz, dateScheduleByYear, tzLocal } from '@jetblack/date-tz'

    console.log(
    dateScheduleByYear(new DateTz(2000, 1, 1), 0, 4).map(x =>
    tzLocal.toISOString(x)
    )
    )
    // returns (4) ['2000-01-01T00:00:00+??:??', '2001-01-01T00:00:00+??:??', '2002-01-01T00:00:00+??:??', '2003-01-01T00:00:00+??:??']

    Parameters

    • dateTz: DateTz

      The start date.

    • start: number

      Start offset years.

    • stop: number

      The number of years.

    • step: number = 1

      The years step count.

    Returns DateTz[]

    The schedule of dates separated by step years.

Timezone Functions

  • Transform the values of a timezone offset.

    Parameters

    • data: object

      The object to transform.

    Returns TimezoneOffset

    The transformed object.

  • fetchTimezone(name: string, version?: string, rootUrl?: string, options?: RequestInit): Promise<IANATimezone>
  • Fetch a timezone.

    import { fetchTimezone } from '@jetblack/date-tz'

    const tzChicago = await fetchTimezone('America/Chicago')
    console.log(tzChicago.makeDate(2022, 12, 25).toISOString())
    // 2023-01-25T06:00:00.000Z

    Parameters

    • name: string

      The timezone name.

    • version: string = 'latest'

      The database version.

    • rootUrl: string = 'https://cdn.jsdelivr.net/npm/@jetblack/tzdata/dist'

      The root url.

    • Optional options: RequestInit

      Fetch options

    Returns Promise<IANATimezone>

    A promise resolving to the timezone.

  • fetchTimezoneNames(version?: string, rootUrl?: string, options?: RequestInit): Promise<string[]>
  • Fetch a list of timezone names.

    import { fetchTimezoneNames } from '@jetblack/map'

    const names = await fetchTimezoneNames()
    console.log(names.filter(name => name.startsWith('Arctic')))
    // (1) ['Arctic/Longyearbyen']

    Parameters

    • version: string = 'latest'

      The database version.

    • rootUrl: string = 'https://cdn.jsdelivr.net/npm/@jetblack/tzdata/dist'

      The root url.

    • Optional options: RequestInit

      Fetch options

    Returns Promise<string[]>

    A promise resolving to the list of time zone names.

  • minDataToTimezoneOffset(data: { a: string; d: number; o: number; u: number }): TimezoneOffset
  • Transform the values of a minified timezone offset.

    Parameters

    • data: { a: string; d: number; o: number; u: number }

      The object to transform.

      • a: string
      • d: number
      • o: number
      • u: number

    Returns TimezoneOffset

    The transformed object.

  • timezoneFromJSON(name: string, tzdata: object[]): IANATimezone
  • Create a timezone from JSON data.

    The JSON data requires transformation to convert date and duration strings to objects.

    Parameters

    • name: string

      The timezone name.

    • tzdata: object[]

      The JSON timezone data.

    Returns IANATimezone

    The new timezone.

  • tzDataReviver(key: string, value: any): any
  • A JSON.parse reviver for tzdata.

    Parameters

    • key: string

      The JSON key.

    • value: any

      The JSON value.

    Returns any

    A revived value if applicable.

Generated using TypeDoc