@daryasidorovich/modsen-datepicker 1.0.0 → 1.0.2
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/README.md +302 -302
- package/package.json +111 -106
- package/.babelrc.json +0 -7
- package/.github/workflows/chromatic.yml +0 -25
- package/.github/workflows/ci.yml +0 -56
- package/.husky/commit-msg +0 -1
- package/.husky/pre-commit +0 -1
- package/.prettierignore +0 -16
- package/.prettierrc +0 -6
- package/.storybook/main.js +0 -93
- package/.storybook/preview-head.html +0 -6
- package/.storybook/preview.js +0 -26
- package/.storybook/preview.tsx +0 -18
- package/commitlint.config.js +0 -23
- package/eslint.config.ts +0 -80
- package/jest.config.json +0 -21
- package/rollup.config.js +0 -65
- package/src/assets/actions/Delete.svg +0 -4
- package/src/assets/actions/Edit.svg +0 -3
- package/src/assets/arrows/Next.svg +0 -4
- package/src/assets/arrows/Prev.svg +0 -4
- package/src/assets/input/Calendar.svg +0 -3
- package/src/assets/input/Clear.svg +0 -3
- package/src/components/BaseCalendar/BaseCalendar.stories.tsx +0 -77
- package/src/components/BaseCalendar/index.tsx +0 -63
- package/src/components/BaseCalendar/styles.module.scss +0 -15
- package/src/components/CalendarGrid/CalendarGrid.stories.tsx +0 -136
- package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/index.tsx +0 -27
- package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/styles.module.scss +0 -9
- package/src/components/CalendarGrid/CalendarGridWithTasks/index.tsx +0 -51
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/CalendarGridWithoutTasks.test.tsx +0 -223
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/index.tsx +0 -36
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/styles.module.scss +0 -11
- package/src/components/CalendarGrid/index.tsx +0 -19
- package/src/components/CalendarGrid/types.ts +0 -26
- package/src/components/Clear/Clear.stories.tsx +0 -16
- package/src/components/Clear/index.tsx +0 -12
- package/src/components/Clear/styles.module.scss +0 -34
- package/src/components/DatePicker/DatePicker.stories.tsx +0 -127
- package/src/components/DatePicker/index.tsx +0 -72
- package/src/components/DatePicker/styles.module.scss +0 -10
- package/src/components/Day/Day.stories.tsx +0 -75
- package/src/components/Day/index.tsx +0 -95
- package/src/components/Day/styles.module.scss +0 -97
- package/src/components/Input/Input.stories.tsx +0 -37
- package/src/components/Input/index.tsx +0 -64
- package/src/components/Input/styles.module.scss +0 -79
- package/src/components/Modal/CrudModal/index.tsx +0 -43
- package/src/components/Modal/CrudModal/styles.module.scss +0 -44
- package/src/components/Modal/index.tsx +0 -66
- package/src/components/Modal/styles.module.scss +0 -40
- package/src/components/Modal/types.ts +0 -13
- package/src/components/Month/Month.stories.tsx +0 -19
- package/src/components/Month/index.tsx +0 -31
- package/src/components/Month/styles.module.scss +0 -30
- package/src/components/RangePicker/RangePicker.stories.tsx +0 -134
- package/src/components/RangePicker/index.tsx +0 -144
- package/src/components/RangePicker/styles.module.scss +0 -19
- package/src/components/TasksManager/AddModal/index.tsx +0 -62
- package/src/components/TasksManager/DeleteModal/index.tsx +0 -22
- package/src/components/TasksManager/EditModal/index.tsx +0 -96
- package/src/components/TasksManager/index.tsx +0 -112
- package/src/components/TasksManager/styles.module.scss +0 -62
- package/src/components/Week/Week.stories.tsx +0 -49
- package/src/components/Week/index.tsx +0 -68
- package/src/components/Week/styles.module.scss +0 -7
- package/src/components/WeekDay/WeekDay.stories.tsx +0 -38
- package/src/components/WeekDay/index.tsx +0 -35
- package/src/components/WeekDay/styles.module.scss +0 -19
- package/src/constants/dateMask.ts +0 -23
- package/src/constants/firstDayOfWeek.ts +0 -7
- package/src/constants/holidays.ts +0 -32
- package/src/constants/modes.ts +0 -6
- package/src/constants/monthsNames.ts +0 -14
- package/src/constants/weekdaysNames.ts +0 -1
- package/src/hooks/useCalendar.ts +0 -62
- package/src/hooks/useLockBodyScroll.ts +0 -19
- package/src/hooks/useModal.ts +0 -45
- package/src/hooks/useTooltip.ts +0 -41
- package/src/hooks/useValidate.ts +0 -80
- package/src/index.ts +0 -15
- package/src/services/calendarService.ts +0 -62
- package/src/services/decorators/withHolidays.test.ts +0 -64
- package/src/services/decorators/withHolidays.ts +0 -12
- package/src/services/decorators/withMinMax.test.ts +0 -77
- package/src/services/decorators/withMinMax.ts +0 -19
- package/src/services/holidayService.ts +0 -56
- package/src/setupTests.ts +0 -1
- package/src/store/localStorage.ts +0 -33
- package/src/store/tasksStore.test.tsx +0 -208
- package/src/store/tasksStore.tsx +0 -146
- package/src/store/types.ts +0 -22
- package/src/styles/_border.scss +0 -9
- package/src/styles/_colors.scss +0 -53
- package/src/styles/_gap.scss +0 -4
- package/src/styles/_globals.scss +0 -61
- package/src/styles/_grid.scss +0 -9
- package/src/styles/_mixins.scss +0 -6
- package/src/styles/_reset.scss +0 -98
- package/src/styles/_theme-mixins.scss +0 -51
- package/src/styles/_typography.scss +0 -10
- package/src/styles/_variables.scss +0 -8
- package/src/styles/main.scss +0 -3
- package/src/types/types.d.ts +0 -15
- package/src/utils/calendar.test.ts +0 -154
- package/src/utils/calendar.ts +0 -82
- package/src/utils/controlDate.ts +0 -3
- package/src/utils/dateChecks.test.ts +0 -216
- package/src/utils/dateChecks.ts +0 -75
- package/src/utils/formatDate.test.ts +0 -57
- package/src/utils/formatDate.ts +0 -27
- package/src/utils/schema.test.ts +0 -40
- package/src/utils/schema.ts +0 -8
- package/src/utils/weekdayOrder.test.ts +0 -11
- package/src/utils/weekdayOrder.ts +0 -7
- package/tsconfig.json +0 -31
- package/vitest.config.ts +0 -38
- package/vitest.shims.d.ts +0 -1
package/src/styles/_mixins.scss
DELETED
package/src/styles/_reset.scss
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
*,
|
|
2
|
-
::before,
|
|
3
|
-
::after {
|
|
4
|
-
box-sizing: border-box;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
:where(ul, ol):where([class]) {
|
|
8
|
-
padding-left: 0;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
body,
|
|
12
|
-
:where(blockquote, figure):where([class]) {
|
|
13
|
-
margin: 0;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
:where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl):where([class]) {
|
|
17
|
-
margin-block: 0;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
:where(dd[class]) {
|
|
21
|
-
margin-left: 0;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
:where(fieldset[class]) {
|
|
25
|
-
margin-left: 0;
|
|
26
|
-
padding: 0;
|
|
27
|
-
border: none;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
:where(ul[class]) {
|
|
31
|
-
list-style: none;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
:where(address[class]) {
|
|
35
|
-
font-style: normal;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
p {
|
|
39
|
-
margin-block: 0;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
img,
|
|
43
|
-
video {
|
|
44
|
-
display: block;
|
|
45
|
-
max-width: 100%;
|
|
46
|
-
height: auto;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
input,
|
|
50
|
-
textarea,
|
|
51
|
-
select,
|
|
52
|
-
button {
|
|
53
|
-
font: inherit;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
html {
|
|
57
|
-
height: 100%;
|
|
58
|
-
|
|
59
|
-
scrollbar-gutter: stable;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
html,
|
|
63
|
-
:has(:target) {
|
|
64
|
-
scroll-behavior: smooth;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
body {
|
|
68
|
-
min-height: 100%;
|
|
69
|
-
|
|
70
|
-
line-height: 1.5;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
a:where([class]) {
|
|
74
|
-
display: inline-flex;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
button,
|
|
78
|
-
label {
|
|
79
|
-
cursor: pointer;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
[stroke] {
|
|
83
|
-
stroke: currentColor;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
svg * {
|
|
87
|
-
transition-property: fill, stroke;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
@media (prefers-reduced-motion: reduce) {
|
|
91
|
-
*,
|
|
92
|
-
::before,
|
|
93
|
-
::after {
|
|
94
|
-
animation-duration: 0.01ms !important;
|
|
95
|
-
animation-iteration-count: 1 !important;
|
|
96
|
-
scroll-behavior: auto !important;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
@use 'sass:map';
|
|
2
|
-
@use './colors' as *;
|
|
3
|
-
|
|
4
|
-
$theme-map: null;
|
|
5
|
-
|
|
6
|
-
@mixin themify-modules($themes) {
|
|
7
|
-
@each $theme, $map in $themes {
|
|
8
|
-
:global(.theme-#{$theme}) & {
|
|
9
|
-
$theme-map: () !global;
|
|
10
|
-
|
|
11
|
-
@each $key, $value in $map {
|
|
12
|
-
$theme-map: map.merge(
|
|
13
|
-
$theme-map,
|
|
14
|
-
(
|
|
15
|
-
$key: $value,
|
|
16
|
-
)
|
|
17
|
-
) !global;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@content;
|
|
21
|
-
|
|
22
|
-
$theme-map: null !global;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@mixin themify($themes) {
|
|
28
|
-
@each $theme, $map in $themes {
|
|
29
|
-
.theme-#{$theme} & {
|
|
30
|
-
$theme-map: () !global;
|
|
31
|
-
|
|
32
|
-
@each $key, $submap in $map {
|
|
33
|
-
$value: map.get(map.get($themes, $theme), $key);
|
|
34
|
-
$theme-map: map.merge(
|
|
35
|
-
$theme-map,
|
|
36
|
-
(
|
|
37
|
-
$key: $value,
|
|
38
|
-
)
|
|
39
|
-
) !global;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@content;
|
|
43
|
-
|
|
44
|
-
$theme-map: null !global;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@function themed($key) {
|
|
50
|
-
@return map.get($theme-map, $key);
|
|
51
|
-
}
|
package/src/styles/main.scss
DELETED
package/src/types/types.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
declare module '*.module.css' {
|
|
2
|
-
const classes: { [key: string]: string };
|
|
3
|
-
export default classes;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
declare module '*.module.scss' {
|
|
7
|
-
const classes: { [key: string]: string };
|
|
8
|
-
export default classes;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
declare module '*.svg?react' {
|
|
12
|
-
import React from 'react';
|
|
13
|
-
const SVG: React.FC<React.SVGProps<SVGSVGElement>>;
|
|
14
|
-
export default SVG;
|
|
15
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getDaysInMonth,
|
|
3
|
-
getFirstDayOfMonth,
|
|
4
|
-
getLastDayOfMonth,
|
|
5
|
-
getMonthDays,
|
|
6
|
-
getWeekDayIndex,
|
|
7
|
-
getWeekDays,
|
|
8
|
-
getWeeksFromDays,
|
|
9
|
-
} from './calendar';
|
|
10
|
-
|
|
11
|
-
describe('getFirstDayOfMonth:', () => {
|
|
12
|
-
it('returns the first day of month', () => {
|
|
13
|
-
const result = getFirstDayOfMonth(new Date(2026, 8, 18));
|
|
14
|
-
expect(result.getMonth()).toBe(8);
|
|
15
|
-
expect(result.getDate()).toBe(1);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('getLastDayOfMonth:', () => {
|
|
20
|
-
it('returns the last day of month', () => {
|
|
21
|
-
const result = getLastDayOfMonth(new Date(2026, 0, 10));
|
|
22
|
-
expect(result.getDate()).toBe(31);
|
|
23
|
-
expect(result.getMonth()).toBe(0);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('handles February in a leap year', () => {
|
|
27
|
-
const result = getLastDayOfMonth(new Date(2024, 1, 1));
|
|
28
|
-
expect(result.getDate()).toBe(29);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('handles February in a non-leap year', () => {
|
|
32
|
-
const result = getLastDayOfMonth(new Date(2025, 1, 1));
|
|
33
|
-
expect(result.getDate()).toBe(28);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('getDaysInMonth:', () => {
|
|
38
|
-
it('returns count of days in the month', () => {
|
|
39
|
-
expect(getDaysInMonth(new Date(2026, 8, 1))).toBe(30);
|
|
40
|
-
expect(getDaysInMonth(new Date(2026, 7, 1))).toBe(31);
|
|
41
|
-
expect(getDaysInMonth(new Date(2026, 6, 1))).toBe(31);
|
|
42
|
-
expect(getDaysInMonth(new Date(2023, 5, 1))).toBe(30);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('getWeekDayIndex:', () => {
|
|
47
|
-
it('return 0 for Sunday if the first of week is 0', () => {
|
|
48
|
-
const sunday = new Date(2026, 8, 6);
|
|
49
|
-
expect(getWeekDayIndex(sunday, 0)).toBe(0);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('return 1 for Monday if the first of week is 0', () => {
|
|
53
|
-
const monday = new Date(2026, 8, 7);
|
|
54
|
-
expect(getWeekDayIndex(monday, 0)).toBe(1);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('return 6 for Sunday if the first of week is 1', () => {
|
|
58
|
-
const sunday = new Date(2026, 8, 6);
|
|
59
|
-
expect(getWeekDayIndex(sunday, 1)).toBe(6);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('return 0 for Monday if the first of week is 1', () => {
|
|
63
|
-
const monday = new Date(2026, 8, 7);
|
|
64
|
-
expect(getWeekDayIndex(monday, 1)).toBe(0);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('uses firstDayOfWeek = 1 by default', () => {
|
|
68
|
-
const monday = new Date(2026, 8, 7);
|
|
69
|
-
expect(getWeekDayIndex(monday)).toBe(0);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('getMonthDays:', () => {
|
|
74
|
-
it('returns a grid with a step of 7', () => {
|
|
75
|
-
const result = getMonthDays(new Date(2026, 8, 1));
|
|
76
|
-
expect(result.length % 7).toBe(0);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('includes all month days', () => {
|
|
80
|
-
const result = getMonthDays(new Date(2026, 8, 1));
|
|
81
|
-
const daysInCurrentMonth = result.filter(
|
|
82
|
-
(day) => day.getMonth() === 8 && day.getFullYear() === 2026
|
|
83
|
-
);
|
|
84
|
-
expect(daysInCurrentMonth.length).toBe(30);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('the first day of a grid is Monday if firstDayOfWeek = 1', () => {
|
|
88
|
-
const result = getMonthDays(new Date(2026, 8, 1), 1);
|
|
89
|
-
expect(result[0].getDay()).toBe(1);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('the first day of a grid is Sunday if firstDayOfWeek = 0', () => {
|
|
93
|
-
const result = getMonthDays(new Date(2026, 8, 1), 0);
|
|
94
|
-
expect(result[0].getDay()).toBe(0);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('correctly adds days of the previous and the next monthes', () => {
|
|
98
|
-
const result = getMonthDays(new Date(2026, 7, 1), 1);
|
|
99
|
-
expect(result[0].getMonth()).toBe(6);
|
|
100
|
-
expect(result[4].getMonth()).toBe(6);
|
|
101
|
-
expect(result[result.length - 1].getMonth()).toBe(8);
|
|
102
|
-
expect(result[result.length - 6].getMonth()).toBe(8);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
describe('getWeeksFromDays:', () => {
|
|
107
|
-
const mockDays: Date[] = Array.from(
|
|
108
|
-
{ length: 30 },
|
|
109
|
-
(_, i) => new Date(2026, 8, i + 1)
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
it('splits the array of days into weeks of 7', () => {
|
|
113
|
-
const weeks = getWeeksFromDays(mockDays, 7);
|
|
114
|
-
expect(weeks.length).toBe(5);
|
|
115
|
-
expect(weeks[0].length).toBe(7);
|
|
116
|
-
expect(weeks[3].length).toBe(7);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('splits the array of days into weeks of 5', () => {
|
|
120
|
-
const weeks = getWeeksFromDays(mockDays, 5);
|
|
121
|
-
weeks.forEach((week) => expect(week.length).toBe(5));
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('handles correctly the last incomplete week', () => {
|
|
125
|
-
const weeks = getWeeksFromDays(mockDays);
|
|
126
|
-
expect(weeks[0].length).toBe(7);
|
|
127
|
-
expect(weeks[4].length).toBe(2);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('returns emply array for an empty entry array', () => {
|
|
131
|
-
expect(getWeeksFromDays([], 7)).toEqual([]);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe('getWeekDays:', () => {
|
|
136
|
-
it('return 7 days', () => {
|
|
137
|
-
const result = getWeekDays(new Date(2026, 8, 16));
|
|
138
|
-
expect(result.length).toBe(7);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('starts from Monday if firstDayOfWeek = 1', () => {
|
|
142
|
-
const wednesday = new Date(2026, 8, 16);
|
|
143
|
-
const result = getWeekDays(wednesday, 1);
|
|
144
|
-
expect(result[0].getDay()).toBe(1);
|
|
145
|
-
expect(result[0].getDate()).toBe(14);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('starts from Sunday if firstDayOfWeek = 0', () => {
|
|
149
|
-
const wednesday = new Date(2026, 8, 16);
|
|
150
|
-
const result = getWeekDays(wednesday, 0);
|
|
151
|
-
expect(result[0].getDay()).toBe(0);
|
|
152
|
-
expect(result[0].getDate()).toBe(13);
|
|
153
|
-
});
|
|
154
|
-
});
|
package/src/utils/calendar.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
export const getFirstDayOfMonth = (date: Date): Date => {
|
|
2
|
-
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
export const getLastDayOfMonth = (date: Date): Date => {
|
|
6
|
-
return new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const getDaysInMonth = (date: Date): number => {
|
|
10
|
-
return getLastDayOfMonth(date).getDate();
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const getWeekDayIndex = (
|
|
14
|
-
date: Date,
|
|
15
|
-
firstDayOfWeek: 0 | 1 = 1
|
|
16
|
-
): number => {
|
|
17
|
-
let index = date.getDay();
|
|
18
|
-
if (firstDayOfWeek === 1) {
|
|
19
|
-
index = index === 0 ? 6 : index - 1;
|
|
20
|
-
}
|
|
21
|
-
return index;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const getMonthDays = (date: Date, firstDayOfWeek: 0 | 1 = 1): Date[] => {
|
|
25
|
-
const year = date.getFullYear();
|
|
26
|
-
const month = date.getMonth();
|
|
27
|
-
|
|
28
|
-
const firstDay = getFirstDayOfMonth(date);
|
|
29
|
-
const daysInMonth = getDaysInMonth(date);
|
|
30
|
-
const firstDayIndex = getWeekDayIndex(firstDay, firstDayOfWeek);
|
|
31
|
-
|
|
32
|
-
const totalDays = Math.ceil((firstDayIndex + daysInMonth) / 7) * 7;
|
|
33
|
-
const days: Date[] = [];
|
|
34
|
-
|
|
35
|
-
for (let i = 0; i < firstDayIndex; i++) {
|
|
36
|
-
days.push(new Date(year, month, 1 - firstDayIndex + i));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
for (let i = 1; i <= daysInMonth; i++) {
|
|
40
|
-
days.push(new Date(year, month, i));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const remaining = totalDays - days.length;
|
|
44
|
-
for (let i = 1; i <= remaining; i++) {
|
|
45
|
-
days.push(new Date(year, month + 1, i));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return days;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const getWeeksFromDays = (
|
|
52
|
-
days: Date[],
|
|
53
|
-
weekLength: 5 | 7 = 7
|
|
54
|
-
): Date[][] => {
|
|
55
|
-
const weeks: Date[][] = [];
|
|
56
|
-
for (let i = 0; i < days.length; i += weekLength) {
|
|
57
|
-
weeks.push(days.slice(i, i + weekLength));
|
|
58
|
-
}
|
|
59
|
-
return weeks;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export const getWeekDays = (date: Date, firstDayOfWeek: 0 | 1 = 1): Date[] => {
|
|
63
|
-
const year = date.getFullYear();
|
|
64
|
-
const month = date.getMonth();
|
|
65
|
-
const day = date.getDate();
|
|
66
|
-
|
|
67
|
-
const currentDayOfWeek = date.getDay();
|
|
68
|
-
|
|
69
|
-
const offset =
|
|
70
|
-
firstDayOfWeek === 1 ? (currentDayOfWeek + 6) % 7 : currentDayOfWeek;
|
|
71
|
-
|
|
72
|
-
const startDate = new Date(year, month, day - offset);
|
|
73
|
-
|
|
74
|
-
const weekDays: Date[] = [];
|
|
75
|
-
for (let i = 0; i < 7; i++) {
|
|
76
|
-
const newDate = new Date(startDate);
|
|
77
|
-
newDate.setDate(startDate.getDate() + i);
|
|
78
|
-
weekDays.push(newDate);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return weekDays;
|
|
82
|
-
};
|
package/src/utils/controlDate.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isCurrentMonth,
|
|
3
|
-
isDisabled,
|
|
4
|
-
isInRange,
|
|
5
|
-
isRangeEnd,
|
|
6
|
-
isRangeStart,
|
|
7
|
-
isSameDay,
|
|
8
|
-
isSelected,
|
|
9
|
-
isToday,
|
|
10
|
-
isWeekend,
|
|
11
|
-
} from './dateChecks';
|
|
12
|
-
|
|
13
|
-
describe('dateChecks:', () => {
|
|
14
|
-
describe('isSameDay:', () => {
|
|
15
|
-
it('returns true for same day', () => {
|
|
16
|
-
const date1 = new Date(2026, 7, 25);
|
|
17
|
-
const date2 = new Date(2026, 7, 25);
|
|
18
|
-
expect(isSameDay(date1, date2)).toBe(true);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('returns false for different days', () => {
|
|
22
|
-
const date1 = new Date(2026, 7, 25);
|
|
23
|
-
const date2 = new Date(2026, 7, 26);
|
|
24
|
-
expect(isSameDay(date1, date2)).toBe(false);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('returns false for different months', () => {
|
|
28
|
-
const date1 = new Date(2026, 7, 25);
|
|
29
|
-
const date2 = new Date(2026, 8, 25);
|
|
30
|
-
expect(isSameDay(date1, date2)).toBe(false);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('returns false for different years', () => {
|
|
34
|
-
const date1 = new Date(2026, 7, 25);
|
|
35
|
-
const date2 = new Date(2027, 7, 25);
|
|
36
|
-
expect(isSameDay(date1, date2)).toBe(false);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('isCurrentMonth:', () => {
|
|
41
|
-
it('returns true for same month and year', () => {
|
|
42
|
-
const date = new Date(2026, 7, 25);
|
|
43
|
-
const monthDate = new Date(2026, 7, 1);
|
|
44
|
-
expect(isCurrentMonth(date, monthDate)).toBe(true);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('returns false for different month', () => {
|
|
48
|
-
const date = new Date(2026, 9, 1);
|
|
49
|
-
const monthDate = new Date(2026, 8, 1);
|
|
50
|
-
expect(isCurrentMonth(date, monthDate)).toBe(false);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('returns false for different year', () => {
|
|
54
|
-
const date = new Date(2026, 9, 25);
|
|
55
|
-
const monthDate = new Date(2027, 9, 1);
|
|
56
|
-
expect(isCurrentMonth(date, monthDate)).toBe(false);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe('isWeekend:', () => {
|
|
61
|
-
it('returns true for Sunday', () => {
|
|
62
|
-
const sunday = new Date(2026, 8, 6);
|
|
63
|
-
expect(isWeekend(sunday)).toBe(true);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('returns true for Saturday', () => {
|
|
67
|
-
const saturday = new Date(2026, 8, 5);
|
|
68
|
-
expect(isWeekend(saturday)).toBe(true);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('returns false for Wednesday', () => {
|
|
72
|
-
const wednesday = new Date(2026, 8, 9);
|
|
73
|
-
expect(isWeekend(wednesday)).toBe(false);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
describe('isToday', () => {
|
|
78
|
-
it('returns true for today', () => {
|
|
79
|
-
const today = new Date();
|
|
80
|
-
expect(isToday(today)).toBe(true);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('returns false for random date', () => {
|
|
84
|
-
const random = new Date(2026, 2, 9);
|
|
85
|
-
expect(isToday(random)).toBe(false);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('isSelected:', () => {
|
|
90
|
-
it('returns true when date is selected', () => {
|
|
91
|
-
const date = new Date(2026, 7, 25);
|
|
92
|
-
const selectedDate = new Date(2026, 7, 25);
|
|
93
|
-
expect(isSelected(date, selectedDate)).toBe(true);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('returns false when date is not selected', () => {
|
|
97
|
-
const date = new Date(2026, 7, 25);
|
|
98
|
-
const selectedDate = new Date(2026, 7, 26);
|
|
99
|
-
expect(isSelected(date, selectedDate)).toBe(false);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('returns false when selectedDate is undefined', () => {
|
|
103
|
-
const date = new Date(2026, 7, 25);
|
|
104
|
-
expect(isSelected(date, undefined)).toBe(false);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe('isDisabled', () => {
|
|
109
|
-
it('returns true when date is before minDate', () => {
|
|
110
|
-
const date = new Date(2026, 7, 25);
|
|
111
|
-
const minDate = new Date(2026, 7, 26);
|
|
112
|
-
expect(isDisabled(date, minDate)).toBe(true);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('returns true when date is after maxDate', () => {
|
|
116
|
-
const date = new Date(2026, 7, 25);
|
|
117
|
-
const maxDate = new Date(2026, 7, 24);
|
|
118
|
-
expect(isDisabled(date, null, maxDate)).toBe(true);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('returns false when date is within range', () => {
|
|
122
|
-
const date = new Date(2026, 7, 25);
|
|
123
|
-
const minDate = new Date(2026, 7, 20);
|
|
124
|
-
const maxDate = new Date(2026, 7, 30);
|
|
125
|
-
expect(isDisabled(date, minDate, maxDate)).toBe(false);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('returns false when minDate and maxDate are null', () => {
|
|
129
|
-
const date = new Date(2026, 7, 25);
|
|
130
|
-
expect(isDisabled(date, null, null)).toBe(false);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('returns false when date equals minDate', () => {
|
|
134
|
-
const date = new Date(2026, 7, 25);
|
|
135
|
-
const minDate = new Date(2026, 7, 25);
|
|
136
|
-
expect(isDisabled(date, minDate, null)).toBe(false);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('returns false when date equals maxDate', () => {
|
|
140
|
-
const date = new Date(2026, 7, 25);
|
|
141
|
-
const maxDate = new Date(2026, 7, 25);
|
|
142
|
-
expect(isDisabled(date, null, maxDate)).toBe(false);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
describe('isInRange:', () => {
|
|
147
|
-
it('returns true when date is between start and end', () => {
|
|
148
|
-
const date = new Date(2026, 7, 25);
|
|
149
|
-
const start = new Date(2026, 7, 20);
|
|
150
|
-
const end = new Date(2026, 7, 30);
|
|
151
|
-
expect(isInRange(date, start, end)).toBe(true);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('returns false when date equals start', () => {
|
|
155
|
-
const date = new Date(2026, 7, 20);
|
|
156
|
-
const start = new Date(2026, 7, 20);
|
|
157
|
-
const end = new Date(2026, 7, 30);
|
|
158
|
-
expect(isInRange(date, start, end)).toBe(false);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('returns false when date equals end', () => {
|
|
162
|
-
const date = new Date(2026, 7, 30);
|
|
163
|
-
const start = new Date(2026, 7, 20);
|
|
164
|
-
const end = new Date(2026, 7, 30);
|
|
165
|
-
expect(isInRange(date, start, end)).toBe(false);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('returns false when start is undefined', () => {
|
|
169
|
-
const date = new Date(2026, 7, 25);
|
|
170
|
-
expect(isInRange(date, undefined, new Date(2026, 7, 30))).toBe(false);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('returns false when end is undefined', () => {
|
|
174
|
-
const date = new Date(2026, 7, 25);
|
|
175
|
-
expect(isInRange(date, new Date(2026, 7, 20), undefined)).toBe(false);
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
describe('isRangeStart', () => {
|
|
180
|
-
it('returns true when date equals start', () => {
|
|
181
|
-
const date = new Date(2026, 7, 25);
|
|
182
|
-
const start = new Date(2026, 7, 25);
|
|
183
|
-
expect(isRangeStart(date, start)).toBe(true);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('returns false when date does not equal start', () => {
|
|
187
|
-
const date = new Date(2026, 7, 25);
|
|
188
|
-
const start = new Date(2026, 7, 26);
|
|
189
|
-
expect(isRangeStart(date, start)).toBe(false);
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it('returns false when start is undefined', () => {
|
|
193
|
-
const date = new Date(2026, 7, 25);
|
|
194
|
-
expect(isRangeStart(date, undefined)).toBe(false);
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
describe('isRangeEnd:', () => {
|
|
199
|
-
it('returns true when date equals end', () => {
|
|
200
|
-
const date = new Date(2026, 7, 25);
|
|
201
|
-
const end = new Date(2026, 7, 25);
|
|
202
|
-
expect(isRangeEnd(date, end)).toBe(true);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('returns false when date does not equal end', () => {
|
|
206
|
-
const date = new Date(2026, 7, 25);
|
|
207
|
-
const end = new Date(2026, 7, 26);
|
|
208
|
-
expect(isRangeEnd(date, end)).toBe(false);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('returns false when end is undefined', () => {
|
|
212
|
-
const date = new Date(2026, 7, 25);
|
|
213
|
-
expect(isRangeEnd(date, undefined)).toBe(false);
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
});
|