Working Days documentation
This package is an example of legislation as code, and can be used to determine whether or not a given day qualifies as a working day, as defined in the legislation of Aotearoa New Zealand.
This package is an example of legislation as code, and can be used to determine whether or not a given day qualifies as a working day, as defined in the legislation of Aotearoa New Zealand.
isWorkingDay(date: Date, definition: WorkingDayDefinition = WorkingDayDefinition.OIA) => boolean
Determines whether or not a given date qualifies as a working day, for a given definition. By default, the definition of working day used by the Official Information Act 1982 will be used.
date: Date
A Date
that may or may not be a working day. Only the year, month, and day portion of the Date
will be used.
definition: WorkingDayDefinition
The definition of working day to use in the determination. If this argument is ommitted, the definition used by the Official Information Act 1982 will be used.
Some definitions of days which are not working days under the Official Information Act 1982 are not defined outside certain date ranges.
Dates in the year 1953, or prior to 1952, will throw a RangeError
due to a lack of a definition for the Sovereign's Birthday.
This date is also defined for years after 1953 only in respect of every year of the reign of Her Majesty Queen Elizabeth the Second
. Elizabeth II died in September 2022, so until the Sovereign's Birthday Observance Act 1952 is amended there is no defined date for the sovereign's birthday observance day in years after 2022.
The dates of Matariki are, at the time of writing, defined only up to the year 2052. Dates from 2053 onward will throw a RangeError
due to a lack of a definition for Matariki.
The method used for calculating Easter dates is only correct for the years 1900-2199. Dates outside this range will throw a RangeError
.
Select a date to see whether or not it is considered a working day according to the definition under the Official Information Act 1982.
workingDaysBetween(startDate: Date, endDate: Date, definition: WorkingDayDefinition = WorkingDayDefinition.OIA) => number
Counts the number of working days between two dates, for a given definition. By default, the definition of working day used by the Official Information Act 1982 will be used.
startDate: Date
The first Date
in a range to count working days between.
endDate: Date
The last Date
in a range to count working days between.
definition: WorkingDayDefinition
The definition of working day to use in the determination. If this argument is ommitted, the definition used by the Official Information Act 1982 will be used.
addWorkingDays(startDate: Date, numWorkingDays: number, definition: WorkingDayDefinition = WorkingDayDefinition.OIA) => number
Determines what the date will be after a specified number of working days from a start date, for a given definition of working day. By default, the definition of working day used by the Official Information Act 1982 will be used.
startDate: Date
The Date
from which to start.
numWorkingDays: number
The number of working days to count after the starting date.
definition: WorkingDayDefinition
The definition of working day to use in the determination. If this argument is ommitted, the definition used by the Official Information Act 1982 will be used.
getHoliday(holiday: Holiday, year: number): DateTuple | null
Returns the specified holiday for the specified year.
Some holidays, such as Mondayised Anzac Day, may not exist in each year. In these cases, this function can return null
.
Other holidays have specific restrictions under which they will throw errors. For example, Matariki is not currently defined for years after 2052, so attempting to get the date of Matariki after 2052 will throw a RangeError
.
holiday: Holiday
The holiday you want to retrieve, specified using the Holiday enum exported by this package.
year: number
The year in which you want to get the date of the specified holiday.
type DateTuple = [
number, // year
number, // month
number, // day
];
The DateTuple
interface is used in place of Date
to refer to just the date portion of a Date
, ignoring any time or regional information.
The three numbers correspond with the values that would be returned by Date.getFullYear()
, Date.getMonth()
, and Date.getDate()
, respectively.
A Date
can be constructed from a DateTuple
if required via new Date(...tuple)
enum WorkingDayDefinition {
OIA,
}
This enum's members can be used when calling isWorkingDay
to specify a definition of working day to be used.
Currently, only the definition used by the Official Information Act 1982 is supported.
enum Holiday {
ANZAC_DAY,
ANZAC_DAY_MONDAYISED,
WAITANGI_DAY,
WAITANGI_DAY_MONDAYISED,
GOOD_FRIDAY,
EASTER_SUNDAY,
EASTER_MONDAY,
LABOUR_DAY,
MATARIKI,
SOVEREIGNS_BIRTHDAY,
QUEEN_ELIZABETH_II_MEMORIAL_DAY,
}
This enum's members can be used when calling getHoliday
to specify a holiday to get the date of.