Utilities
The calendar comes with its utilities, making it easy to work with date formatting.
There are 4 utilities in total, and they are functions that can be used anywhere in your code, even without the calendar.
parseDates(dates: string[])
— Takes an array of date ranges using a delimiter between dates in the string formatFormatDateString ('YYYY-MM-DD')
. Returns an array of dates in the string formatFormatDateString ('YYYY-MM-DD')
.
import { parseDates } from 'vanilla-calendar-pro/utils';
parseDates(['2024-12-12:2024-12-15']); // return: ['2024-12-12', '2024-12-13', '2024-12-14', '2024-12-15']
getDateString(date: Date)
— Takes a date of typeDate
. Returns the date in the string formatFormatDateString ('YYYY-MM-DD')
.
import { getDateString } from 'vanilla-calendar-pro/utils';
getDateString(new Date('24.12.2024')); // return: 2024-12-24
getDate(date: FormatDateString)
— Takes a date in string format, e.g.,FormatDateString ('YYYY-MM-DD')
. Returns a date of typeDate
.
import { getDate } from 'vanilla-calendar-pro/utils';
getDate('2024-12-12'); // return: Tue Dec 24 2024 00:00:00 GMT
getWeekNumber(date: FormatDateString, weekStartDay: WeekDayID)
— Takes a date in string formatFormatDateString ('YYYY-MM-DD')
and the week start day, specifically itsid
of typenumber
from 0 to 6. Returns an object{ year: yearNumber, week: weekNumber }
for the date specified in the arguments.
import { getWeekNumber } from 'vanilla-calendar-pro/utils';
getWeekNumber('2024-12-12', 1); // return: {year: 2024, week: 50}