: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
endOfDesiredMonth.getFullYear(),
endOfDesiredMonth.getMonth(),
let index_es_defaultOptions = {};
function getDefaultOptions() {
return index_es_defaultOptions;
* The {@link startOfWeek} function options.
* @summary Return the start of a week for the given date.
* Return the start of a week for the given date.
* The result will be in the local timezone.
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
* @param date - The original date
* @param options - An object with options
* @returns The start of a week
* // The start of a week for 2 September 2014 11:55:00:
* const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0))
* //=> Sun Aug 31 2014 00:00:00
* // If the week starts on Monday, the start of the week for 2 September 2014 11:55:00:
* const result = startOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
* //=> Mon Sep 01 2014 00:00:00
function startOfWeek(date, options) {
const defaultOptions = getDefaultOptions();
options?.locale?.options?.weekStartsOn ??
defaultOptions.weekStartsOn ??
defaultOptions.locale?.options?.weekStartsOn ??
const _date = toDate(date);
const day = _date.getDay();
const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
_date.setDate(_date.getDate() - diff);
_date.setHours(0, 0, 0, 0);
* @summary Return the start of a day for the given date.
* Return the start of a day for the given date.
* The result will be in the local timezone.
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
* @param date - The original date
* @returns The start of a day
* // The start of a day for 2 September 2014 11:55:00:
* const result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))
* //=> Tue Sep 02 2014 00:00:00
function startOfDay(date) {
const _date = toDate(date);
_date.setHours(0, 0, 0, 0);
* @summary Add the specified number of weeks to the given date.
* Add the specified number of week to the given date.
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
* @param date - The date to be changed
* @param amount - The amount of weeks to be added.
* @returns The new date with the weeks added
* // Add 4 weeks to 1 September 2014:
* const result = addWeeks(new Date(2014, 8, 1), 4)
* //=> Mon Sep 29 2014 00:00:00
function addWeeks(date, amount) {
return addDays(date, days);
* @summary Add the specified number of years to the given date.
* Add the specified number of years to the given date.
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
* @param date - The date to be changed
* @param amount - The amount of years to be added.
* @returns The new date with the years added
* // Add 5 years to 1 September 2014:
* const result = addYears(new Date(2014, 8, 1), 5)
* //=> Sun Sep 01 2019 00:00:00
function addYears(date, amount) {
return addMonths(date, amount * 12);
* @category Month Helpers
* @summary Return the end of a month for the given date.
* Return the end of a month for the given date.
* The result will be in the local timezone.
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
* @param date - The original date
* @returns The end of a month
* // The end of a month for 2 September 2014 11:55:00:
* const result = endOfMonth(new Date(2014, 8, 2, 11, 55, 0))
* //=> Tue Sep 30 2014 23:59:59.999
function endOfMonth(date) {
const _date = toDate(date);
const month = _date.getMonth();
_date.setFullYear(_date.getFullYear(), month + 1, 0);
_date.setHours(23, 59, 59, 999);
* The {@link eachDayOfInterval} function options.
* @name eachDayOfInterval
* @category Interval Helpers
* @summary Return the array of dates within the specified time interval.
* Return the array of dates within the specified time interval.
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
* @param interval - The interval.
* @param options - An object with options.
* @returns The array with starts of days from the day of the interval start to the day of the interval end
* // Each day between 6 October 2014 and 10 October 2014:
* const result = eachDayOfInterval({
* start: new Date(2014, 9, 6),
* end: new Date(2014, 9, 10)
* // Mon Oct 06 2014 00:00:00,
* // Tue Oct 07 2014 00:00:00,
* // Wed Oct 08 2014 00:00:00,
* // Thu Oct 09 2014 00:00:00,
* // Fri Oct 10 2014 00:00:00
function eachDayOfInterval(interval, options) {
const startDate = toDate(interval.start);
const endDate = toDate(interval.end);
let reversed = +startDate > +endDate;
const endTime = reversed ? +startDate : +endDate;
const currentDate = reversed ? endDate : startDate;
currentDate.setHours(0, 0, 0, 0);
let step = options?.step ?? 1;
while (+currentDate <= endTime) {
dates.push(toDate(currentDate));
currentDate.setDate(currentDate.getDate() + step);
currentDate.setHours(0, 0, 0, 0);
return reversed ? dates.reverse() : dates;
* The {@link eachMonthOfInterval} function options.
* @name eachMonthOfInterval
* @category Interval Helpers
* @summary Return the array of months within the specified time interval.
* Return the array of months within the specified time interval.
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
* @param interval - The interval
* @returns The array with starts of months from the month of the interval start to the month of the interval end
* // Each month between 6 February 2014 and 10 August 2014:
* const result = eachMonthOfInterval({
* start: new Date(2014, 1, 6),
* end: new Date(2014, 7, 10)
* // Sat Feb 01 2014 00:00:00,
* // Sat Mar 01 2014 00:00:00,
* // Tue Apr 01 2014 00:00:00,
* // Thu May 01 2014 00:00:00,
* // Sun Jun 01 2014 00:00:00,
* // Tue Jul 01 2014 00:00:00,
* // Fri Aug 01 2014 00:00:00
function eachMonthOfInterval(interval, options) {
const startDate = toDate(interval.start);
const endDate = toDate(interval.end);
let reversed = +startDate > +endDate;
const endTime = reversed ? +startDate : +endDate;
const currentDate = reversed ? endDate : startDate;
currentDate.setHours(0, 0, 0, 0);
let step = options?.step ?? 1;
while (+currentDate <= endTime) {
dates.push(toDate(currentDate));
currentDate.setMonth(currentDate.getMonth() + step);
return reversed ? dates.reverse() : dates;
* The {@link eachWeekOfInterval} function options.
* @name eachWeekOfInterval
* @category Interval Helpers
* @summary Return the array of weeks within the specified time interval.
* Return the array of weeks within the specified time interval.
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
* @param interval - The interval.
* @param options - An object with options.
* @returns The array with starts of weeks from the week of the interval start to the week of the interval end
* // Each week within interval 6 October 2014 - 23 November 2014:
* const result = eachWeekOfInterval({
* start: new Date(2014, 9, 6),
* end: new Date(2014, 10, 23)
* // Sun Oct 05 2014 00:00:00,
* // Sun Oct 12 2014 00:00:00,
* // Sun Oct 19 2014 00:00:00,
* // Sun Oct 26 2014 00:00:00,
* // Sun Nov 02 2014 00:00:00,
* // Sun Nov 09 2014 00:00:00,
* // Sun Nov 16 2014 00:00:00,
* // Sun Nov 23 2014 00:00:00
function eachWeekOfInterval(interval, options) {
const startDate = toDate(interval.start);
const endDate = toDate(interval.end);
let reversed = +startDate > +endDate;
const startDateWeek = reversed
? startOfWeek(endDate, options)
: startOfWeek(startDate, options);
const endDateWeek = reversed
? startOfWeek(startDate, options)
: startOfWeek(endDate, options);
// Some timezones switch DST at midnight, making start of day unreliable in these timezones, 3pm is a safe bet
startDateWeek.setHours(15);
endDateWeek.setHours(15);
const endTime = +endDateWeek.getTime();
let currentDate = startDateWeek;
let step = options?.step ?? 1;
while (+currentDate <= endTime) {
dates.push(toDate(currentDate));
currentDate = addWeeks(currentDate, step);
currentDate.setHours(15);
return reversed ? dates.reverse() : dates;
* @category Month Helpers
* @summary Return the start of a month for the given date.
* Return the start of a month for the given date.
* The result will be in the local timezone.
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
* @param date - The original date
* @returns The start of a month
* // The start of a month for 2 September 2014 11:55:00:
* const result = startOfMonth(new Date(2014, 8, 2, 11, 55, 0))
* //=> Mon Sep 01 2014 00:00:00
function startOfMonth(date) {
const _date = toDate(date);
_date.setHours(0, 0, 0, 0);
* The {@link endOfWeek} function options.
* @summary Return the end of a week for the given date.
* Return the end of a week for the given date.
* The result will be in the local timezone.
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
* @param date - The original date
* @param options - An object with options
* @returns The end of a week
* // The end of a week for 2 September 2014 11:55:00:
* const result = endOfWeek(new Date(2014, 8, 2, 11, 55, 0))
* //=> Sat Sep 06 2014 23:59:59.999
* // If the week starts on Monday, the end of the week for 2 September 2014 11:55:00:
* const result = endOfWeek(new Date(2014, 8, 2, 11, 55, 0), { weekStartsOn: 1 })
* //=> Sun Sep 07 2014 23:59:59.999
function endOfWeek(date, options) {
const defaultOptions = getDefaultOptions();
options?.locale?.options?.weekStartsOn ??
defaultOptions.weekStartsOn ??
defaultOptions.locale?.options?.weekStartsOn ??
const _date = toDate(date);
const day = _date.getDay();
const diff = (day < weekStartsOn ? -7 : 0) + 6 - (day - weekStartsOn);
_date.setDate(_date.getDate() + diff);
_date.setHours(23, 59, 59, 999);
* @category Month Helpers
* @summary Get the number of days in a month of the given date.
* Get the number of days in a month of the given date.
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
* @param date - The given date
* @returns The number of days in a month
* // How many days are in February 2000?
* const result = getDaysInMonth(new Date(2000, 1))
function getDaysInMonth(date) {
const _date = toDate(date);
const year = _date.getFullYear();
const monthIndex = _date.getMonth();
const lastDayOfMonth = constructFrom(date, 0);
lastDayOfMonth.setFullYear(year, monthIndex + 1, 0);
lastDayOfMonth.setHours(0, 0, 0, 0);
return lastDayOfMonth.getDate();
* @category Common Helpers
* @summary Is the first date after the second one?
* Is the first date after the second one?
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
* @param date - The date that should be after the other one to return true
* @param dateToCompare - The date to compare with
* @returns The first date is after the second date
* // Is 10 July 1989 after 11 February 1987?
* const result = isAfter(new Date(1989, 6, 10), new Date(1987, 1, 11))
function isAfter(date, dateToCompare) {
const _date = toDate(date);
const _dateToCompare = toDate(dateToCompare);
return _date.getTime() > _dateToCompare.getTime();
* @category Common Helpers
* @summary Is the first date before the second one?
* Is the first date before the second one?
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).