UNPKG

@universal-material/web

Version:
32 lines 1.15 kB
export class DefaultCalendarAdapter { constructor() { this.weekDayFormat = 'narrow'; this.locale = 'pt-br'; } getWeekDays(locale) { const date = new Date(); const intlLocale = new Intl.Locale(locale); const weekInfo = intlLocale.getWeekInfo ? intlLocale.getWeekInfo() : intlLocale.weekinfo; this.#setDateToFirstDayOfWeek(date, weekInfo.firstDay); const weekDays = []; for (let i = 0; i < 7; i++) { weekDays.push(date.toLocaleDateString(locale, { weekday: this.weekDayFormat })); date.setDate(date.getDate() + 1); } return weekDays; } #setDateToFirstDayOfWeek(date, firstDayOfWeek) { const diffToFirstDayOfWeek = (firstDayOfWeek - date.getDay() + 7) % 7; date.setDate(date.getDate() + diffToFirstDayOfWeek); } getDay(date) { return date.toLocaleDateString(this.locale, { day: 'numeric' }); } getMonth(date) { return date.toLocaleDateString(this.locale, { month: 'long', year: 'numeric', }); } } //# sourceMappingURL=default-calendar-adapter.js.map