实用工具
日历附带其实用工具,使处理日期格式化变得容易。
总共有 4 个实用工具,它们是可以在代码中任何位置使用的函数,甚至无需日历。
parseDates(dates: string[])— 接受使用字符串格式FormatDateString ('YYYY-MM-DD')中日期之间的分隔符的日期范围数组。返回字符串格式FormatDateString ('YYYY-MM-DD')的日期数组。
import { parseDates } from 'vanilla-calendar-pro/utils';
parseDates(['2024-12-12:2024-12-15']); // 返回: ['2024-12-12', '2024-12-13', '2024-12-14', '2024-12-15']getDateString(date: Date)— 接受Date类型的日期。返回字符串格式FormatDateString ('YYYY-MM-DD')的日期。
import { getDateString } from 'vanilla-calendar-pro/utils';
getDateString(new Date('24.12.2024')); // 返回: 2024-12-24getDate(date: FormatDateString)— 接受字符串格式的日期,例如FormatDateString ('YYYY-MM-DD')。返回Date类型的日期。
import { getDate } from 'vanilla-calendar-pro/utils';
getDate('2024-12-12'); // 返回: Tue Dec 24 2024 00:00:00 GMTgetWeekNumber(date: FormatDateString, weekStartDay: WeekDayID)— 接受字符串格式FormatDateString ('YYYY-MM-DD')的日期和周起始日,特别是其id类型为number从 0 到 6。返回参数中指定日期的对象{ year: yearNumber, week: weekNumber }。
import { getWeekNumber } from 'vanilla-calendar-pro/utils';
getWeekNumber('2024-12-12', 1); // 返回: {year: 2024, week: 50}