@daryasidorovich/modsen-datepicker 1.0.0 → 1.0.1

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.
Files changed (128) hide show
  1. package/.prettierrc +6 -6
  2. package/.storybook/main.js +93 -93
  3. package/.storybook/main.ts +16 -0
  4. package/.storybook/preview.js +26 -26
  5. package/.storybook/preview.tsx +18 -18
  6. package/README.md +5 -5
  7. package/commitlint.config.js +23 -23
  8. package/package.json +1 -1
  9. package/rollup.config.js +65 -65
  10. package/src/components/BaseCalendar/BaseCalendar.stories.tsx +77 -77
  11. package/src/components/BaseCalendar/index.tsx +63 -63
  12. package/src/components/BaseCalendar/styles.module.scss +15 -15
  13. package/src/components/Button/Button.stories.tsx +16 -0
  14. package/src/components/Button/Button.tsx +14 -0
  15. package/src/components/Button/index.ts +1 -0
  16. package/src/components/Button/styles.module.scss +3 -0
  17. package/src/components/CalendarGrid/CalendarGrid.stories.tsx +136 -136
  18. package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/index.tsx +27 -27
  19. package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/styles.module.scss +9 -9
  20. package/src/components/CalendarGrid/CalendarGridWithTasks/index.tsx +51 -51
  21. package/src/components/CalendarGrid/CalendarGridWithoutTasks/index.tsx +36 -36
  22. package/src/components/CalendarGrid/CalendarGridWithoutTasks/styles.module.scss +11 -11
  23. package/src/components/CalendarGrid/index.tsx +19 -19
  24. package/src/components/CalendarGrid/types.ts +26 -26
  25. package/src/components/Clear/Clear.stories.tsx +16 -16
  26. package/src/components/Clear/index.tsx +12 -12
  27. package/src/components/Clear/styles.module.scss +34 -34
  28. package/src/components/DatePicker/DatePicker.stories.tsx +127 -127
  29. package/src/components/DatePicker/index.tsx +72 -72
  30. package/src/components/DatePicker/styles.module.scss +10 -10
  31. package/src/components/Day/Day.stories.tsx +75 -75
  32. package/src/components/Day/index.tsx +95 -95
  33. package/src/components/Day/styles.module.scss +97 -97
  34. package/src/components/Input/Input.stories.tsx +37 -37
  35. package/src/components/Input/index.tsx +64 -64
  36. package/src/components/Input/styles.module.scss +79 -79
  37. package/src/components/Modal/CrudModal/index.tsx +43 -43
  38. package/src/components/Modal/CrudModal/styles.module.scss +44 -44
  39. package/src/components/Modal/index.tsx +66 -66
  40. package/src/components/Modal/styles.module.scss +40 -40
  41. package/src/components/Modal/types.ts +13 -13
  42. package/src/components/Month/Month.stories.tsx +19 -19
  43. package/src/components/Month/index.tsx +31 -31
  44. package/src/components/Month/styles.module.scss +30 -30
  45. package/src/components/RangePicker/RangePicker.stories.tsx +134 -134
  46. package/src/components/RangePicker/index.tsx +144 -144
  47. package/src/components/RangePicker/styles.module.scss +19 -19
  48. package/src/components/TasksManager/AddModal/index.tsx +62 -62
  49. package/src/components/TasksManager/DeleteModal/index.tsx +22 -22
  50. package/src/components/TasksManager/EditModal/index.tsx +96 -96
  51. package/src/components/TasksManager/index.tsx +112 -112
  52. package/src/components/TasksManager/styles.module.scss +62 -62
  53. package/src/components/Week/Week.stories.tsx +49 -49
  54. package/src/components/Week/index.tsx +68 -68
  55. package/src/components/Week/styles.module.scss +7 -7
  56. package/src/components/WeekDay/WeekDay.stories.tsx +38 -38
  57. package/src/components/WeekDay/index.tsx +35 -35
  58. package/src/components/WeekDay/styles.module.scss +19 -19
  59. package/src/constants/dateMask.ts +23 -23
  60. package/src/constants/firstDayOfWeek.ts +7 -7
  61. package/src/constants/holidays.ts +32 -32
  62. package/src/constants/modes.ts +6 -6
  63. package/src/constants/monthsNames.ts +14 -14
  64. package/src/constants/weekdaysNames.ts +1 -1
  65. package/src/hooks/useCalendar.ts +62 -62
  66. package/src/hooks/useLockBodyScroll.ts +19 -19
  67. package/src/hooks/useModal.ts +45 -45
  68. package/src/hooks/useTooltip.ts +41 -41
  69. package/src/hooks/useValidate.ts +80 -80
  70. package/src/index.ts +15 -15
  71. package/src/services/calendarService.ts +62 -62
  72. package/src/services/decorators/withHolidays.ts +12 -12
  73. package/src/services/decorators/withMinMax.test.ts +77 -77
  74. package/src/services/decorators/withMinMax.ts +19 -19
  75. package/src/services/holidayService.ts +56 -56
  76. package/src/store/localStorage.ts +33 -33
  77. package/src/store/tasksStore.tsx +146 -146
  78. package/src/store/types.ts +22 -22
  79. package/src/stories/Button.stories.ts +54 -0
  80. package/src/stories/Button.tsx +37 -0
  81. package/src/stories/Configure.mdx +388 -0
  82. package/src/stories/Header.stories.ts +34 -0
  83. package/src/stories/Header.tsx +56 -0
  84. package/src/stories/Page.stories.ts +33 -0
  85. package/src/stories/Page.tsx +73 -0
  86. package/src/stories/assets/accessibility.png +0 -0
  87. package/src/stories/assets/accessibility.svg +1 -0
  88. package/src/stories/assets/addon-library.png +0 -0
  89. package/src/stories/assets/assets.png +0 -0
  90. package/src/stories/assets/avif-test-image.avif +0 -0
  91. package/src/stories/assets/context.png +0 -0
  92. package/src/stories/assets/discord.svg +1 -0
  93. package/src/stories/assets/docs.png +0 -0
  94. package/src/stories/assets/figma-plugin.png +0 -0
  95. package/src/stories/assets/github.svg +1 -0
  96. package/src/stories/assets/share.png +0 -0
  97. package/src/stories/assets/styling.png +0 -0
  98. package/src/stories/assets/testing.png +0 -0
  99. package/src/stories/assets/theming.png +0 -0
  100. package/src/stories/assets/tutorials.svg +1 -0
  101. package/src/stories/assets/youtube.svg +1 -0
  102. package/src/stories/button.css +30 -0
  103. package/src/stories/header.css +32 -0
  104. package/src/stories/page.css +68 -0
  105. package/src/styles/_border.scss +9 -9
  106. package/src/styles/_colors.scss +53 -53
  107. package/src/styles/_gap.scss +4 -4
  108. package/src/styles/_globals.scss +61 -61
  109. package/src/styles/_grid.scss +9 -9
  110. package/src/styles/_mixins.scss +6 -6
  111. package/src/styles/_reset.scss +98 -98
  112. package/src/styles/_theme-mixins.scss +51 -51
  113. package/src/styles/_typography.scss +10 -10
  114. package/src/styles/_variables.scss +8 -8
  115. package/src/styles/main.scss +3 -3
  116. package/src/types/types.d.ts +15 -15
  117. package/src/utils/calendar.test.ts +154 -154
  118. package/src/utils/calendar.ts +82 -82
  119. package/src/utils/controlDate.ts +3 -3
  120. package/src/utils/dateChecks.test.ts +216 -216
  121. package/src/utils/dateChecks.ts +75 -75
  122. package/src/utils/formatDate.ts +27 -27
  123. package/src/utils/schema.test.ts +40 -40
  124. package/src/utils/schema.ts +8 -8
  125. package/src/utils/weekdayOrder.test.ts +11 -11
  126. package/src/utils/weekdayOrder.ts +7 -7
  127. package/vitest.config.ts +38 -38
  128. package/vitest.shims.d.ts +1 -1
@@ -1,216 +1,216 @@
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
- });
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
+ });
@@ -1,75 +1,75 @@
1
- import { formatDateForInput } from './formatDate';
2
-
3
- export const isSameDay = (date1: Date, date2: Date) => {
4
- return (
5
- date1.getFullYear() === date2.getFullYear() &&
6
- date1.getMonth() === date2.getMonth() &&
7
- date1.getDate() === date2.getDate()
8
- );
9
- };
10
-
11
- export const isCurrentMonth = (date: Date, monthDate: Date) => {
12
- return (
13
- date.getMonth() === monthDate.getMonth() &&
14
- date.getFullYear() === monthDate.getFullYear()
15
- );
16
- };
17
-
18
- export const isWeekend = (date: Date) => {
19
- return date.getDay() === 0 || date.getDay() === 6;
20
- };
21
-
22
- export const isToday = (date: Date) => {
23
- return isSameDay(date, new Date());
24
- };
25
-
26
- export const isSelected = (date: Date, selectedDate?: Date) => {
27
- if (!selectedDate) return false;
28
- return isSameDay(date, selectedDate);
29
- };
30
-
31
- export const isDisabled = (
32
- date: Date,
33
- minDate?: Date | null,
34
- maxDate?: Date | null
35
- ): boolean => {
36
- if (minDate && date < minDate) return true;
37
- if (maxDate && date > maxDate) return true;
38
- return false;
39
- };
40
-
41
- export const isInRange = (date: Date, start?: Date, end?: Date) => {
42
- if (!start || !end) return false;
43
-
44
- const dateStart = new Date(
45
- start.getFullYear(),
46
- start.getMonth(),
47
- start.getDate()
48
- );
49
- const dateEnd = new Date(end.getFullYear(), end.getMonth(), end.getDate());
50
- const dateToCheck = new Date(
51
- date.getFullYear(),
52
- date.getMonth(),
53
- date.getDate()
54
- );
55
-
56
- return dateToCheck > dateStart && dateToCheck < dateEnd;
57
- };
58
-
59
- export const isRangeStart = (date: Date, start?: Date) => {
60
- if (!start) return false;
61
- return isSameDay(date, start);
62
- };
63
-
64
- export const isRangeEnd = (date: Date, end?: Date) => {
65
- if (!end) return false;
66
- return isSameDay(date, end);
67
- };
68
-
69
- export const getRangeError = (date: Date, startDate: Date): string => {
70
- if (startDate && date < startDate) {
71
- return `Date must be after ${formatDateForInput(startDate)}`;
72
- }
73
-
74
- return '';
75
- };
1
+ import { formatDateForInput } from './formatDate';
2
+
3
+ export const isSameDay = (date1: Date, date2: Date) => {
4
+ return (
5
+ date1.getFullYear() === date2.getFullYear() &&
6
+ date1.getMonth() === date2.getMonth() &&
7
+ date1.getDate() === date2.getDate()
8
+ );
9
+ };
10
+
11
+ export const isCurrentMonth = (date: Date, monthDate: Date) => {
12
+ return (
13
+ date.getMonth() === monthDate.getMonth() &&
14
+ date.getFullYear() === monthDate.getFullYear()
15
+ );
16
+ };
17
+
18
+ export const isWeekend = (date: Date) => {
19
+ return date.getDay() === 0 || date.getDay() === 6;
20
+ };
21
+
22
+ export const isToday = (date: Date) => {
23
+ return isSameDay(date, new Date());
24
+ };
25
+
26
+ export const isSelected = (date: Date, selectedDate?: Date) => {
27
+ if (!selectedDate) return false;
28
+ return isSameDay(date, selectedDate);
29
+ };
30
+
31
+ export const isDisabled = (
32
+ date: Date,
33
+ minDate?: Date | null,
34
+ maxDate?: Date | null
35
+ ): boolean => {
36
+ if (minDate && date < minDate) return true;
37
+ if (maxDate && date > maxDate) return true;
38
+ return false;
39
+ };
40
+
41
+ export const isInRange = (date: Date, start?: Date, end?: Date) => {
42
+ if (!start || !end) return false;
43
+
44
+ const dateStart = new Date(
45
+ start.getFullYear(),
46
+ start.getMonth(),
47
+ start.getDate()
48
+ );
49
+ const dateEnd = new Date(end.getFullYear(), end.getMonth(), end.getDate());
50
+ const dateToCheck = new Date(
51
+ date.getFullYear(),
52
+ date.getMonth(),
53
+ date.getDate()
54
+ );
55
+
56
+ return dateToCheck > dateStart && dateToCheck < dateEnd;
57
+ };
58
+
59
+ export const isRangeStart = (date: Date, start?: Date) => {
60
+ if (!start) return false;
61
+ return isSameDay(date, start);
62
+ };
63
+
64
+ export const isRangeEnd = (date: Date, end?: Date) => {
65
+ if (!end) return false;
66
+ return isSameDay(date, end);
67
+ };
68
+
69
+ export const getRangeError = (date: Date, startDate: Date): string => {
70
+ if (startDate && date < startDate) {
71
+ return `Date must be after ${formatDateForInput(startDate)}`;
72
+ }
73
+
74
+ return '';
75
+ };
@@ -1,27 +1,27 @@
1
- export const formatDate = (date: Date): string => {
2
- const year = date.getFullYear();
3
- const month = String(date.getMonth() + 1).padStart(2, '0');
4
- const day = String(date.getDate()).padStart(2, '0');
5
- return `${year}-${month}-${day}`;
6
- };
7
-
8
- export const formatDateForInput = (date: Date): string => {
9
- const year = date.getFullYear();
10
- const month = String(date.getMonth() + 1).padStart(2, '0');
11
- const day = String(date.getDate()).padStart(2, '0');
12
- return `${day}/${month}/${year}`;
13
- };
14
-
15
- export const parseDate = (value: string): Date | null => {
16
- if (!value.trim()) return null;
17
-
18
- const [day, month, year] = value.split('/').map(Number);
19
- const parsed = new Date(year, month - 1, day);
20
-
21
- const isValid =
22
- parsed.getFullYear() === year &&
23
- parsed.getMonth() === month - 1 &&
24
- parsed.getDate() === day;
25
-
26
- return isValid ? parsed : null;
27
- };
1
+ export const formatDate = (date: Date): string => {
2
+ const year = date.getFullYear();
3
+ const month = String(date.getMonth() + 1).padStart(2, '0');
4
+ const day = String(date.getDate()).padStart(2, '0');
5
+ return `${year}-${month}-${day}`;
6
+ };
7
+
8
+ export const formatDateForInput = (date: Date): string => {
9
+ const year = date.getFullYear();
10
+ const month = String(date.getMonth() + 1).padStart(2, '0');
11
+ const day = String(date.getDate()).padStart(2, '0');
12
+ return `${day}/${month}/${year}`;
13
+ };
14
+
15
+ export const parseDate = (value: string): Date | null => {
16
+ if (!value.trim()) return null;
17
+
18
+ const [day, month, year] = value.split('/').map(Number);
19
+ const parsed = new Date(year, month - 1, day);
20
+
21
+ const isValid =
22
+ parsed.getFullYear() === year &&
23
+ parsed.getMonth() === month - 1 &&
24
+ parsed.getDate() === day;
25
+
26
+ return isValid ? parsed : null;
27
+ };