(locale: string, mode: Mode, firstDayOfWeek = 0)
| 71 | * or "T". |
| 72 | */ |
| 73 | export const getDaysOfWeek = (locale: string, mode: Mode, firstDayOfWeek = 0) => { |
| 74 | /** |
| 75 | * Nov 1st, 2020 starts on a Sunday. |
| 76 | * ion-datetime assumes weeks start on Sunday, |
| 77 | * but is configurable via `firstDayOfWeek`. |
| 78 | */ |
| 79 | const weekdayFormat = mode === 'ios' ? 'short' : 'narrow'; |
| 80 | const intl = new Intl.DateTimeFormat(locale, { weekday: weekdayFormat }); |
| 81 | const startDate = new Date('11/01/2020'); |
| 82 | const daysOfWeek = []; |
| 83 | |
| 84 | /** |
| 85 | * For each day of the week, |
| 86 | * get the day name. |
| 87 | */ |
| 88 | for (let i = firstDayOfWeek; i < firstDayOfWeek + 7; i++) { |
| 89 | const currentDate = new Date(startDate); |
| 90 | currentDate.setDate(currentDate.getDate() + i); |
| 91 | |
| 92 | daysOfWeek.push(intl.format(currentDate)); |
| 93 | } |
| 94 | |
| 95 | return daysOfWeek; |
| 96 | }; |
| 97 | |
| 98 | /** |
| 99 | * Returns an array containing all of the |
no test coverage detected