diff --git a/docs/en/reference/additionally/settings.mdx b/docs/en/reference/additionally/settings.mdx index e1892621..09a4b23c 100644 --- a/docs/en/reference/additionally/settings.mdx +++ b/docs/en/reference/additionally/settings.mdx @@ -44,17 +44,19 @@ This parameter sets the start of the week in accordance with the international s ## settings.range.min -`Type: String` +`Type: String | Date` `Default: '1970-01-01'` -`Options: 'YYYY-MM-DD'` +`Options: 'YYYY-MM-DD' | Date` ```js new VanillaCalendar('#calendar', { settings: { range: { min: '2022-07-01', + // or + min: new Date('2018-01-01'), } }, }); @@ -70,17 +72,19 @@ This parameter sets the minimum date that the user can choose. Dates earlier tha ## settings.range.max -`Type: String` +`Type: String | Date` `Default: '2470-12-31'` -`Options: 'YYYY-MM-DD'` +`Options: 'YYYY-MM-DD' | Date` ```js new VanillaCalendar('#calendar', { settings: { range: { max: '2024-07-01', + // or + max: new Date('2018-01-01'), } }, }); @@ -185,17 +189,17 @@ This parameter allows you to disable specified weekdays. Specify an array with n ## settings.range.disabled -`Type: String[]` +`Type: String[] | Date[]` `Default: null` -`Options: ['YYYY-MM-DD'] | null` +`Options: ['YYYY-MM-DD'] | [Date] | null` ```js new VanillaCalendar('#calendar', { settings: { range: { - disabled: ['2022-08-10:2022-08-15', '2022-08-20'], + disabled: ['2022-08-10:2022-08-15', '2022-08-20', new Date()], } }, }); @@ -215,13 +219,13 @@ This parameter allows you to disable specific dates regardless of the specified `Default: null` -`Options: ['YYYY-MM-DD'] | null` +`Options: ['YYYY-MM-DD'] | [Date] | null` ```js new VanillaCalendar('#calendar', { settings: { range: { - enabled: ['2022-08-11:2022-08-16', '2022-08-20'], + enabled: ['2022-08-11:2022-08-16', '2022-08-20', new Date()], } }, }); @@ -413,17 +417,17 @@ This option allows you to enable/disable cancellation of the selected date by pr ## settings.selected.dates -`Type: String[]` +`Type: String[] | Date[]` `Default: null` -`Options: ['YYYY-MM-DD'] | null` +`Options: ['YYYY-MM-DD'] | [Date] | null` ```js new VanillaCalendar('#calendar', { settings: { selected: { - dates: ['2022-08-10:2022-08-15', '2022-08-20'], + dates: ['2022-08-10:2022-08-15', '2022-08-20', new Date()], }, }, }); @@ -483,17 +487,17 @@ This parameter determines the year that will be displayed when the calendar is i ## settings.selected.holidays -`Type: String[]` +`Type: String[] | Date[]` `Default: null` -`Options: ['YYYY-MM-DD'] | null` +`Options: ['YYYY-MM-DD'] | [Date] | null` ```js new VanillaCalendar('#calendar', { settings: { selected: { - holidays: ['2022-08-10:2022-08-15', '2022-08-20'], + holidays: ['2022-08-10:2022-08-15', '2022-08-20', new Date()], }, }, }); diff --git a/docs/en/reference/main/main-settings.mdx b/docs/en/reference/main/main-settings.mdx index 7b15387d..e4e30d00 100644 --- a/docs/en/reference/main/main-settings.mdx +++ b/docs/en/reference/main/main-settings.mdx @@ -76,7 +76,7 @@ The `jumpMonths` parameter controls the number of months to jump. ## date.min -`Type: String` +`Type: String | Date` `Default: '1970-01-01'` @@ -86,6 +86,8 @@ The `jumpMonths` parameter controls the number of months to jump. new VanillaCalendar('#calendar', { date: { min: '1970-01-01', + // or + min: new Date('2018-01-01'), }, }); ``` @@ -96,7 +98,7 @@ The `date.min` parameter sets the minimum allowable date that the calendar will ## date.max -`Type: String` +`Type: String | Date` `Default: '2470-12-31'` @@ -106,6 +108,8 @@ The `date.min` parameter sets the minimum allowable date that the calendar will new VanillaCalendar('#calendar', { date: { max: '2470-12-31', + // or + max: new Date('2018-01-01'), }, }); ``` diff --git a/package/src/scripts/helpers/parseDates.ts b/package/src/scripts/helpers/parseDates.ts index 76606388..be926b5d 100644 --- a/package/src/scripts/helpers/parseDates.ts +++ b/package/src/scripts/helpers/parseDates.ts @@ -2,8 +2,11 @@ import { FormatDateString } from '@package/types'; import getDateString from '@scripts/helpers/getDateString'; import getDate from '@scripts/helpers/getDate'; -const parseDates = (dates: string[]): FormatDateString[] => dates.reduce((accumulator: FormatDateString[], date) => { - if (date.match(/^(\d{4}-\d{2}-\d{2})$/g)) { +const parseDates = (dates: Array): FormatDateString[] => dates.reduce((accumulator: FormatDateString[], date) => { + if (date instanceof Date || typeof date === 'number') { + const d = date instanceof Date ? date : new Date(date); + accumulator.push(d.toISOString().substring(0, 10) as FormatDateString); + } else if (date.match(/^(\d{4}-\d{2}-\d{2})$/g)) { accumulator.push(date as FormatDateString); } else { date.replace(/(\d{4}-\d{2}-\d{2}).*?(\d{4}-\d{2}-\d{2})/g, (_, startDateStr, endDateStr) => { diff --git a/package/types.ts b/package/types.ts index 5ca991e6..705a003e 100644 --- a/package/types.ts +++ b/package/types.ts @@ -38,7 +38,7 @@ export interface ISelection { } export interface ISelected { - dates?: string[]; + dates?: Array; month?: number; year?: number; holidays?: string[];