@sebgroup/green-angular 8.1.0 → 8.1.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.
- package/fesm2022/sebgroup-green-angular-src-v-angular-datepicker.mjs +222 -203
- package/fesm2022/sebgroup-green-angular-src-v-angular-datepicker.mjs.map +1 -1
- package/fesm2022/sebgroup-green-angular-v-angular.mjs +220 -201
- package/fesm2022/sebgroup-green-angular-v-angular.mjs.map +1 -1
- package/package.json +13 -13
- package/src/v-angular/datepicker/components/calendar/calendar.component.d.ts +1 -1
- package/src/v-angular/datepicker/components/date-input/date-input.component.d.ts +1 -1
- package/src/v-angular/datepicker/components/datepicker/datepicker.component.d.ts +1 -1
- package/src/v-angular/datepicker/datepicker.utils.d.ts +7 -0
- package/v-angular/datepicker/components/calendar/calendar.component.d.ts +1 -1
- package/v-angular/datepicker/components/date-input/date-input.component.d.ts +1 -1
- package/v-angular/datepicker/components/datepicker/datepicker.component.d.ts +1 -1
- package/v-angular/datepicker/datepicker.utils.d.ts +7 -0
|
@@ -6,10 +6,10 @@ import * as i2 from '@jsverse/transloco';
|
|
|
6
6
|
import { TRANSLOCO_SCOPE, TranslocoModule } from '@jsverse/transloco';
|
|
7
7
|
import { Subject, fromEvent } from 'rxjs';
|
|
8
8
|
import { takeUntil, debounceTime, map, distinctUntilChanged, startWith } from 'rxjs/operators';
|
|
9
|
-
import * as i4 from '@sebgroup/green-angular/src/v-angular/input-mask';
|
|
10
|
-
import { createMask, NggvInputMaskModule } from '@sebgroup/green-angular/src/v-angular/input-mask';
|
|
11
9
|
import * as i1$1 from '@angular/common';
|
|
12
10
|
import { WeekDay, formatDate, CommonModule } from '@angular/common';
|
|
11
|
+
import * as i4 from '@sebgroup/green-angular/src/v-angular/input-mask';
|
|
12
|
+
import { createMask, NggvInputMaskModule } from '@sebgroup/green-angular/src/v-angular/input-mask';
|
|
13
13
|
import '@sebgroup/green-core/components/icon/icons/chevron-left.js';
|
|
14
14
|
import '@sebgroup/green-core/components/icon/icons/chevron-right.js';
|
|
15
15
|
import * as i3 from '@sebgroup/green-angular/src/lib/shared';
|
|
@@ -17,6 +17,220 @@ import { NggCoreWrapperModule } from '@sebgroup/green-angular/src/lib/shared';
|
|
|
17
17
|
import '@sebgroup/green-core/components/icon/icons/calendar.js';
|
|
18
18
|
import '@sebgroup/green-core/components/icon/icons/triangle-exclamation.js';
|
|
19
19
|
|
|
20
|
+
const weekdays = [
|
|
21
|
+
WeekDay.Monday,
|
|
22
|
+
WeekDay.Tuesday,
|
|
23
|
+
WeekDay.Wednesday,
|
|
24
|
+
WeekDay.Thursday,
|
|
25
|
+
WeekDay.Friday,
|
|
26
|
+
WeekDay.Saturday,
|
|
27
|
+
WeekDay.Sunday,
|
|
28
|
+
];
|
|
29
|
+
const sortWeekDays = (firstDayOfWeek) => {
|
|
30
|
+
const firstDayIndex = weekdays.indexOf(firstDayOfWeek);
|
|
31
|
+
const weekStart = weekdays.slice(firstDayIndex);
|
|
32
|
+
const weekEnd = weekdays.slice(0, firstDayIndex);
|
|
33
|
+
return weekStart.concat(weekEnd);
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Safely converts a value to a Date object, handling timezone issues.
|
|
37
|
+
* If the value is already a Date, returns it as-is.
|
|
38
|
+
* If it's a string in ISO format (YYYY-MM-DD), parses it in local timezone.
|
|
39
|
+
* Otherwise, uses standard Date constructor.
|
|
40
|
+
*/
|
|
41
|
+
const toLocalDate = (value) => {
|
|
42
|
+
// If already a Date object, use it directly to avoid timezone issues
|
|
43
|
+
if (value instanceof Date) {
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
// If string is in ISO format (YYYY-MM-DD), parse in local timezone
|
|
47
|
+
const dateMatch = String(value).match(/^(\d{4})-(\d{2})-(\d{2})/);
|
|
48
|
+
if (dateMatch) {
|
|
49
|
+
const [, year, month, day] = dateMatch;
|
|
50
|
+
return new Date(parseInt(year), parseInt(month) - 1, parseInt(day));
|
|
51
|
+
}
|
|
52
|
+
// Otherwise use standard Date constructor
|
|
53
|
+
return new Date(value);
|
|
54
|
+
};
|
|
55
|
+
/** Sets labels and sort weekday arrays based off of first day of week. */
|
|
56
|
+
const getSortedWeekDays = (firstDayOfWeek, startDate) => {
|
|
57
|
+
if (startDate === undefined)
|
|
58
|
+
startDate = new Date();
|
|
59
|
+
// sort weekdays according to firstDayOfWeek
|
|
60
|
+
const sortedWeekdays = sortWeekDays(firstDayOfWeek);
|
|
61
|
+
// get the date object for the first day of week
|
|
62
|
+
const startDayIndex = sortedWeekdays.indexOf(startDate.getDay());
|
|
63
|
+
const firstOfWeek = new Date(startDate);
|
|
64
|
+
firstOfWeek.setDate(startDate.getDate() - startDayIndex);
|
|
65
|
+
// map each day in array to a date object
|
|
66
|
+
return sortedWeekdays.map((_, offset) => {
|
|
67
|
+
// set appropriate date
|
|
68
|
+
const weekdayDate = new Date(firstOfWeek);
|
|
69
|
+
weekdayDate.setDate(weekdayDate.getDate() + offset);
|
|
70
|
+
// and return value
|
|
71
|
+
return weekdayDate;
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
/** Generate a matrix of dates used to visualize a calendar month. */
|
|
75
|
+
const generateDateMatrix = (month, year, minWeeks = 5, firstDayOfWeek) => {
|
|
76
|
+
// generate a new matrix with 5 or 6 rows (depending on number of days in that month)
|
|
77
|
+
const matrix = new Array(minWeeks);
|
|
78
|
+
matrix.fill([]);
|
|
79
|
+
const date = new Date(year, month, 1);
|
|
80
|
+
const firstDate = firstCalendarDate(date, firstDayOfWeek);
|
|
81
|
+
// for each week in that month
|
|
82
|
+
const dateMatrix = matrix.map((_, weekOffset) => {
|
|
83
|
+
const offset = weekOffset * 7;
|
|
84
|
+
// update the date with the offset for that week
|
|
85
|
+
const firstOfWeek = new Date(firstDate);
|
|
86
|
+
firstOfWeek.setDate(firstDate.getDate() + offset);
|
|
87
|
+
return getSortedWeekDays(firstDayOfWeek, firstOfWeek);
|
|
88
|
+
});
|
|
89
|
+
// check if another row needs to be added (if last dates of month are missing)
|
|
90
|
+
const lastAdded = dateMatrix.slice(-1)[0].slice(-1)[0];
|
|
91
|
+
const lastOfMonth = new Date(lastAdded);
|
|
92
|
+
lastOfMonth.setMonth(month + 1);
|
|
93
|
+
lastOfMonth.setDate(0);
|
|
94
|
+
if (isBefore(lastAdded, lastOfMonth)) {
|
|
95
|
+
// add another week row
|
|
96
|
+
const firstOfWeek = new Date(lastAdded);
|
|
97
|
+
firstOfWeek.setDate(lastAdded.getDate() + 1);
|
|
98
|
+
dateMatrix.push(getSortedWeekDays(firstDayOfWeek, firstOfWeek));
|
|
99
|
+
}
|
|
100
|
+
// return final datematrix
|
|
101
|
+
return dateMatrix;
|
|
102
|
+
};
|
|
103
|
+
/** Returns the first date used in the calendars first button. */
|
|
104
|
+
const firstCalendarDate = (date, firstDayOfWeek) => {
|
|
105
|
+
// sort weekdays according to firstDayOfWeek
|
|
106
|
+
const sortedWeekdays = sortWeekDays(firstDayOfWeek);
|
|
107
|
+
// set date to the first of month
|
|
108
|
+
const firstOfMonth = new Date(date);
|
|
109
|
+
firstOfMonth.setDate(1);
|
|
110
|
+
// get the offset
|
|
111
|
+
const offset = sortedWeekdays.indexOf(firstOfMonth.getDay());
|
|
112
|
+
const firstOfWeek = new Date(firstOfMonth);
|
|
113
|
+
// use offset to set date
|
|
114
|
+
firstOfWeek.setDate(1 - offset);
|
|
115
|
+
return firstOfWeek;
|
|
116
|
+
};
|
|
117
|
+
const getDayOffset = (from, to, firstDayOfWeek, direction) => {
|
|
118
|
+
const sortedWeekdays = sortWeekDays(firstDayOfWeek);
|
|
119
|
+
const fromIndex = sortedWeekdays.indexOf(from);
|
|
120
|
+
const toIndex = sortedWeekdays.indexOf(to);
|
|
121
|
+
const offset = toIndex - fromIndex;
|
|
122
|
+
if (direction === 'forward' && offset < 0)
|
|
123
|
+
return offset + 6;
|
|
124
|
+
if (direction === 'back' && offset > 0)
|
|
125
|
+
return offset - 6;
|
|
126
|
+
return offset;
|
|
127
|
+
};
|
|
128
|
+
/** Returns an array of Dates for each of month. */
|
|
129
|
+
const getMonthArray = () => {
|
|
130
|
+
const firstDayOfYear = new Date();
|
|
131
|
+
firstDayOfYear.setMonth(0);
|
|
132
|
+
firstDayOfYear.setDate(1);
|
|
133
|
+
// create a new array of length 12,
|
|
134
|
+
// and fill it with date objects of 1:st of january
|
|
135
|
+
const monthArray = new Array(12).fill(firstDayOfYear);
|
|
136
|
+
// map through the array,
|
|
137
|
+
// and create a new instance of the date,
|
|
138
|
+
// changing the month based on index (0 - 11)
|
|
139
|
+
return monthArray.map((d, index) => {
|
|
140
|
+
const date = new Date(d);
|
|
141
|
+
date.setMonth(index);
|
|
142
|
+
return date;
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
/** Returns an array of Dates for the current year and the next. */
|
|
146
|
+
const getYearArray = () => {
|
|
147
|
+
const currentYear = new Date();
|
|
148
|
+
currentYear.setMonth(0);
|
|
149
|
+
currentYear.setDate(1);
|
|
150
|
+
const nextYear = new Date(currentYear);
|
|
151
|
+
nextYear.setFullYear(currentYear.getFullYear() + 1);
|
|
152
|
+
return [currentYear, nextYear];
|
|
153
|
+
};
|
|
154
|
+
/** Returns true if the two dates have the same year, month and date values. */
|
|
155
|
+
const match = (a, b) => {
|
|
156
|
+
if (!a || !b)
|
|
157
|
+
return false;
|
|
158
|
+
if (a.getDate() !== b.getDate())
|
|
159
|
+
return false;
|
|
160
|
+
if (a.getMonth() !== b.getMonth())
|
|
161
|
+
return false;
|
|
162
|
+
if (a.getFullYear() !== b.getFullYear())
|
|
163
|
+
return false;
|
|
164
|
+
return true;
|
|
165
|
+
};
|
|
166
|
+
const afterClosingHours = (closingHours) => {
|
|
167
|
+
if (!closingHours)
|
|
168
|
+
return false;
|
|
169
|
+
return Date.now() >= closingHours.getTime();
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Checks if a date is before control date, regardless of time.
|
|
173
|
+
*
|
|
174
|
+
* @param date - comparison date
|
|
175
|
+
* @param controlDate - date to compare against
|
|
176
|
+
* @returns - true if the comparison date is before the control date
|
|
177
|
+
*/
|
|
178
|
+
const isBefore = (date, controlDate) => {
|
|
179
|
+
// if year values are dissimilar
|
|
180
|
+
if (date.getFullYear() !== controlDate.getFullYear()) {
|
|
181
|
+
return date.getFullYear() < controlDate.getFullYear();
|
|
182
|
+
}
|
|
183
|
+
// if month values are dissimilar
|
|
184
|
+
if (date.getMonth() !== controlDate.getMonth()) {
|
|
185
|
+
return date.getMonth() < controlDate.getMonth();
|
|
186
|
+
}
|
|
187
|
+
// if year and month are equal, check the date
|
|
188
|
+
return date.getDate() < controlDate.getDate();
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Checks if a date is after control date, regardless of time.
|
|
192
|
+
*
|
|
193
|
+
* @param date - comparison date
|
|
194
|
+
* @param controlDate - date to compare against
|
|
195
|
+
* @returns - true if the comparison date is before the control date
|
|
196
|
+
*/
|
|
197
|
+
const isAfter = (date, controlDate) => {
|
|
198
|
+
// if year values are dissimilar
|
|
199
|
+
if (date.getFullYear() !== controlDate.getFullYear()) {
|
|
200
|
+
return date.getFullYear() > controlDate.getFullYear();
|
|
201
|
+
}
|
|
202
|
+
// if month values are dissimilar
|
|
203
|
+
if (date.getMonth() !== controlDate.getMonth()) {
|
|
204
|
+
return date.getMonth() > controlDate.getMonth();
|
|
205
|
+
}
|
|
206
|
+
// if year and month are equal, check the date
|
|
207
|
+
return date.getDate() > controlDate.getDate();
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Checks if a value can be used to initiate a new Date object.
|
|
211
|
+
*
|
|
212
|
+
* @param value any value
|
|
213
|
+
* @returns - true if value can be coersed to a Date.
|
|
214
|
+
*/
|
|
215
|
+
const isValid = (value) => {
|
|
216
|
+
// if value is type of string and can be parsed to a Date
|
|
217
|
+
const date = value && typeof value === 'string' && !isNaN(Date.parse(value))
|
|
218
|
+
? new Date(value)
|
|
219
|
+
: null;
|
|
220
|
+
switch (true) {
|
|
221
|
+
// if date or value is a valid date object - return valid
|
|
222
|
+
case typeof value?.getMonth === 'function':
|
|
223
|
+
case typeof date?.getMonth === 'function':
|
|
224
|
+
return true;
|
|
225
|
+
// if date or value is not a valid date object - return invalid
|
|
226
|
+
case value == null:
|
|
227
|
+
case date?.toString() === 'Invalid Date':
|
|
228
|
+
return false;
|
|
229
|
+
default:
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
20
234
|
/**
|
|
21
235
|
* Helper function to generate InputmaskOptions by requested locale.
|
|
22
236
|
* @param locale - requested locale. If not given, it'll use the browsers locale
|
|
@@ -440,7 +654,7 @@ class DateControlValueAccessorComponent {
|
|
|
440
654
|
try {
|
|
441
655
|
// if value is type of string,
|
|
442
656
|
if (value && typeof value === 'string')
|
|
443
|
-
value =
|
|
657
|
+
value = toLocalDate(value);
|
|
444
658
|
switch (true) {
|
|
445
659
|
// remove instances where the value will not correctly be parsed to a date string
|
|
446
660
|
case value == null:
|
|
@@ -448,8 +662,7 @@ class DateControlValueAccessorComponent {
|
|
|
448
662
|
return null;
|
|
449
663
|
// if value-as-date is a valid date object, parse the value to YYYY-MM-DD format
|
|
450
664
|
case typeof value?.getMonth === 'function':
|
|
451
|
-
|
|
452
|
-
return date.toISOString().split('T')[0];
|
|
665
|
+
return new Intl.DateTimeFormat('sv-SE').format(value);
|
|
453
666
|
default:
|
|
454
667
|
return value;
|
|
455
668
|
}
|
|
@@ -710,200 +923,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImpo
|
|
|
710
923
|
type: Output
|
|
711
924
|
}] } });
|
|
712
925
|
|
|
713
|
-
const weekdays = [
|
|
714
|
-
WeekDay.Monday,
|
|
715
|
-
WeekDay.Tuesday,
|
|
716
|
-
WeekDay.Wednesday,
|
|
717
|
-
WeekDay.Thursday,
|
|
718
|
-
WeekDay.Friday,
|
|
719
|
-
WeekDay.Saturday,
|
|
720
|
-
WeekDay.Sunday,
|
|
721
|
-
];
|
|
722
|
-
const sortWeekDays = (firstDayOfWeek) => {
|
|
723
|
-
const firstDayIndex = weekdays.indexOf(firstDayOfWeek);
|
|
724
|
-
const weekStart = weekdays.slice(firstDayIndex);
|
|
725
|
-
const weekEnd = weekdays.slice(0, firstDayIndex);
|
|
726
|
-
return weekStart.concat(weekEnd);
|
|
727
|
-
};
|
|
728
|
-
/** Sets labels and sort weekday arrays based off of first day of week. */
|
|
729
|
-
const getSortedWeekDays = (firstDayOfWeek, startDate) => {
|
|
730
|
-
if (startDate === undefined)
|
|
731
|
-
startDate = new Date();
|
|
732
|
-
// sort weekdays according to firstDayOfWeek
|
|
733
|
-
const sortedWeekdays = sortWeekDays(firstDayOfWeek);
|
|
734
|
-
// get the date object for the first day of week
|
|
735
|
-
const startDayIndex = sortedWeekdays.indexOf(startDate.getDay());
|
|
736
|
-
const firstOfWeek = new Date(startDate);
|
|
737
|
-
firstOfWeek.setDate(startDate.getDate() - startDayIndex);
|
|
738
|
-
// map each day in array to a date object
|
|
739
|
-
return sortedWeekdays.map((_, offset) => {
|
|
740
|
-
// set appropriate date
|
|
741
|
-
const weekdayDate = new Date(firstOfWeek);
|
|
742
|
-
weekdayDate.setDate(weekdayDate.getDate() + offset);
|
|
743
|
-
// and return value
|
|
744
|
-
return weekdayDate;
|
|
745
|
-
});
|
|
746
|
-
};
|
|
747
|
-
/** Generate a matrix of dates used to visualize a calendar month. */
|
|
748
|
-
const generateDateMatrix = (month, year, minWeeks = 5, firstDayOfWeek) => {
|
|
749
|
-
// generate a new matrix with 5 or 6 rows (depending on number of days in that month)
|
|
750
|
-
const matrix = new Array(minWeeks);
|
|
751
|
-
matrix.fill([]);
|
|
752
|
-
const date = new Date(year, month, 1);
|
|
753
|
-
const firstDate = firstCalendarDate(date, firstDayOfWeek);
|
|
754
|
-
// for each week in that month
|
|
755
|
-
const dateMatrix = matrix.map((_, weekOffset) => {
|
|
756
|
-
const offset = weekOffset * 7;
|
|
757
|
-
// update the date with the offset for that week
|
|
758
|
-
const firstOfWeek = new Date(firstDate);
|
|
759
|
-
firstOfWeek.setDate(firstDate.getDate() + offset);
|
|
760
|
-
return getSortedWeekDays(firstDayOfWeek, firstOfWeek);
|
|
761
|
-
});
|
|
762
|
-
// check if another row needs to be added (if last dates of month are missing)
|
|
763
|
-
const lastAdded = dateMatrix.slice(-1)[0].slice(-1)[0];
|
|
764
|
-
const lastOfMonth = new Date(lastAdded);
|
|
765
|
-
lastOfMonth.setMonth(month + 1);
|
|
766
|
-
lastOfMonth.setDate(0);
|
|
767
|
-
if (isBefore(lastAdded, lastOfMonth)) {
|
|
768
|
-
// add another week row
|
|
769
|
-
const firstOfWeek = new Date(lastAdded);
|
|
770
|
-
firstOfWeek.setDate(lastAdded.getDate() + 1);
|
|
771
|
-
dateMatrix.push(getSortedWeekDays(firstDayOfWeek, firstOfWeek));
|
|
772
|
-
}
|
|
773
|
-
// return final datematrix
|
|
774
|
-
return dateMatrix;
|
|
775
|
-
};
|
|
776
|
-
/** Returns the first date used in the calendars first button. */
|
|
777
|
-
const firstCalendarDate = (date, firstDayOfWeek) => {
|
|
778
|
-
// sort weekdays according to firstDayOfWeek
|
|
779
|
-
const sortedWeekdays = sortWeekDays(firstDayOfWeek);
|
|
780
|
-
// set date to the first of month
|
|
781
|
-
const firstOfMonth = new Date(date);
|
|
782
|
-
firstOfMonth.setDate(1);
|
|
783
|
-
// get the offset
|
|
784
|
-
const offset = sortedWeekdays.indexOf(firstOfMonth.getDay());
|
|
785
|
-
const firstOfWeek = new Date(firstOfMonth);
|
|
786
|
-
// use offset to set date
|
|
787
|
-
firstOfWeek.setDate(1 - offset);
|
|
788
|
-
return firstOfWeek;
|
|
789
|
-
};
|
|
790
|
-
const getDayOffset = (from, to, firstDayOfWeek, direction) => {
|
|
791
|
-
const sortedWeekdays = sortWeekDays(firstDayOfWeek);
|
|
792
|
-
const fromIndex = sortedWeekdays.indexOf(from);
|
|
793
|
-
const toIndex = sortedWeekdays.indexOf(to);
|
|
794
|
-
const offset = toIndex - fromIndex;
|
|
795
|
-
if (direction === 'forward' && offset < 0)
|
|
796
|
-
return offset + 6;
|
|
797
|
-
if (direction === 'back' && offset > 0)
|
|
798
|
-
return offset - 6;
|
|
799
|
-
return offset;
|
|
800
|
-
};
|
|
801
|
-
/** Returns an array of Dates for each of month. */
|
|
802
|
-
const getMonthArray = () => {
|
|
803
|
-
const firstDayOfYear = new Date();
|
|
804
|
-
firstDayOfYear.setMonth(0);
|
|
805
|
-
firstDayOfYear.setDate(1);
|
|
806
|
-
// create a new array of length 12,
|
|
807
|
-
// and fill it with date objects of 1:st of january
|
|
808
|
-
const monthArray = new Array(12).fill(firstDayOfYear);
|
|
809
|
-
// map through the array,
|
|
810
|
-
// and create a new instance of the date,
|
|
811
|
-
// changing the month based on index (0 - 11)
|
|
812
|
-
return monthArray.map((d, index) => {
|
|
813
|
-
const date = new Date(d);
|
|
814
|
-
date.setMonth(index);
|
|
815
|
-
return date;
|
|
816
|
-
});
|
|
817
|
-
};
|
|
818
|
-
/** Returns an array of Dates for the current year and the next. */
|
|
819
|
-
const getYearArray = () => {
|
|
820
|
-
const currentYear = new Date();
|
|
821
|
-
currentYear.setMonth(0);
|
|
822
|
-
currentYear.setDate(1);
|
|
823
|
-
const nextYear = new Date(currentYear);
|
|
824
|
-
nextYear.setFullYear(currentYear.getFullYear() + 1);
|
|
825
|
-
return [currentYear, nextYear];
|
|
826
|
-
};
|
|
827
|
-
/** Returns true if the two dates have the same year, month and date values. */
|
|
828
|
-
const match = (a, b) => {
|
|
829
|
-
if (!a || !b)
|
|
830
|
-
return false;
|
|
831
|
-
if (a.getDate() !== b.getDate())
|
|
832
|
-
return false;
|
|
833
|
-
if (a.getMonth() !== b.getMonth())
|
|
834
|
-
return false;
|
|
835
|
-
if (a.getFullYear() !== b.getFullYear())
|
|
836
|
-
return false;
|
|
837
|
-
return true;
|
|
838
|
-
};
|
|
839
|
-
const afterClosingHours = (closingHours) => {
|
|
840
|
-
if (!closingHours)
|
|
841
|
-
return false;
|
|
842
|
-
return Date.now() >= closingHours.getTime();
|
|
843
|
-
};
|
|
844
|
-
/**
|
|
845
|
-
* Checks if a date is before control date, regardless of time.
|
|
846
|
-
*
|
|
847
|
-
* @param date - comparison date
|
|
848
|
-
* @param controlDate - date to compare against
|
|
849
|
-
* @returns - true if the comparison date is before the control date
|
|
850
|
-
*/
|
|
851
|
-
const isBefore = (date, controlDate) => {
|
|
852
|
-
// if year values are dissimilar
|
|
853
|
-
if (date.getFullYear() !== controlDate.getFullYear()) {
|
|
854
|
-
return date.getFullYear() < controlDate.getFullYear();
|
|
855
|
-
}
|
|
856
|
-
// if month values are dissimilar
|
|
857
|
-
if (date.getMonth() !== controlDate.getMonth()) {
|
|
858
|
-
return date.getMonth() < controlDate.getMonth();
|
|
859
|
-
}
|
|
860
|
-
// if year and month are equal, check the date
|
|
861
|
-
return date.getDate() < controlDate.getDate();
|
|
862
|
-
};
|
|
863
|
-
/**
|
|
864
|
-
* Checks if a date is after control date, regardless of time.
|
|
865
|
-
*
|
|
866
|
-
* @param date - comparison date
|
|
867
|
-
* @param controlDate - date to compare against
|
|
868
|
-
* @returns - true if the comparison date is before the control date
|
|
869
|
-
*/
|
|
870
|
-
const isAfter = (date, controlDate) => {
|
|
871
|
-
// if year values are dissimilar
|
|
872
|
-
if (date.getFullYear() !== controlDate.getFullYear()) {
|
|
873
|
-
return date.getFullYear() > controlDate.getFullYear();
|
|
874
|
-
}
|
|
875
|
-
// if month values are dissimilar
|
|
876
|
-
if (date.getMonth() !== controlDate.getMonth()) {
|
|
877
|
-
return date.getMonth() > controlDate.getMonth();
|
|
878
|
-
}
|
|
879
|
-
// if year and month are equal, check the date
|
|
880
|
-
return date.getDate() > controlDate.getDate();
|
|
881
|
-
};
|
|
882
|
-
/**
|
|
883
|
-
* Checks if a value can be used to initiate a new Date object.
|
|
884
|
-
*
|
|
885
|
-
* @param value any value
|
|
886
|
-
* @returns - true if value can be coersed to a Date.
|
|
887
|
-
*/
|
|
888
|
-
const isValid = (value) => {
|
|
889
|
-
// if value is type of string and can be parsed to a Date
|
|
890
|
-
const date = value && typeof value === 'string' && !isNaN(Date.parse(value))
|
|
891
|
-
? new Date(value)
|
|
892
|
-
: null;
|
|
893
|
-
switch (true) {
|
|
894
|
-
// if date or value is a valid date object - return valid
|
|
895
|
-
case typeof value?.getMonth === 'function':
|
|
896
|
-
case typeof date?.getMonth === 'function':
|
|
897
|
-
return true;
|
|
898
|
-
// if date or value is not a valid date object - return invalid
|
|
899
|
-
case value == null:
|
|
900
|
-
case date?.toString() === 'Invalid Date':
|
|
901
|
-
return false;
|
|
902
|
-
default:
|
|
903
|
-
return false;
|
|
904
|
-
}
|
|
905
|
-
};
|
|
906
|
-
|
|
907
926
|
class CalendarDateDirective {
|
|
908
927
|
get nativeElement() {
|
|
909
928
|
return this.elementRef.nativeElement;
|
|
@@ -1061,7 +1080,7 @@ class CalendarComponent {
|
|
|
1061
1080
|
}
|
|
1062
1081
|
ngOnChanges(changes) {
|
|
1063
1082
|
if (changes.selected?.currentValue) {
|
|
1064
|
-
this.selected =
|
|
1083
|
+
this.selected = toLocalDate(changes.selected.currentValue);
|
|
1065
1084
|
}
|
|
1066
1085
|
if (changes.firstDayOfWeek?.currentValue) {
|
|
1067
1086
|
this.lastDayOfWeek = sortWeekDays(changes.firstDayOfWeek.currentValue).pop();
|
|
@@ -1445,7 +1464,7 @@ class DatepickerComponent {
|
|
|
1445
1464
|
!!changes.selected.currentValue &&
|
|
1446
1465
|
!changes.selected.isFirstChange()) {
|
|
1447
1466
|
// set active calendar to match selected date
|
|
1448
|
-
const activeCalendar = new CalendarMonth(
|
|
1467
|
+
const activeCalendar = new CalendarMonth(toLocalDate(changes.selected.currentValue));
|
|
1449
1468
|
this.changeActiveCalendar(activeCalendar);
|
|
1450
1469
|
}
|
|
1451
1470
|
if (changes.disableDates && !changes.disableDates.isFirstChange()) {
|
|
@@ -1495,7 +1514,7 @@ class DatepickerComponent {
|
|
|
1495
1514
|
const withinSameMonth = (a, b) => a.getMonth() === b.getMonth() && a.getFullYear() === b.getFullYear();
|
|
1496
1515
|
// filter out disabled dates for current and adjacent months
|
|
1497
1516
|
return disableDates
|
|
1498
|
-
.map((d) =>
|
|
1517
|
+
.map((d) => toLocalDate(d))
|
|
1499
1518
|
.filter((d) => withinSameMonth(d, previousMonth) ||
|
|
1500
1519
|
withinSameMonth(d, targetMonth) ||
|
|
1501
1520
|
withinSameMonth(d, nextMonth));
|
|
@@ -1860,5 +1879,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImpo
|
|
|
1860
1879
|
* Generated bundle index. Do not edit.
|
|
1861
1880
|
*/
|
|
1862
1881
|
|
|
1863
|
-
export { CalendarComponent, CalendarControlComponent, CalendarDateDirective, CalendarMonth, DateControlValueAccessorComponent, DateInputComponent, DatepickerComponent, IsDisabledPipe, MatchesPipe, NggvDatepickerModule, afterClosingHours, firstCalendarDate, generateDateMatrix, getDayOffset, getFormatDateMask, getLocaleDateMask, getLocaleDateString, getMonthArray, getSortedWeekDays, getYearArray, isAfter, isBefore, isValid, match, setDateFormatCharacters, sortWeekDays };
|
|
1882
|
+
export { CalendarComponent, CalendarControlComponent, CalendarDateDirective, CalendarMonth, DateControlValueAccessorComponent, DateInputComponent, DatepickerComponent, IsDisabledPipe, MatchesPipe, NggvDatepickerModule, afterClosingHours, firstCalendarDate, generateDateMatrix, getDayOffset, getFormatDateMask, getLocaleDateMask, getLocaleDateString, getMonthArray, getSortedWeekDays, getYearArray, isAfter, isBefore, isValid, match, setDateFormatCharacters, sortWeekDays, toLocalDate };
|
|
1864
1883
|
//# sourceMappingURL=sebgroup-green-angular-src-v-angular-datepicker.mjs.map
|