* Builds the "_weeks" object that represents the month. * @param localeData * @private
(localeData: LocaleData)
| 225 | * @private |
| 226 | */ |
| 227 | _buildWeeks(localeData: LocaleData) { |
| 228 | if (this._hidden) { |
| 229 | return; // Optimization to not do any work unless the current picker |
| 230 | } |
| 231 | |
| 232 | this._weeks = []; |
| 233 | |
| 234 | const firstDayOfWeek = this._getFirstDayOfWeek(); |
| 235 | const specialCalendarDates = this._specialCalendarDates; |
| 236 | const monthsNames = localeData.getMonths("wide", this._primaryCalendarType); |
| 237 | const secondaryMonthsNames = this.hasSecondaryCalendarType ? localeData.getMonths("wide", this.secondaryCalendarType) : []; |
| 238 | const nonWorkingDayLabel = DayPicker.i18nBundle.getText(DAY_PICKER_NON_WORKING_DAY); |
| 239 | const todayLabel = DayPicker.i18nBundle.getText(DAY_PICKER_TODAY); |
| 240 | const tempDate = this._getFirstDay(); // date that will be changed by 1 day 42 times |
| 241 | const todayDate = CalendarDate.fromLocalJSDate(UI5Date.getInstance(), this._primaryCalendarType); // current day date - calculate once |
| 242 | const calendarDate = this._calendarDate; // store the _calendarDate value as this getter is expensive and degrades IE11 perf |
| 243 | |
| 244 | const minDate = this._minDate; |
| 245 | const maxDate = this._maxDate; |
| 246 | const precomputedDisabledDates = this._precomputeDisabledDates(); |
| 247 | |
| 248 | const tempSecondDate = this.hasSecondaryCalendarType ? this._getSecondaryDay(tempDate) : undefined; |
| 249 | |
| 250 | let week: Week = []; |
| 251 | for (let i = 0; i < DAYS_IN_WEEK * 6; i++) { // always show 6 weeks total, 42 days to avoid jumping |
| 252 | const timestamp = tempDate.valueOf() / 1000; // no need to round because CalendarDate does it |
| 253 | |
| 254 | let dayOfTheWeek = tempDate.getDay() - firstDayOfWeek; |
| 255 | if (dayOfTheWeek < 0) { |
| 256 | dayOfTheWeek += DAYS_IN_WEEK; |
| 257 | } |
| 258 | |
| 259 | const specialCalendarDate = specialCalendarDates.find(specialDate => specialDate.specialDateTimestamp === timestamp); |
| 260 | const specialDayType = specialCalendarDate ? specialCalendarDate.type : ""; |
| 261 | const specialDayTooltip = specialCalendarDate ? specialCalendarDate.tooltip : ""; |
| 262 | const unnamedCalendarTypeLabel = specialDayTooltip && !this._isDefaultCalendarLegendType(specialDayType) ? specialDayTooltip : ""; |
| 263 | |
| 264 | const isFocused = tempDate.getMonth() === calendarDate.getMonth() && tempDate.getDate() === calendarDate.getDate(); |
| 265 | const isSelected = this._isDaySelected(timestamp); |
| 266 | const isSelectedBetween = this._isDayInsideSelectionRange(timestamp); |
| 267 | const isOtherMonth = tempDate.getMonth() !== calendarDate.getMonth(); |
| 268 | const isWeekend = this._isWeekend(tempDate); |
| 269 | const isDisabled = !this._isDateEnabled(tempDate, minDate, maxDate, precomputedDisabledDates); |
| 270 | const isToday = tempDate.isSame(todayDate); |
| 271 | const isFirstDayOfWeek = tempDate.getDay() === firstDayOfWeek; |
| 272 | |
| 273 | const nonWorkingAriaLabel = (isWeekend || specialDayType === "NonWorking") && specialDayType !== "Working" |
| 274 | ? `${nonWorkingDayLabel} ` |
| 275 | : ""; |
| 276 | const todayAriaLabel = isToday ? `${todayLabel} ` : ""; |
| 277 | |
| 278 | const tempSecondDateNumber = tempSecondDate ? tempSecondDate.getDate() : ""; |
| 279 | const tempSecondYearNumber = tempSecondDate ? tempSecondDate.getYear() : ""; |
| 280 | const secondaryMonthsNamesString = secondaryMonthsNames.length > 0 ? secondaryMonthsNames[tempSecondDate!.getMonth()] : ""; |
| 281 | |
| 282 | const tooltip = `${todayAriaLabel}${nonWorkingAriaLabel}${unnamedCalendarTypeLabel}`.trim(); |
| 283 | |
| 284 | let ariaLabel = this.hasSecondaryCalendarType |
no test coverage detected