Skip to main content

Class: DateLib

Defined in: packages/react-day-picker/src/classes/DateLib.ts:116

A wrapper class around date-fns that provides utility methods for date manipulation and formatting.

Since​

9.2.0

Example​

const dateLib = new DateLib({ locale: es });
const newDate = dateLib.addDays(new Date(), 5);

Constructors​

Constructor​

new DateLib(options?, overrides?): DateLib

Defined in: packages/react-day-picker/src/classes/DateLib.ts:129

Creates an instance of DateLib.

Parameters​

Returns​

DateLib

Methods​

addDays()​

addDays(date, amount): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:287

Adds the specified number of days to the given date.

Parameters​

Returns​

Date

The new date with the days added.


addMonths()​

addMonths(date, amount): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:300

Adds the specified number of months to the given date.

Parameters​

Returns​

Date

The new date with the months added.


addWeeks()​

addWeeks(date, amount): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:313

Adds the specified number of weeks to the given date.

Parameters​

Returns​

Date

The new date with the weeks added.


addYears()​

addYears(date, amount): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:326

Adds the specified number of years to the given date.

Parameters​

Returns​

Date

The new date with the years added.


differenceInCalendarDays()​

differenceInCalendarDays(dateLeft, dateRight): number

Defined in: packages/react-day-picker/src/classes/DateLib.ts:339

Returns the number of calendar days between the given dates.

Parameters​

Returns​

number

The number of calendar days between the dates.


differenceInCalendarMonths()​

differenceInCalendarMonths(dateLeft, dateRight): number

Defined in: packages/react-day-picker/src/classes/DateLib.ts:352

Returns the number of calendar months between the given dates.

Parameters​

Returns​

number

The number of calendar months between the dates.


eachMonthOfInterval()​

eachMonthOfInterval(interval): Date[]

Defined in: packages/react-day-picker/src/classes/DateLib.ts:363

Returns the months between the given dates.

Parameters​

Returns​

Date[]


eachYearOfInterval()​

eachYearOfInterval(interval): Date[]

Defined in: packages/react-day-picker/src/classes/DateLib.ts:376

Returns the years between the given dates.

Parameters​

Returns​

Date[]

The array of years in the interval.

Since​

9.11.1


endOfBroadcastWeek()​

endOfBroadcastWeek(date): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:401

Returns the end of the broadcast week for the given date.

Parameters​

Returns​

Date

The end of the broadcast week.


endOfISOWeek()​

endOfISOWeek(date): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:413

Returns the end of the ISO week for the given date.

Parameters​

Returns​

Date

The end of the ISO week.


endOfMonth()​

endOfMonth(date): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:425

Returns the end of the month for the given date.

Parameters​

Returns​

Date

The end of the month.


endOfWeek()​

endOfWeek(date, options?): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:437

Returns the end of the week for the given date.

Parameters​

Returns​

Date

The end of the week.


endOfYear()​

endOfYear(date): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:449

Returns the end of the year for the given date.

Parameters​

Returns​

Date

The end of the year.


format()​

format(date, formatStr, _options?): string

Defined in: packages/react-day-picker/src/classes/DateLib.ts:462

Formats the given date using the specified format string.

Parameters​

Returns​

string

The formatted date string.


formatMonthYear()​

formatMonthYear(date): string

Defined in: packages/react-day-picker/src/classes/DateLib.ts:201

Formats the month/year pair respecting locale conventions.

Parameters​

Returns​

string

Since​

9.11.0


formatNumber()​

formatNumber(value): string

Defined in: packages/react-day-picker/src/classes/DateLib.ts:180

Formats a number using the configured numbering system.

Parameters​

Returns​

string

The formatted number as a string.

Since​

9.5.0


getISOWeek()​

getISOWeek(date): number

Defined in: packages/react-day-picker/src/classes/DateLib.ts:482

Returns the ISO week number for the given date.

Parameters​

Returns​

number

The ISO week number.


getMonth()​

getMonth(date, _options?): number

Defined in: packages/react-day-picker/src/classes/DateLib.ts:494

Returns the month of the given date.

Parameters​

Returns​

number

The month.


getMonthYearOrder()​

getMonthYearOrder(): MonthYearOrder

Defined in: packages/react-day-picker/src/classes/DateLib.ts:188

Returns the preferred ordering for month and year labels for the current locale.

Returns​

MonthYearOrder


getWeek()​

getWeek(date, _options?): number

Defined in: packages/react-day-picker/src/classes/DateLib.ts:518

Returns the local week number for the given date.

Parameters​

Returns​

number

The week number.


getYear()​

getYear(date, _options?): number

Defined in: packages/react-day-picker/src/classes/DateLib.ts:506

Returns the year of the given date.

Parameters​

Returns​

number

The year.


isAfter()​

isAfter(date, dateToCompare): boolean

Defined in: packages/react-day-picker/src/classes/DateLib.ts:531

Checks if the first date is after the second date.

Parameters​

Returns​

boolean

True if the first date is after the second date.


isBefore()​

isBefore(date, dateToCompare): boolean

Defined in: packages/react-day-picker/src/classes/DateLib.ts:544

Checks if the first date is before the second date.

Parameters​

Returns​

boolean

True if the first date is before the second date.


isSameDay()​

isSameDay(dateLeft, dateRight): boolean

Defined in: packages/react-day-picker/src/classes/DateLib.ts:569

Checks if the given dates are on the same day.

Parameters​

Returns​

boolean

True if the dates are on the same day.


isSameMonth()​

isSameMonth(dateLeft, dateRight): boolean

Defined in: packages/react-day-picker/src/classes/DateLib.ts:582

Checks if the given dates are in the same month.

Parameters​

Returns​

boolean

True if the dates are in the same month.


isSameYear()​

isSameYear(dateLeft, dateRight): boolean

Defined in: packages/react-day-picker/src/classes/DateLib.ts:595

Checks if the given dates are in the same year.

Parameters​

Returns​

boolean

True if the dates are in the same year.


max()​

max(dates): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:607

Returns the latest date in the given array of dates.

Parameters​

Returns​

Date

The latest date.


min()​

min(dates): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:617

Returns the earliest date in the given array of dates.

Parameters​

Returns​

Date

The earliest date.


newDate()​

newDate(year, monthIndex, date): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:270

Creates a new Date object with the specified year, month, and day.

Parameters​

Returns​

Date

A new Date object.

Since​

9.5.0


setMonth()​

setMonth(date, month): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:628

Sets the month of the given date.

Parameters​

Returns​

Date

The new date with the month set.


setYear()​

setYear(date, year): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:641

Sets the year of the given date.

Parameters​

Returns​

Date

The new date with the year set.


startOfBroadcastWeek()​

startOfBroadcastWeek(date, _dateLib): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:653

Returns the start of the broadcast week for the given date.

Parameters​

Returns​

Date

The start of the broadcast week.


startOfDay()​

startOfDay(date): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:665

Returns the start of the day for the given date.

Parameters​

Returns​

Date

The start of the day.


startOfISOWeek()​

startOfISOWeek(date): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:677

Returns the start of the ISO week for the given date.

Parameters​

Returns​

Date

The start of the ISO week.


startOfMonth()​

startOfMonth(date): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:689

Returns the start of the month for the given date.

Parameters​

Returns​

Date

The start of the month.


startOfWeek()​

startOfWeek(date, _options?): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:701

Returns the start of the week for the given date.

Parameters​

Returns​

Date

The start of the week.


startOfYear()​

startOfYear(date): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:713

Returns the start of the year for the given date.

Parameters​

Returns​

Date

The start of the year.


today()​

today(): Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:250

Creates a new Date object representing today's date.

Returns​

Date

A Date object for today's date.

Since​

9.5.0

Properties​

isDate​

isDate: (value) => value is Date

Defined in: packages/react-day-picker/src/classes/DateLib.ts:556

Checks if the given value is a Date object.

Parameters​

Returns​

value is Date

True if the value is a Date object.


options​

readonly options: DateLibOptions

Defined in: packages/react-day-picker/src/classes/DateLib.ts:118

The options for configuring the date library.


overrides?​

readonly optional overrides?: Partial<DateLib>

Defined in: packages/react-day-picker/src/classes/DateLib.ts:121

Overrides for the default date library functions.