@fluentui/react-datepicker-compat 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +169 -1
- package/CHANGELOG.md +43 -2
- package/dist/index.d.ts +4 -1
- package/lib/Calendar.js +0 -1
- package/lib/Calendar.js.map +1 -1
- package/lib/CalendarDay.js +0 -1
- package/lib/CalendarDay.js.map +1 -1
- package/lib/CalendarDayGrid.js +0 -1
- package/lib/CalendarDayGrid.js.map +1 -1
- package/lib/CalendarMonth.js +0 -1
- package/lib/CalendarMonth.js.map +1 -1
- package/lib/CalendarPicker.js +0 -1
- package/lib/CalendarPicker.js.map +1 -1
- package/lib/CalendarYear.js +0 -1
- package/lib/CalendarYear.js.map +1 -1
- package/lib/DatePicker.js +0 -1
- package/lib/DatePicker.js.map +1 -1
- package/lib/components/Calendar/Calendar.js +278 -300
- package/lib/components/Calendar/Calendar.js.map +1 -1
- package/lib/components/Calendar/Calendar.types.js +7 -12
- package/lib/components/Calendar/Calendar.types.js.map +1 -1
- package/lib/components/Calendar/defaults.js +0 -1
- package/lib/components/Calendar/defaults.js.map +1 -1
- package/lib/components/Calendar/index.js +0 -1
- package/lib/components/Calendar/index.js.map +1 -1
- package/lib/components/Calendar/useCalendarStyles.styles.js.map +1 -1
- package/lib/components/CalendarDay/CalendarDay.js +100 -128
- package/lib/components/CalendarDay/CalendarDay.js.map +1 -1
- package/lib/components/CalendarDay/CalendarDay.types.js +0 -1
- package/lib/components/CalendarDay/CalendarDay.types.js.map +1 -1
- package/lib/components/CalendarDay/index.js +0 -1
- package/lib/components/CalendarDay/index.js.map +1 -1
- package/lib/components/CalendarDay/useCalendarDayStyles.styles.js.map +1 -1
- package/lib/components/CalendarDayGrid/CalendarDayGrid.js +146 -159
- package/lib/components/CalendarDayGrid/CalendarDayGrid.js.map +1 -1
- package/lib/components/CalendarDayGrid/CalendarDayGrid.types.js +0 -1
- package/lib/components/CalendarDayGrid/CalendarDayGrid.types.js.map +1 -1
- package/lib/components/CalendarDayGrid/CalendarGridDayCell.js +150 -179
- package/lib/components/CalendarDayGrid/CalendarGridDayCell.js.map +1 -1
- package/lib/components/CalendarDayGrid/CalendarGridRow.js +20 -34
- package/lib/components/CalendarDayGrid/CalendarGridRow.js.map +1 -1
- package/lib/components/CalendarDayGrid/CalendarMonthHeaderRow.js +29 -39
- package/lib/components/CalendarDayGrid/CalendarMonthHeaderRow.js.map +1 -1
- package/lib/components/CalendarDayGrid/index.js +0 -1
- package/lib/components/CalendarDayGrid/index.js.map +1 -1
- package/lib/components/CalendarDayGrid/useCalendarDayGridStyles.styles.js.map +1 -1
- package/lib/components/CalendarDayGrid/useWeekCornerStyles.styles.js.map +1 -1
- package/lib/components/CalendarDayGrid/useWeeks.js +34 -36
- package/lib/components/CalendarDayGrid/useWeeks.js.map +1 -1
- package/lib/components/CalendarMonth/CalendarMonth.js +238 -258
- package/lib/components/CalendarMonth/CalendarMonth.js.map +1 -1
- package/lib/components/CalendarMonth/CalendarMonth.types.js +0 -1
- package/lib/components/CalendarMonth/CalendarMonth.types.js.map +1 -1
- package/lib/components/CalendarMonth/index.js +0 -1
- package/lib/components/CalendarMonth/index.js.map +1 -1
- package/lib/components/CalendarMonth/useCalendarMonthStyles.js +2 -4
- package/lib/components/CalendarMonth/useCalendarMonthStyles.js.map +1 -1
- package/lib/components/CalendarPicker/CalendarPicker.types.js +1 -2
- package/lib/components/CalendarPicker/CalendarPicker.types.js.map +1 -1
- package/lib/components/CalendarPicker/index.js +0 -1
- package/lib/components/CalendarPicker/index.js.map +1 -1
- package/lib/components/CalendarPicker/useCalendarPickerStyles.styles.js.map +1 -1
- package/lib/components/CalendarYear/CalendarYear.js +260 -312
- package/lib/components/CalendarYear/CalendarYear.js.map +1 -1
- package/lib/components/CalendarYear/CalendarYear.types.js +0 -1
- package/lib/components/CalendarYear/CalendarYear.types.js.map +1 -1
- package/lib/components/CalendarYear/index.js +0 -1
- package/lib/components/CalendarYear/index.js.map +1 -1
- package/lib/components/CalendarYear/useCalendarYearStyles.styles.js.map +1 -1
- package/lib/components/DatePicker/DatePicker.js +4 -5
- package/lib/components/DatePicker/DatePicker.js.map +1 -1
- package/lib/components/DatePicker/DatePicker.types.js +0 -1
- package/lib/components/DatePicker/DatePicker.types.js.map +1 -1
- package/lib/components/DatePicker/defaults.js +9 -10
- package/lib/components/DatePicker/defaults.js.map +1 -1
- package/lib/components/DatePicker/index.js +0 -1
- package/lib/components/DatePicker/index.js.map +1 -1
- package/lib/components/DatePicker/renderDatePicker.js +5 -12
- package/lib/components/DatePicker/renderDatePicker.js.map +1 -1
- package/lib/components/DatePicker/useDatePicker.js +402 -354
- package/lib/components/DatePicker/useDatePicker.js.map +1 -1
- package/lib/components/DatePicker/useDatePickerStyles.styles.js.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/utils/animations.js +72 -73
- package/lib/utils/animations.js.map +1 -1
- package/lib/utils/constants.js +50 -52
- package/lib/utils/constants.js.map +1 -1
- package/lib/utils/dateFormatting/dateFormatting.defaults.js +71 -34
- package/lib/utils/dateFormatting/dateFormatting.defaults.js.map +1 -1
- package/lib/utils/dateFormatting/dateFormatting.types.js +1 -2
- package/lib/utils/dateFormatting/dateFormatting.types.js.map +1 -1
- package/lib/utils/dateFormatting/index.js +0 -1
- package/lib/utils/dateFormatting/index.js.map +1 -1
- package/lib/utils/dateGrid/dateGrid.types.js +1 -2
- package/lib/utils/dateGrid/dateGrid.types.js.map +1 -1
- package/lib/utils/dateGrid/findAvailableDate.js +14 -21
- package/lib/utils/dateGrid/findAvailableDate.js.map +1 -1
- package/lib/utils/dateGrid/getBoundedDateRange.js +11 -11
- package/lib/utils/dateGrid/getBoundedDateRange.js.map +1 -1
- package/lib/utils/dateGrid/getDateRangeTypeToUse.js +6 -8
- package/lib/utils/dateGrid/getDateRangeTypeToUse.js.map +1 -1
- package/lib/utils/dateGrid/getDayGrid.js +59 -73
- package/lib/utils/dateGrid/getDayGrid.js.map +1 -1
- package/lib/utils/dateGrid/index.js +0 -1
- package/lib/utils/dateGrid/index.js.map +1 -1
- package/lib/utils/dateGrid/isAfterMaxDate.js +3 -7
- package/lib/utils/dateGrid/isAfterMaxDate.js.map +1 -1
- package/lib/utils/dateGrid/isBeforeMinDate.js +3 -7
- package/lib/utils/dateGrid/isBeforeMinDate.js.map +1 -1
- package/lib/utils/dateGrid/isContiguous.js +11 -12
- package/lib/utils/dateGrid/isContiguous.js.map +1 -1
- package/lib/utils/dateGrid/isRestrictedDate.js +7 -13
- package/lib/utils/dateGrid/isRestrictedDate.js.map +1 -1
- package/lib/utils/dateMath/dateMath.js +179 -198
- package/lib/utils/dateMath/dateMath.js.map +1 -1
- package/lib/utils/dateMath/index.js +0 -1
- package/lib/utils/dateMath/index.js.map +1 -1
- package/lib/utils/dom.js +5 -6
- package/lib/utils/dom.js.map +1 -1
- package/lib/utils/focus.js +17 -19
- package/lib/utils/focus.js.map +1 -1
- package/lib/utils/index.js +0 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/usePopupPositioning.js +12 -16
- package/lib/utils/usePopupPositioning.js.map +1 -1
- package/lib-commonjs/Calendar.js +0 -3
- package/lib-commonjs/Calendar.js.map +1 -1
- package/lib-commonjs/CalendarDay.js +0 -3
- package/lib-commonjs/CalendarDay.js.map +1 -1
- package/lib-commonjs/CalendarDayGrid.js +0 -3
- package/lib-commonjs/CalendarDayGrid.js.map +1 -1
- package/lib-commonjs/CalendarMonth.js +0 -3
- package/lib-commonjs/CalendarMonth.js.map +1 -1
- package/lib-commonjs/CalendarPicker.js +0 -3
- package/lib-commonjs/CalendarPicker.js.map +1 -1
- package/lib-commonjs/CalendarYear.js +0 -3
- package/lib-commonjs/CalendarYear.js.map +1 -1
- package/lib-commonjs/DatePicker.js +0 -3
- package/lib-commonjs/DatePicker.js.map +1 -1
- package/lib-commonjs/components/Calendar/Calendar.js +1 -3
- package/lib-commonjs/components/Calendar/Calendar.js.map +1 -1
- package/lib-commonjs/components/Calendar/Calendar.types.js +5 -7
- package/lib-commonjs/components/Calendar/Calendar.types.js.map +1 -1
- package/lib-commonjs/components/Calendar/defaults.js +1 -3
- package/lib-commonjs/components/Calendar/defaults.js.map +1 -1
- package/lib-commonjs/components/Calendar/index.js +0 -3
- package/lib-commonjs/components/Calendar/index.js.map +1 -1
- package/lib-commonjs/components/Calendar/useCalendarStyles.styles.js +0 -2
- package/lib-commonjs/components/Calendar/useCalendarStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarDay/CalendarDay.js +1 -3
- package/lib-commonjs/components/CalendarDay/CalendarDay.js.map +1 -1
- package/lib-commonjs/components/CalendarDay/CalendarDay.types.js +0 -3
- package/lib-commonjs/components/CalendarDay/CalendarDay.types.js.map +1 -1
- package/lib-commonjs/components/CalendarDay/index.js +0 -3
- package/lib-commonjs/components/CalendarDay/index.js.map +1 -1
- package/lib-commonjs/components/CalendarDay/useCalendarDayStyles.styles.js +0 -2
- package/lib-commonjs/components/CalendarDay/useCalendarDayStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarDayGrid.js +7 -9
- package/lib-commonjs/components/CalendarDayGrid/CalendarDayGrid.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarDayGrid.types.js +0 -3
- package/lib-commonjs/components/CalendarDayGrid/CalendarDayGrid.types.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarGridDayCell.js +1 -3
- package/lib-commonjs/components/CalendarDayGrid/CalendarGridDayCell.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarGridRow.js +1 -3
- package/lib-commonjs/components/CalendarDayGrid/CalendarGridRow.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/CalendarMonthHeaderRow.js +1 -3
- package/lib-commonjs/components/CalendarDayGrid/CalendarMonthHeaderRow.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/index.js +0 -3
- package/lib-commonjs/components/CalendarDayGrid/index.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/useCalendarDayGridStyles.styles.js +0 -2
- package/lib-commonjs/components/CalendarDayGrid/useCalendarDayGridStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/useWeekCornerStyles.styles.js +0 -2
- package/lib-commonjs/components/CalendarDayGrid/useWeekCornerStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarDayGrid/useWeeks.js +9 -11
- package/lib-commonjs/components/CalendarDayGrid/useWeeks.js.map +1 -1
- package/lib-commonjs/components/CalendarMonth/CalendarMonth.js +1 -3
- package/lib-commonjs/components/CalendarMonth/CalendarMonth.js.map +1 -1
- package/lib-commonjs/components/CalendarMonth/CalendarMonth.types.js +0 -3
- package/lib-commonjs/components/CalendarMonth/CalendarMonth.types.js.map +1 -1
- package/lib-commonjs/components/CalendarMonth/index.js +0 -3
- package/lib-commonjs/components/CalendarMonth/index.js.map +1 -1
- package/lib-commonjs/components/CalendarMonth/useCalendarMonthStyles.js +1 -3
- package/lib-commonjs/components/CalendarMonth/useCalendarMonthStyles.js.map +1 -1
- package/lib-commonjs/components/CalendarPicker/CalendarPicker.types.js +0 -3
- package/lib-commonjs/components/CalendarPicker/CalendarPicker.types.js.map +1 -1
- package/lib-commonjs/components/CalendarPicker/index.js +0 -3
- package/lib-commonjs/components/CalendarPicker/index.js.map +1 -1
- package/lib-commonjs/components/CalendarPicker/useCalendarPickerStyles.styles.js +0 -2
- package/lib-commonjs/components/CalendarPicker/useCalendarPickerStyles.styles.js.map +1 -1
- package/lib-commonjs/components/CalendarYear/CalendarYear.js +1 -3
- package/lib-commonjs/components/CalendarYear/CalendarYear.js.map +1 -1
- package/lib-commonjs/components/CalendarYear/CalendarYear.types.js +0 -3
- package/lib-commonjs/components/CalendarYear/CalendarYear.types.js.map +1 -1
- package/lib-commonjs/components/CalendarYear/index.js +0 -3
- package/lib-commonjs/components/CalendarYear/index.js.map +1 -1
- package/lib-commonjs/components/CalendarYear/useCalendarYearStyles.styles.js +0 -2
- package/lib-commonjs/components/CalendarYear/useCalendarYearStyles.styles.js.map +1 -1
- package/lib-commonjs/components/DatePicker/DatePicker.js +1 -3
- package/lib-commonjs/components/DatePicker/DatePicker.js.map +1 -1
- package/lib-commonjs/components/DatePicker/DatePicker.types.js +0 -3
- package/lib-commonjs/components/DatePicker/DatePicker.types.js.map +1 -1
- package/lib-commonjs/components/DatePicker/defaults.js +1 -3
- package/lib-commonjs/components/DatePicker/defaults.js.map +1 -1
- package/lib-commonjs/components/DatePicker/index.js +0 -3
- package/lib-commonjs/components/DatePicker/index.js.map +1 -1
- package/lib-commonjs/components/DatePicker/renderDatePicker.js +1 -3
- package/lib-commonjs/components/DatePicker/renderDatePicker.js.map +1 -1
- package/lib-commonjs/components/DatePicker/useDatePicker.js +14 -17
- package/lib-commonjs/components/DatePicker/useDatePicker.js.map +1 -1
- package/lib-commonjs/components/DatePicker/useDatePickerStyles.styles.js +0 -2
- package/lib-commonjs/components/DatePicker/useDatePickerStyles.styles.js.map +1 -1
- package/lib-commonjs/index.js +0 -3
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/animations.js +4 -6
- package/lib-commonjs/utils/animations.js.map +1 -1
- package/lib-commonjs/utils/constants.js +7 -9
- package/lib-commonjs/utils/constants.js.map +1 -1
- package/lib-commonjs/utils/dateFormatting/dateFormatting.defaults.js +1 -3
- package/lib-commonjs/utils/dateFormatting/dateFormatting.defaults.js.map +1 -1
- package/lib-commonjs/utils/dateFormatting/dateFormatting.types.js +0 -3
- package/lib-commonjs/utils/dateFormatting/dateFormatting.types.js.map +1 -1
- package/lib-commonjs/utils/dateFormatting/index.js +0 -3
- package/lib-commonjs/utils/dateFormatting/index.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/dateGrid.types.js +0 -3
- package/lib-commonjs/utils/dateGrid/dateGrid.types.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/findAvailableDate.js +1 -3
- package/lib-commonjs/utils/dateGrid/findAvailableDate.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/getBoundedDateRange.js +1 -3
- package/lib-commonjs/utils/dateGrid/getBoundedDateRange.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/getDateRangeTypeToUse.js +1 -3
- package/lib-commonjs/utils/dateGrid/getDateRangeTypeToUse.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/getDayGrid.js +1 -3
- package/lib-commonjs/utils/dateGrid/getDayGrid.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/index.js +0 -3
- package/lib-commonjs/utils/dateGrid/index.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/isAfterMaxDate.js +1 -3
- package/lib-commonjs/utils/dateGrid/isAfterMaxDate.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/isBeforeMinDate.js +1 -3
- package/lib-commonjs/utils/dateGrid/isBeforeMinDate.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/isContiguous.js +1 -3
- package/lib-commonjs/utils/dateGrid/isContiguous.js.map +1 -1
- package/lib-commonjs/utils/dateGrid/isRestrictedDate.js +1 -3
- package/lib-commonjs/utils/dateGrid/isRestrictedDate.js.map +1 -1
- package/lib-commonjs/utils/dateMath/dateMath.js +1 -3
- package/lib-commonjs/utils/dateMath/dateMath.js.map +1 -1
- package/lib-commonjs/utils/dateMath/index.js +0 -3
- package/lib-commonjs/utils/dateMath/index.js.map +1 -1
- package/lib-commonjs/utils/dom.js +1 -3
- package/lib-commonjs/utils/dom.js.map +1 -1
- package/lib-commonjs/utils/focus.js +1 -3
- package/lib-commonjs/utils/focus.js.map +1 -1
- package/lib-commonjs/utils/index.js +0 -3
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/usePopupPositioning.js +1 -3
- package/lib-commonjs/utils/usePopupPositioning.js.map +1 -1
- package/package.json +14 -14
|
@@ -3,17 +3,16 @@
|
|
|
3
3
|
* @param days - list of days in a week
|
|
4
4
|
* @param isSingleWeek - decides whether the contiguous logic applies across week boundaries or not
|
|
5
5
|
* @param firstDayOfWeek - decides which day of week is the first one in the order.
|
|
6
|
-
*/export const isContiguous = (days, isSingleWeek, firstDayOfWeek)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
*/ export const isContiguous = (days, isSingleWeek, firstDayOfWeek)=>{
|
|
7
|
+
const daySet = new Set(days);
|
|
8
|
+
let amountOfNoNeighbors = 0;
|
|
9
|
+
for (const day of days){
|
|
10
|
+
const nextDay = (day + 1) % 7;
|
|
11
|
+
if (!(daySet.has(nextDay) && (!isSingleWeek || firstDayOfWeek !== nextDay))) {
|
|
12
|
+
amountOfNoNeighbors++;
|
|
13
|
+
}
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return amountOfNoNeighbors < 2;
|
|
15
|
+
// In case the full week is provided, then each day has a neighbor
|
|
16
|
+
//, otherwise the last day does not have a neighbor.
|
|
17
|
+
return amountOfNoNeighbors < 2;
|
|
18
18
|
};
|
|
19
|
-
//# sourceMappingURL=isContiguous.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["isContiguous.ts"],"sourcesContent":["import { DayOfWeek } from '../constants';\n\n/**\n * Returns whether provided week days are contiguous.\n * @param days - list of days in a week\n * @param isSingleWeek - decides whether the contiguous logic applies across week boundaries or not\n * @param firstDayOfWeek - decides which day of week is the first one in the order.\n */\nexport const isContiguous = (days: DayOfWeek[], isSingleWeek: boolean, firstDayOfWeek: DayOfWeek): boolean => {\n const daySet = new Set(days);\n let amountOfNoNeighbors = 0;\n for (const day of days) {\n const nextDay = (day + 1) % 7;\n if (!(daySet.has(nextDay) && (!isSingleWeek || firstDayOfWeek !== nextDay))) {\n amountOfNoNeighbors++;\n }\n }\n\n // In case the full week is provided, then each day has a neighbor\n //, otherwise the last day does not have a neighbor.\n return amountOfNoNeighbors < 2;\n};\n"],"names":["isContiguous","days","isSingleWeek","firstDayOfWeek","daySet","Set","amountOfNoNeighbors","day","nextDay","has"],"mappings":"AAEA;;;;;CAKC,GACD,OAAO,MAAMA,eAAe,CAACC,MAAmBC,cAAuBC,iBAAuC;IAC5G,MAAMC,SAAS,IAAIC,IAAIJ;IACvB,IAAIK,sBAAsB;IAC1B,KAAK,MAAMC,OAAON,KAAM;QACtB,MAAMO,UAAU,AAACD,CAAAA,MAAM,CAAA,IAAK;QAC5B,IAAI,CAAEH,CAAAA,OAAOK,GAAG,CAACD,YAAa,CAAA,CAACN,gBAAgBC,mBAAmBK,OAAM,CAAC,GAAI;YAC3EF;QACF,CAAC;IACH;IAEA,kEAAkE;IAClE,oDAAoD;IACpD,OAAOA,sBAAsB;AAC/B,EAAE"}
|
|
@@ -5,17 +5,11 @@ import { isAfterMaxDate } from './isAfterMaxDate';
|
|
|
5
5
|
* Checks if `date` falls into the restricted `options`
|
|
6
6
|
* @param date - date to check
|
|
7
7
|
* @param options - restriction options (min date, max date and list of restricted dates)
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (!restrictedDates && !minDate && !maxDate) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
const inRestrictedDates = restrictedDates && restrictedDates.some(rd => compareDates(rd, date));
|
|
19
|
-
return inRestrictedDates || isBeforeMinDate(date, options) || isAfterMaxDate(date, options);
|
|
8
|
+
*/ export const isRestrictedDate = (date, options)=>{
|
|
9
|
+
const { restrictedDates , minDate , maxDate } = options;
|
|
10
|
+
if (!restrictedDates && !minDate && !maxDate) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const inRestrictedDates = restrictedDates && restrictedDates.some((rd)=>compareDates(rd, date));
|
|
14
|
+
return inRestrictedDates || isBeforeMinDate(date, options) || isAfterMaxDate(date, options);
|
|
20
15
|
};
|
|
21
|
-
//# sourceMappingURL=isRestrictedDate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["isRestrictedDate.ts"],"sourcesContent":["import { RestrictedDatesOptions } from './dateGrid.types';\nimport { compareDates } from '../dateMath/dateMath';\nimport { isBeforeMinDate } from './isBeforeMinDate';\nimport { isAfterMaxDate } from './isAfterMaxDate';\n\n/**\n * Checks if `date` falls into the restricted `options`\n * @param date - date to check\n * @param options - restriction options (min date, max date and list of restricted dates)\n */\nexport const isRestrictedDate = (date: Date, options: RestrictedDatesOptions): boolean => {\n const { restrictedDates, minDate, maxDate } = options;\n if (!restrictedDates && !minDate && !maxDate) {\n return false;\n }\n const inRestrictedDates = restrictedDates && restrictedDates.some((rd: Date) => compareDates(rd, date));\n return inRestrictedDates || isBeforeMinDate(date, options) || isAfterMaxDate(date, options);\n};\n"],"names":["compareDates","isBeforeMinDate","isAfterMaxDate","isRestrictedDate","date","options","restrictedDates","minDate","maxDate","inRestrictedDates","some","rd"],"mappings":"AACA,SAASA,YAAY,QAAQ,uBAAuB;AACpD,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,cAAc,QAAQ,mBAAmB;AAElD;;;;CAIC,GACD,OAAO,MAAMC,mBAAmB,CAACC,MAAYC,UAA6C;IACxF,MAAM,EAAEC,gBAAe,EAAEC,QAAO,EAAEC,QAAO,EAAE,GAAGH;IAC9C,IAAI,CAACC,mBAAmB,CAACC,WAAW,CAACC,SAAS;QAC5C,OAAO,KAAK;IACd,CAAC;IACD,MAAMC,oBAAoBH,mBAAmBA,gBAAgBI,IAAI,CAAC,CAACC,KAAaX,aAAaW,IAAIP;IACjG,OAAOK,qBAAqBR,gBAAgBG,MAAMC,YAAYH,eAAeE,MAAMC;AACrF,EAAE"}
|
|
@@ -4,20 +4,18 @@ import { DateRangeType, DayOfWeek, FirstWeekOfYear, MonthOfYear, TimeConstants }
|
|
|
4
4
|
* @param date - The origin date
|
|
5
5
|
* @param days - The number of days to offset. 'days' can be negative.
|
|
6
6
|
* @returns A new Date object offset from the origin date by the given number of days
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return result;
|
|
7
|
+
*/ export function addDays(date, days) {
|
|
8
|
+
const result = new Date(date.getTime());
|
|
9
|
+
result.setDate(result.getDate() + days);
|
|
10
|
+
return result;
|
|
12
11
|
}
|
|
13
12
|
/**
|
|
14
13
|
* Returns a date offset from the given date by the specified number of weeks.
|
|
15
14
|
* @param date - The origin date
|
|
16
15
|
* @param weeks - The number of weeks to offset. 'weeks' can be negative.
|
|
17
16
|
* @returns A new Date object offset from the origin date by the given number of weeks
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
return addDays(date, weeks * TimeConstants.DaysInOneWeek);
|
|
17
|
+
*/ export function addWeeks(date, weeks) {
|
|
18
|
+
return addDays(date, weeks * TimeConstants.DaysInOneWeek);
|
|
21
19
|
}
|
|
22
20
|
/**
|
|
23
21
|
* Returns a date offset from the given date by the specified number of months.
|
|
@@ -26,18 +24,17 @@ export function addWeeks(date, weeks) {
|
|
|
26
24
|
* @param date - The origin date
|
|
27
25
|
* @param months - The number of months to offset. 'months' can be negative.
|
|
28
26
|
* @returns A new Date object offset from the origin date by the given number of months
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return result;
|
|
27
|
+
*/ export function addMonths(date, months) {
|
|
28
|
+
let result = new Date(date.getTime());
|
|
29
|
+
const newMonth = result.getMonth() + months;
|
|
30
|
+
result.setMonth(newMonth);
|
|
31
|
+
// We want to maintain the same day-of-month, but that may not be possible if the new month doesn't have enough days.
|
|
32
|
+
// Loop until we back up to a day the new month has.
|
|
33
|
+
// (Weird modulo math is due to Javascript's treatment of negative numbers in modulo)
|
|
34
|
+
if (result.getMonth() !== (newMonth % TimeConstants.MonthInOneYear + TimeConstants.MonthInOneYear) % TimeConstants.MonthInOneYear) {
|
|
35
|
+
result = addDays(result, -result.getDate());
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
41
38
|
}
|
|
42
39
|
/**
|
|
43
40
|
* Returns a date offset from the given date by the specified number of years.
|
|
@@ -46,49 +43,44 @@ export function addMonths(date, months) {
|
|
|
46
43
|
* @param date - The origin date
|
|
47
44
|
* @param years - The number of years to offset. 'years' can be negative.
|
|
48
45
|
* @returns A new Date object offset from the origin date by the given number of years
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return result;
|
|
46
|
+
*/ export function addYears(date, years) {
|
|
47
|
+
let result = new Date(date.getTime());
|
|
48
|
+
result.setFullYear(date.getFullYear() + years);
|
|
49
|
+
// We want to maintain the same day-of-month, but that may not be possible if the new month doesn't have enough days.
|
|
50
|
+
// Loop until we back up to a day the new month has.
|
|
51
|
+
// (Weird modulo math is due to Javascript's treatment of negative numbers in modulo)
|
|
52
|
+
if (result.getMonth() !== (date.getMonth() % TimeConstants.MonthInOneYear + TimeConstants.MonthInOneYear) % TimeConstants.MonthInOneYear) {
|
|
53
|
+
result = addDays(result, -result.getDate());
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
60
56
|
}
|
|
61
57
|
/**
|
|
62
58
|
* Returns a date that is the first day of the month of the provided date.
|
|
63
59
|
* @param date - The origin date
|
|
64
60
|
* @returns A new Date object with the day set to the first day of the month.
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
return new Date(date.getFullYear(), date.getMonth(), 1, 0, 0, 0, 0);
|
|
61
|
+
*/ export function getMonthStart(date) {
|
|
62
|
+
return new Date(date.getFullYear(), date.getMonth(), 1, 0, 0, 0, 0);
|
|
68
63
|
}
|
|
69
64
|
/**
|
|
70
65
|
* Returns a date that is the last day of the month of the provided date.
|
|
71
66
|
* @param date - The origin date
|
|
72
67
|
* @returns A new Date object with the day set to the last day of the month.
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
return new Date(date.getFullYear(), date.getMonth() + 1, 0, 0, 0, 0, 0);
|
|
68
|
+
*/ export function getMonthEnd(date) {
|
|
69
|
+
return new Date(date.getFullYear(), date.getMonth() + 1, 0, 0, 0, 0, 0);
|
|
76
70
|
}
|
|
77
71
|
/**
|
|
78
72
|
* Returns a date that is the first day of the year of the provided date.
|
|
79
73
|
* @param date - The origin date
|
|
80
74
|
* @returns A new Date object with the day set to the first day of the year.
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
return new Date(date.getFullYear(), 0, 1, 0, 0, 0, 0);
|
|
75
|
+
*/ export function getYearStart(date) {
|
|
76
|
+
return new Date(date.getFullYear(), 0, 1, 0, 0, 0, 0);
|
|
84
77
|
}
|
|
85
78
|
/**
|
|
86
79
|
* Returns a date that is the last day of the year of the provided date.
|
|
87
80
|
* @param date - The origin date
|
|
88
81
|
* @returns A new Date object with the day set to the last day of the year.
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
return new Date(date.getFullYear() + 1, 0, 0, 0, 0, 0, 0);
|
|
82
|
+
*/ export function getYearEnd(date) {
|
|
83
|
+
return new Date(date.getFullYear() + 1, 0, 0, 0, 0, 0, 0);
|
|
92
84
|
}
|
|
93
85
|
/**
|
|
94
86
|
* Returns a date that is a copy of the given date, aside from the month changing to the given month.
|
|
@@ -97,22 +89,20 @@ export function getYearEnd(date) {
|
|
|
97
89
|
* @param date - The origin date
|
|
98
90
|
* @param month - The 0-based index of the month to set on the date.
|
|
99
91
|
* @returns A new Date object with the given month set.
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
|
-
return addMonths(date, month - date.getMonth());
|
|
92
|
+
*/ export function setMonth(date, month) {
|
|
93
|
+
return addMonths(date, month - date.getMonth());
|
|
103
94
|
}
|
|
104
95
|
/**
|
|
105
96
|
* Compares two dates, and returns true if the two dates (not accounting for time-of-day) are equal.
|
|
106
97
|
* @returns True if the two dates represent the same date (regardless of time-of-day), false otherwise.
|
|
107
|
-
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
98
|
+
*/ export function compareDates(date1, date2) {
|
|
99
|
+
if (!date1 && !date2) {
|
|
100
|
+
return true;
|
|
101
|
+
} else if (!date1 || !date2) {
|
|
102
|
+
return false;
|
|
103
|
+
} else {
|
|
104
|
+
return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() && date1.getDate() === date2.getDate();
|
|
105
|
+
}
|
|
116
106
|
}
|
|
117
107
|
/**
|
|
118
108
|
* Compare the date parts of two dates
|
|
@@ -120,9 +110,8 @@ export function compareDates(date1, date2) {
|
|
|
120
110
|
* @param date2 - The second date to compare
|
|
121
111
|
* @returns A negative value if date1 is earlier than date2, 0 if the dates are equal, or a positive value
|
|
122
112
|
* if date1 is later than date2.
|
|
123
|
-
*/
|
|
124
|
-
|
|
125
|
-
return getDatePartHashValue(date1) - getDatePartHashValue(date2);
|
|
113
|
+
*/ export function compareDatePart(date1, date2) {
|
|
114
|
+
return getDatePartHashValue(date1) - getDatePartHashValue(date2);
|
|
126
115
|
}
|
|
127
116
|
/**
|
|
128
117
|
* Gets the date range array including the specified date. The date range array is calculated as the list
|
|
@@ -134,58 +123,62 @@ export function compareDatePart(date1, date2) {
|
|
|
134
123
|
* @param daysToSelectInDayView - The number of days to include when using dateRangeType === DateRangeType.Day
|
|
135
124
|
* for multiday view. Defaults to 1
|
|
136
125
|
* @returns An array of dates representing the date range containing the specified date.
|
|
137
|
-
*/
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
// push all days not in work week view
|
|
168
|
-
datesArray.push(nextDate);
|
|
169
|
-
} else if (workWeekDays.indexOf(nextDate.getDay()) !== -1) {
|
|
170
|
-
datesArray.push(nextDate);
|
|
126
|
+
*/ export function getDateRangeArray(date, dateRangeType, firstDayOfWeek, workWeekDays, daysToSelectInDayView = 1) {
|
|
127
|
+
const datesArray = [];
|
|
128
|
+
let startDate;
|
|
129
|
+
let endDate = null;
|
|
130
|
+
if (!workWeekDays) {
|
|
131
|
+
workWeekDays = [
|
|
132
|
+
DayOfWeek.Monday,
|
|
133
|
+
DayOfWeek.Tuesday,
|
|
134
|
+
DayOfWeek.Wednesday,
|
|
135
|
+
DayOfWeek.Thursday,
|
|
136
|
+
DayOfWeek.Friday
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
daysToSelectInDayView = Math.max(daysToSelectInDayView, 1);
|
|
140
|
+
switch(dateRangeType){
|
|
141
|
+
case DateRangeType.Day:
|
|
142
|
+
startDate = getDatePart(date);
|
|
143
|
+
endDate = addDays(startDate, daysToSelectInDayView);
|
|
144
|
+
break;
|
|
145
|
+
case DateRangeType.Week:
|
|
146
|
+
case DateRangeType.WorkWeek:
|
|
147
|
+
startDate = getStartDateOfWeek(getDatePart(date), firstDayOfWeek);
|
|
148
|
+
endDate = addDays(startDate, TimeConstants.DaysInOneWeek);
|
|
149
|
+
break;
|
|
150
|
+
case DateRangeType.Month:
|
|
151
|
+
startDate = new Date(date.getFullYear(), date.getMonth(), 1);
|
|
152
|
+
endDate = addMonths(startDate, 1);
|
|
153
|
+
break;
|
|
154
|
+
default:
|
|
155
|
+
throw new Error('Unexpected object: ' + dateRangeType);
|
|
171
156
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
157
|
+
// Populate the dates array with the dates in range
|
|
158
|
+
let nextDate = startDate;
|
|
159
|
+
do {
|
|
160
|
+
if (dateRangeType !== DateRangeType.WorkWeek) {
|
|
161
|
+
// push all days not in work week view
|
|
162
|
+
datesArray.push(nextDate);
|
|
163
|
+
} else if (workWeekDays.indexOf(nextDate.getDay()) !== -1) {
|
|
164
|
+
datesArray.push(nextDate);
|
|
165
|
+
}
|
|
166
|
+
nextDate = addDays(nextDate, 1);
|
|
167
|
+
}while (!compareDates(nextDate, endDate))
|
|
168
|
+
return datesArray;
|
|
175
169
|
}
|
|
176
170
|
/**
|
|
177
171
|
* Checks whether the specified date is in the given date range.
|
|
178
172
|
* @param date - The origin date
|
|
179
173
|
* @param dateRange - An array of dates to do the lookup on
|
|
180
174
|
* @returns True if the date matches one of the dates in the specified array, false otherwise.
|
|
181
|
-
*/
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
175
|
+
*/ export function isInDateRangeArray(date, dateRange) {
|
|
176
|
+
for (const dateInRange of dateRange){
|
|
177
|
+
if (compareDates(date, dateInRange)) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
186
180
|
}
|
|
187
|
-
|
|
188
|
-
return false;
|
|
181
|
+
return false;
|
|
189
182
|
}
|
|
190
183
|
/**
|
|
191
184
|
* Returns the week number for a date.
|
|
@@ -194,23 +187,22 @@ export function isInDateRangeArray(date, dateRange) {
|
|
|
194
187
|
* @param firstDayOfWeek - The first day of the week (0-6, Sunday = 0)
|
|
195
188
|
* @param firstWeekOfYear - The first week of the year (1-2)
|
|
196
189
|
* @returns The weeks number array for the current month.
|
|
197
|
-
*/
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return weeksArray;
|
|
190
|
+
*/ export function getWeekNumbersInMonth(weeksInMonth, firstDayOfWeek, firstWeekOfYear, navigatedDate) {
|
|
191
|
+
const selectedYear = navigatedDate.getFullYear();
|
|
192
|
+
const selectedMonth = navigatedDate.getMonth();
|
|
193
|
+
let dayOfMonth = 1;
|
|
194
|
+
const fistDayOfMonth = new Date(selectedYear, selectedMonth, dayOfMonth);
|
|
195
|
+
const endOfFirstWeek = dayOfMonth + (firstDayOfWeek + TimeConstants.DaysInOneWeek - 1) - adjustWeekDay(firstDayOfWeek, fistDayOfMonth.getDay());
|
|
196
|
+
let endOfWeekRange = new Date(selectedYear, selectedMonth, endOfFirstWeek);
|
|
197
|
+
dayOfMonth = endOfWeekRange.getDate();
|
|
198
|
+
const weeksArray = [];
|
|
199
|
+
for(let i = 0; i < weeksInMonth; i++){
|
|
200
|
+
// Get week number for end of week
|
|
201
|
+
weeksArray.push(getWeekNumber(endOfWeekRange, firstDayOfWeek, firstWeekOfYear));
|
|
202
|
+
dayOfMonth += TimeConstants.DaysInOneWeek;
|
|
203
|
+
endOfWeekRange = new Date(selectedYear, selectedMonth, dayOfMonth);
|
|
204
|
+
}
|
|
205
|
+
return weeksArray;
|
|
214
206
|
}
|
|
215
207
|
/**
|
|
216
208
|
* Returns the week number for a date.
|
|
@@ -219,63 +211,58 @@ export function getWeekNumbersInMonth(weeksInMonth, firstDayOfWeek, firstWeekOfY
|
|
|
219
211
|
* @param firstDayOfWeek - The first day of the week (0-6, Sunday = 0)
|
|
220
212
|
* @param firstWeekOfYear - The first week of the year (1-2)
|
|
221
213
|
* @returns The week's number in the year.
|
|
222
|
-
*/
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
214
|
+
*/ export function getWeekNumber(date, firstDayOfWeek, firstWeekOfYear) {
|
|
215
|
+
// First four-day week of the year - minumum days count
|
|
216
|
+
const fourDayWeek = 4;
|
|
217
|
+
switch(firstWeekOfYear){
|
|
218
|
+
case FirstWeekOfYear.FirstFullWeek:
|
|
219
|
+
return getWeekOfYearFullDays(date, firstDayOfWeek, TimeConstants.DaysInOneWeek);
|
|
220
|
+
case FirstWeekOfYear.FirstFourDayWeek:
|
|
221
|
+
return getWeekOfYearFullDays(date, firstDayOfWeek, fourDayWeek);
|
|
222
|
+
default:
|
|
223
|
+
return getFirstDayWeekOfYear(date, firstDayOfWeek);
|
|
224
|
+
}
|
|
234
225
|
}
|
|
235
226
|
/**
|
|
236
227
|
* Gets the date for the first day of the week based on the given date assuming
|
|
237
228
|
* the specified first day of the week.
|
|
238
229
|
* @param date - The date to find the beginning of the week date for.
|
|
239
230
|
* @returns A new date object representing the first day of the week containing the input date.
|
|
240
|
-
*/
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
return addDays(date, daysOffset);
|
|
231
|
+
*/ export function getStartDateOfWeek(date, firstDayOfWeek) {
|
|
232
|
+
let daysOffset = firstDayOfWeek - date.getDay();
|
|
233
|
+
if (daysOffset > 0) {
|
|
234
|
+
// If first day of week is > date, go 1 week back, to ensure resulting date is in the past.
|
|
235
|
+
daysOffset -= TimeConstants.DaysInOneWeek;
|
|
236
|
+
}
|
|
237
|
+
return addDays(date, daysOffset);
|
|
248
238
|
}
|
|
249
239
|
/**
|
|
250
240
|
* Gets the date for the last day of the week based on the given date assuming
|
|
251
241
|
* the specified first day of the week.
|
|
252
242
|
* @param date - The date to find the beginning of the week date for.
|
|
253
243
|
* @returns A new date object representing the first day of the week containing the input date.
|
|
254
|
-
*/
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
return addDays(date, daysOffset);
|
|
244
|
+
*/ export function getEndDateOfWeek(date, firstDayOfWeek) {
|
|
245
|
+
const lastDayOfWeek = firstDayOfWeek - 1 >= 0 ? firstDayOfWeek - 1 : TimeConstants.DaysInOneWeek - 1;
|
|
246
|
+
let daysOffset = lastDayOfWeek - date.getDay();
|
|
247
|
+
if (daysOffset < 0) {
|
|
248
|
+
// If last day of week is < date, go 1 week forward, to ensure resulting date is in the future.
|
|
249
|
+
daysOffset += TimeConstants.DaysInOneWeek;
|
|
250
|
+
}
|
|
251
|
+
return addDays(date, daysOffset);
|
|
263
252
|
}
|
|
264
253
|
/**
|
|
265
254
|
* Gets a new date with the time portion zeroed out, i.e., set to midnight
|
|
266
255
|
* @param date - The origin date
|
|
267
256
|
* @returns A new date with the time set to midnight
|
|
268
|
-
*/
|
|
269
|
-
|
|
270
|
-
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
257
|
+
*/ function getDatePart(date) {
|
|
258
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
271
259
|
}
|
|
272
260
|
/**
|
|
273
261
|
* Helper function to assist in date comparisons
|
|
274
|
-
*/
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
return date.getDate() + (date.getMonth() << 5) + (date.getFullYear() << 9);
|
|
262
|
+
*/ export function getDatePartHashValue(date) {
|
|
263
|
+
// Generate date hash value created as sum of Date (up to 31 = 5 bits), Month (up to 11 = 4 bits) and Year.
|
|
264
|
+
// eslint-disable-next-line no-bitwise
|
|
265
|
+
return date.getDate() + (date.getMonth() << 5) + (date.getFullYear() << 9);
|
|
279
266
|
}
|
|
280
267
|
/**
|
|
281
268
|
* Helper function for `getWeekNumber`.
|
|
@@ -284,26 +271,25 @@ export function getDatePartHashValue(date) {
|
|
|
284
271
|
* @param firstDayOfWeek - The first day of week (0-6, Sunday = 0)
|
|
285
272
|
* @param numberOfFullDays - week settings.
|
|
286
273
|
* @returns The week's number in the year.
|
|
287
|
-
*/
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
274
|
+
*/ function getWeekOfYearFullDays(date, firstDayOfWeek, numberOfFullDays) {
|
|
275
|
+
const dayOfYear = getDayOfYear(date) - 1;
|
|
276
|
+
let num = date.getDay() - dayOfYear % TimeConstants.DaysInOneWeek;
|
|
277
|
+
const lastDayOfPrevYear = new Date(date.getFullYear() - 1, MonthOfYear.December, 31);
|
|
278
|
+
const daysInYear = getDayOfYear(lastDayOfPrevYear) - 1;
|
|
279
|
+
let num2 = (firstDayOfWeek - num + 2 * TimeConstants.DaysInOneWeek) % TimeConstants.DaysInOneWeek;
|
|
280
|
+
if (num2 !== 0 && num2 >= numberOfFullDays) {
|
|
281
|
+
num2 -= TimeConstants.DaysInOneWeek;
|
|
282
|
+
}
|
|
283
|
+
let num3 = dayOfYear - num2;
|
|
284
|
+
if (num3 < 0) {
|
|
285
|
+
num -= daysInYear % TimeConstants.DaysInOneWeek;
|
|
286
|
+
num2 = (firstDayOfWeek - num + 2 * TimeConstants.DaysInOneWeek) % TimeConstants.DaysInOneWeek;
|
|
287
|
+
if (num2 !== 0 && num2 + 1 >= numberOfFullDays) {
|
|
288
|
+
num2 -= TimeConstants.DaysInOneWeek;
|
|
289
|
+
}
|
|
290
|
+
num3 = daysInYear - num2;
|
|
303
291
|
}
|
|
304
|
-
num3
|
|
305
|
-
}
|
|
306
|
-
return Math.floor(num3 / TimeConstants.DaysInOneWeek + 1);
|
|
292
|
+
return Math.floor(num3 / TimeConstants.DaysInOneWeek + 1);
|
|
307
293
|
}
|
|
308
294
|
/**
|
|
309
295
|
* Helper function for `getWeekNumber`.
|
|
@@ -311,12 +297,11 @@ function getWeekOfYearFullDays(date, firstDayOfWeek, numberOfFullDays) {
|
|
|
311
297
|
* @param date - current selected date.
|
|
312
298
|
* @param firstDayOfWeek - The first day of week (0-6, Sunday = 0)
|
|
313
299
|
* @returns The week's number in the year.
|
|
314
|
-
*/
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
return Math.floor((num + num3) / TimeConstants.DaysInOneWeek + 1);
|
|
300
|
+
*/ function getFirstDayWeekOfYear(date, firstDayOfWeek) {
|
|
301
|
+
const num = getDayOfYear(date) - 1;
|
|
302
|
+
const num2 = date.getDay() - num % TimeConstants.DaysInOneWeek;
|
|
303
|
+
const num3 = (num2 - firstDayOfWeek + 2 * TimeConstants.DaysInOneWeek) % TimeConstants.DaysInOneWeek;
|
|
304
|
+
return Math.floor((num + num3) / TimeConstants.DaysInOneWeek + 1);
|
|
320
305
|
}
|
|
321
306
|
/**
|
|
322
307
|
* Helper function for `getWeekNumber`.
|
|
@@ -326,33 +311,29 @@ function getFirstDayWeekOfYear(date, firstDayOfWeek) {
|
|
|
326
311
|
* @param dateWeekDay - shifts number forward to 1 week in case passed as true
|
|
327
312
|
* @returns The day of week adjusted to `firstDayOfWeek`; e.g. when `firstDayOfWeek` is Monday (1),
|
|
328
313
|
* Sunday becomes 7.
|
|
329
|
-
*/
|
|
330
|
-
|
|
331
|
-
return firstDayOfWeek !== DayOfWeek.Sunday && dateWeekDay < firstDayOfWeek ? dateWeekDay + TimeConstants.DaysInOneWeek : dateWeekDay;
|
|
314
|
+
*/ function adjustWeekDay(firstDayOfWeek, dateWeekDay) {
|
|
315
|
+
return firstDayOfWeek !== DayOfWeek.Sunday && dateWeekDay < firstDayOfWeek ? dateWeekDay + TimeConstants.DaysInOneWeek : dateWeekDay;
|
|
332
316
|
}
|
|
333
317
|
/**
|
|
334
318
|
* Returns the day number for a date in a year:
|
|
335
319
|
* the number of days since January 1st in the particular year.
|
|
336
320
|
* @param date - A date to find the day number for.
|
|
337
321
|
* @returns The day's number in the year.
|
|
338
|
-
*/
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
return daysUntilDate;
|
|
322
|
+
*/ function getDayOfYear(date) {
|
|
323
|
+
const month = date.getMonth();
|
|
324
|
+
const year = date.getFullYear();
|
|
325
|
+
let daysUntilDate = 0;
|
|
326
|
+
for(let i = 0; i < month; i++){
|
|
327
|
+
daysUntilDate += daysInMonth(i + 1, year);
|
|
328
|
+
}
|
|
329
|
+
daysUntilDate += date.getDate();
|
|
330
|
+
return daysUntilDate;
|
|
348
331
|
}
|
|
349
332
|
/**
|
|
350
333
|
* Returns the number of days in the month
|
|
351
334
|
* @param month - The month number to target (months 1-12).
|
|
352
335
|
* @param year - The year to target.
|
|
353
336
|
* @returns The number of days in the month.
|
|
354
|
-
*/
|
|
355
|
-
|
|
356
|
-
return new Date(year, month, 0).getDate();
|
|
337
|
+
*/ function daysInMonth(month, year) {
|
|
338
|
+
return new Date(year, month, 0).getDate();
|
|
357
339
|
}
|
|
358
|
-
//# sourceMappingURL=dateMath.js.map
|