The 7 days of the week
The 12 months of the year
The Intl name style.
The default calendar where Saturday and Sunday are considered holidays.
The local timezone.
The timezone for UTC.
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
The start date.
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
The start date.
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
The start date.
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
The start date.
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
The start date.
A new date which is the end of the second.
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
A date.
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
A date.
The first day of the week where 0 is Sunday.
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
A date
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
The start date.
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-??:??
The start date.
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
A date.
A date which is the last day of the week.
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
A date.
The first day of the week where 0 is Sunday.
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
The start date.
A date which is the last day of the year.
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())
The start date.
The number of days to add (or subtract if negative).
The calendar to use to identify dates which are holidays. Defaults to the calWeekends
calendar.
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)
The start date.
The number of days to add (or subtract if negative).
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)
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)
The start date.
The number of hours to add (or subtract if negative).
A new date adjusted by the number of hours.
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
The start date.
The number of milliseconds to add (or subtract if negative).
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
The start date.
The number of minutes to ad (or subtract if negative).
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)
The start date.
The number of months to add (or subtract if negative)
A new date adjusted by the number of months.
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)
The start date.
The number of week days.
The day of the week where Sunday is 0.
When true the returned date must be different to the start date.
The nth week day.
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.
The start date.
The number of quarters to add (or subtract if negative)
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
The start date.
The number of seconds to add.
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)
The start date.
The number of years to add (or subtract if negative).
A new date adjusted by the number of years.
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
The year.
The month where January is 1.
The number of days in the month for the given year.
Find the number of days in a year.
import { daysInYear } from '@jetblack/date-tz'
console.log(daysInYear(2000))
// 366
console.log(daysInYear(2001))
// 365
The year.
The number of days in the year.
Check if the date is the last day of the month.
The time component is ignored.
The date to check.
True if the date is the last day of the month.
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
The date to check.
True if the date is the last day of the quarter.
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)
The year.
True if the year is a leap year, otherwise false.
Find the quarter for a given date.
import { DateTz, quarterOfYear } from '@jetblack/date-tz'
console.log(quarterOfYear(new DateTz(2000, 4, 1)))
// 2
The date.
The quarter of the year.
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
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)
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)
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
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
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
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
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
The dates to check.
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
The dates to check.
The smallest date.
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
The number of days between the start of day on the start and end 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
The number of days between the start of day on the start and end dates.
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
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. |
A date.
The format pattern.
An optional locale. Defaults to the current browser locale.
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')
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. |
Date string
Date parse format
An optional timezone. Defaults to the local timezone.
An optional locale. Defaults to the current locale.
The date, or null if parsing failed.
Find the nearest business date.
The start date.
If true a future date is preferred if both directions have the same cost. Defaults to true.
The calendar to use to identify business days. Defaults to the weekend calendar.
The nearest business date.
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
The date.
The week of the year.
Find the week year for a given date.
The date.
The week year.
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)
The date.
The business day conventions. Defaults to BusinessDayConvention.FOLLOWING.
If true prefer the nearest business day in the future. Defaults to true.
An optional holiday calendar. Defaults to calWeekend.
The adjusted date.
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
The date
The day of the year
Find the index of the first date with the given day of the month.
The dates
The day of the month to check
The index of the first match, or -1.
Find the index of the first date that is the end of the month.
The dates
The index of the first match, or -1.
Find the index of the last date with the given day of the month.
The dates
The day of the month to check
The index of the last match, or -1.
Find the index of the last date that is the end of the month.
The dates
The index of the last match, or -1.
Find the index of the last date that is the start of the month.
The dates
The index of the last match, or -1.
Find the index of the last date with the given weekday.
The dates
The weekday to check
The index of the last match, or -1.
Find the index of the first date that is the start of the month.
The dates
The index of the first match, or -1.
Find the index of the first date with the given weekday.
The dates
The weekday to check
The index of the first match, or -1.
Get the locale information.
A populated LocalInfo
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
The value to check.
True if the value is a valid date.
Find the ISO week date.
import { DateTz, isoWeekDate } from '@jetblack/date-tz'
console.log(isoWeekDate(new DateTz(2000, 1, 1)))
// [1999, 52, 6]
The date
The ISO date as a year, week, and day.
Find the ISO week of the year.
The date.
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)
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+??:??"
The date to round
The start of the day of the rounded date.
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
The start date.
The end date.
The day step count.
The range of dates separated by step days from the start to the end date.
Creates a schedule of dates for a periodicity.
The periodicity.
The start date.
Start offset periods.
The number of periods.
The period step count.
The schedule of dates.
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+??:??']
The start date.
Start offset days.
The number of days.
The days step count.
The schedule of dates separated by step days.
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+??:??']
The start date.
Start offset months.
The number of months.
The months step count.
The schedule of dates separated by step months.
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+??:??']
The start date.
Start offset quarters.
The number of quarters.
The quarters step count.
The schedule of dates separated by step quarter.
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+??:??']
The start date.
Start offset weeks.
The number of weeks.
The weeks step count.
The schedule of dates separated by step weeks.
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+??:??']
The start date.
Start offset years.
The number of years.
The years step count.
The schedule of dates separated by step years.
Transform the values of a timezone offset.
The object to transform.
The transformed object.
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
The timezone name.
The database version.
The root url.
Fetch options
A promise resolving to the timezone.
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']
The database version.
The root url.
Fetch options
A promise resolving to the list of time zone names.
Transform the values of a minified timezone offset.
The object to transform.
The transformed object.
Create a timezone from JSON data.
The JSON data requires transformation to convert date and duration strings to objects.
The timezone name.
The JSON timezone data.
The new timezone.
A JSON.parse reviver for tzdata.
The JSON key.
The JSON value.
A revived value if applicable.
Generated using TypeDoc
Day periods: morning, afternoon.