@imihai/angular-datetime-picker 22.0.0 → 22.0.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.
Files changed (113) hide show
  1. package/assets/style/picker.min.css +1 -0
  2. package/fesm2022/imihai-angular-datetime-picker.mjs +5843 -0
  3. package/fesm2022/imihai-angular-datetime-picker.mjs.map +1 -0
  4. package/imihai-angular-datetime-picker-22.0.6.tgz +0 -0
  5. package/package.json +34 -77
  6. package/types/imihai-angular-datetime-picker.d.ts +2193 -0
  7. package/.browserslistrc +0 -9
  8. package/.editorconfig +0 -13
  9. package/.eslintrc.js +0 -208
  10. package/.github/workflows/ci_test.yml +0 -35
  11. package/.prettierrc +0 -2
  12. package/.travis.yml +0 -16
  13. package/angular.json +0 -221
  14. package/e2e/protractor.conf.js +0 -28
  15. package/e2e/src/app.e2e-spec.ts +0 -14
  16. package/e2e/src/app.po.ts +0 -11
  17. package/e2e/tsconfig.e2e.json +0 -13
  18. package/projects/picker/karma.conf.js +0 -62
  19. package/projects/picker/ng-package.json +0 -7
  20. package/projects/picker/package.json +0 -23
  21. package/projects/picker/src/lib/date-time/adapter/date-time-adapter.class.ts +0 -313
  22. package/projects/picker/src/lib/date-time/adapter/date-time-format.class.ts +0 -18
  23. package/projects/picker/src/lib/date-time/adapter/luxon-date-time-adapter.class.ts +0 -307
  24. package/projects/picker/src/lib/date-time/adapter/luxon-date-time-format.class.ts +0 -11
  25. package/projects/picker/src/lib/date-time/adapter/luxon-date-time.module.ts +0 -31
  26. package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time-adapter.class.ts +0 -356
  27. package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time-format.class.ts +0 -14
  28. package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time.module.ts +0 -26
  29. package/projects/picker/src/lib/date-time/calendar-body.component.html +0 -38
  30. package/projects/picker/src/lib/date-time/calendar-body.component.scss +0 -0
  31. package/projects/picker/src/lib/date-time/calendar-body.component.spec.ts +0 -120
  32. package/projects/picker/src/lib/date-time/calendar-body.component.ts +0 -190
  33. package/projects/picker/src/lib/date-time/calendar-month-view.component.html +0 -47
  34. package/projects/picker/src/lib/date-time/calendar-month-view.component.scss +0 -16
  35. package/projects/picker/src/lib/date-time/calendar-month-view.component.spec.ts +0 -394
  36. package/projects/picker/src/lib/date-time/calendar-month-view.component.ts +0 -705
  37. package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.html +0 -44
  38. package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.scss +0 -0
  39. package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.spec.ts +0 -343
  40. package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.ts +0 -465
  41. package/projects/picker/src/lib/date-time/calendar-year-view.component.html +0 -16
  42. package/projects/picker/src/lib/date-time/calendar-year-view.component.scss +0 -0
  43. package/projects/picker/src/lib/date-time/calendar-year-view.component.spec.ts +0 -381
  44. package/projects/picker/src/lib/date-time/calendar-year-view.component.ts +0 -549
  45. package/projects/picker/src/lib/date-time/calendar.component.html +0 -169
  46. package/projects/picker/src/lib/date-time/calendar.component.scss +0 -0
  47. package/projects/picker/src/lib/date-time/calendar.component.spec.ts +0 -592
  48. package/projects/picker/src/lib/date-time/calendar.component.ts +0 -496
  49. package/projects/picker/src/lib/date-time/date-time-inline.component.html +0 -1
  50. package/projects/picker/src/lib/date-time/date-time-inline.component.scss +0 -4
  51. package/projects/picker/src/lib/date-time/date-time-inline.component.ts +0 -365
  52. package/projects/picker/src/lib/date-time/date-time-picker-animation-event.ts +0 -4
  53. package/projects/picker/src/lib/date-time/date-time-picker-container.component.html +0 -126
  54. package/projects/picker/src/lib/date-time/date-time-picker-container.component.scss +0 -0
  55. package/projects/picker/src/lib/date-time/date-time-picker-container.component.ts +0 -631
  56. package/projects/picker/src/lib/date-time/date-time-picker-input.directive.ts +0 -851
  57. package/projects/picker/src/lib/date-time/date-time-picker-intl.service.ts +0 -76
  58. package/projects/picker/src/lib/date-time/date-time-picker-trigger.directive.ts +0 -88
  59. package/projects/picker/src/lib/date-time/date-time-picker.component.html +0 -0
  60. package/projects/picker/src/lib/date-time/date-time-picker.component.scss +0 -0
  61. package/projects/picker/src/lib/date-time/date-time-picker.component.spec.ts +0 -2648
  62. package/projects/picker/src/lib/date-time/date-time-picker.component.ts +0 -731
  63. package/projects/picker/src/lib/date-time/date-time.class.ts +0 -256
  64. package/projects/picker/src/lib/date-time/date-time.module.ts +0 -61
  65. package/projects/picker/src/lib/date-time/numberedFixLen.pipe.ts +0 -28
  66. package/projects/picker/src/lib/date-time/options-provider.ts +0 -44
  67. package/projects/picker/src/lib/date-time/timer-box.component.html +0 -79
  68. package/projects/picker/src/lib/date-time/timer-box.component.scss +0 -0
  69. package/projects/picker/src/lib/date-time/timer-box.component.ts +0 -175
  70. package/projects/picker/src/lib/date-time/timer.component.html +0 -58
  71. package/projects/picker/src/lib/date-time/timer.component.scss +0 -0
  72. package/projects/picker/src/lib/date-time/timer.component.spec.ts +0 -399
  73. package/projects/picker/src/lib/date-time/timer.component.ts +0 -371
  74. package/projects/picker/src/lib/dialog/dialog-config.class.ts +0 -220
  75. package/projects/picker/src/lib/dialog/dialog-container.component.html +0 -1
  76. package/projects/picker/src/lib/dialog/dialog-container.component.scss +0 -0
  77. package/projects/picker/src/lib/dialog/dialog-container.component.ts +0 -231
  78. package/projects/picker/src/lib/dialog/dialog-ref.class.ts +0 -178
  79. package/projects/picker/src/lib/dialog/dialog.module.ts +0 -25
  80. package/projects/picker/src/lib/dialog/dialog.service.ts +0 -353
  81. package/projects/picker/src/lib/utils/array.utils.ts +0 -12
  82. package/projects/picker/src/lib/utils/constants.ts +0 -59
  83. package/projects/picker/src/lib/utils/date.utils.ts +0 -97
  84. package/projects/picker/src/lib/utils/index.ts +0 -5
  85. package/projects/picker/src/lib/utils/object.utils.ts +0 -29
  86. package/projects/picker/src/public_api.ts +0 -56
  87. package/projects/picker/src/sass/picker.scss +0 -743
  88. package/projects/picker/src/test-helpers.ts +0 -125
  89. package/projects/picker/src/test.ts +0 -52
  90. package/projects/picker/tsconfig.lib.json +0 -19
  91. package/projects/picker/tsconfig.lib.prod.json +0 -7
  92. package/projects/picker/tsconfig.spec.json +0 -17
  93. package/projects/picker/tslint.json +0 -8
  94. package/src/app/app.component.html +0 -77
  95. package/src/app/app.component.scss +0 -32
  96. package/src/app/app.component.spec.ts +0 -16
  97. package/src/app/app.component.ts +0 -35
  98. package/src/assets/.gitkeep +0 -0
  99. package/src/environments/environment.prod.ts +0 -3
  100. package/src/environments/environment.ts +0 -16
  101. package/src/favicon.ico +0 -0
  102. package/src/index.html +0 -14
  103. package/src/karma.conf.js +0 -31
  104. package/src/main.ts +0 -16
  105. package/src/polyfills.ts +0 -53
  106. package/src/styles.scss +0 -7
  107. package/src/test.ts +0 -50
  108. package/src/tsconfig.app.json +0 -16
  109. package/src/tsconfig.spec.json +0 -18
  110. package/src/tslint.json +0 -17
  111. package/tsconfig.base.json +0 -31
  112. package/tsconfig.json +0 -30
  113. package/tslint.json +0 -130
@@ -1,705 +0,0 @@
1
- /**
2
- * calendar-month-view.component
3
- */
4
-
5
- import {
6
- AfterContentInit,
7
- ChangeDetectionStrategy,
8
- ChangeDetectorRef,
9
- Component,
10
- EventEmitter,
11
- Inject,
12
- Input,
13
- OnDestroy,
14
- OnInit,
15
- Optional,
16
- Output,
17
- ViewChild
18
- } from '@angular/core';
19
- import {
20
- CalendarCell,
21
- OwlCalendarBodyComponent
22
- } from './calendar-body.component';
23
- import { DateTimeAdapter } from './adapter/date-time-adapter.class';
24
- import {
25
- OWL_DATE_TIME_FORMATS,
26
- OwlDateTimeFormats
27
- } from './adapter/date-time-format.class';
28
- import { Subscription } from 'rxjs';
29
- import { SelectMode } from './date-time.class';
30
- import {
31
- DOWN_ARROW,
32
- END,
33
- ENTER,
34
- HOME,
35
- LEFT_ARROW,
36
- PAGE_DOWN,
37
- PAGE_UP,
38
- RIGHT_ARROW,
39
- UP_ARROW
40
- } from '@angular/cdk/keycodes';
41
- import { getLocaleFirstDayOfWeek } from '@angular/common';
42
-
43
- const DAYS_PER_WEEK = 7;
44
- const WEEKS_PER_VIEW = 6;
45
-
46
- @Component({
47
- selector: 'owl-date-time-month-view',
48
- exportAs: 'owlYearView',
49
- templateUrl: './calendar-month-view.component.html',
50
- styleUrls: ['./calendar-month-view.component.scss'],
51
- standalone: false,
52
- host: {
53
- '[class.owl-dt-calendar-view]': 'owlDTCalendarView'
54
- },
55
- preserveWhitespaces: false,
56
- changeDetection: ChangeDetectionStrategy.OnPush
57
- })
58
- export class OwlMonthViewComponent<T>
59
- implements OnInit, AfterContentInit, OnDestroy {
60
- /**
61
- * Whether to hide dates in other months at the start or end of the current month.
62
- * */
63
- @Input()
64
- hideOtherMonths = false;
65
-
66
- /**
67
- * Whether to show calendar weeks in the calendar
68
- * */
69
- @Input()
70
- showCalendarWeeks = false;
71
-
72
- private isDefaultFirstDayOfWeek = true;
73
-
74
- /**
75
- * Define the first day of a week
76
- * Sunday: 0 - Saturday: 6
77
- * */
78
- private _firstDayOfWeek: number;
79
-
80
- @Input()
81
- get firstDayOfWeek(): number {
82
- return this._firstDayOfWeek;
83
- }
84
-
85
- set firstDayOfWeek(val: number) {
86
- if (val >= 0 && val <= 6 && val !== this._firstDayOfWeek) {
87
- this._firstDayOfWeek = val;
88
- this.isDefaultFirstDayOfWeek = false;
89
-
90
- if (this.initiated) {
91
- this.generateWeekDays();
92
- this.generateCalendar();
93
- this.cdRef.markForCheck();
94
- }
95
- }
96
- }
97
-
98
- /**
99
- * The select mode of the picker;
100
- * */
101
- private _selectMode: SelectMode = 'single';
102
- @Input()
103
- get selectMode(): SelectMode {
104
- return this._selectMode;
105
- }
106
-
107
- set selectMode(val: SelectMode) {
108
- this._selectMode = val;
109
- if (this.initiated) {
110
- this.generateCalendar();
111
- this.cdRef.markForCheck();
112
- }
113
- }
114
-
115
- /** The currently selected date. */
116
- private _selected: T | null;
117
- @Input()
118
- get selected(): T | null {
119
- return this._selected;
120
- }
121
-
122
- set selected(value: T | null) {
123
- const oldSelected = this._selected;
124
- value = this.dateTimeAdapter.deserialize(value);
125
- this._selected = this.getValidDate(value);
126
-
127
- if (!this.dateTimeAdapter.isSameDay(oldSelected, this._selected)) {
128
- this.setSelectedDates();
129
- }
130
- }
131
-
132
- private _selecteds: T[] = [];
133
- @Input()
134
- get selecteds(): T[] {
135
- return this._selecteds;
136
- }
137
-
138
- set selecteds(values: T[]) {
139
- this._selecteds = values.map(v => {
140
- v = this.dateTimeAdapter.deserialize(v);
141
- return this.getValidDate(v);
142
- });
143
- this.setSelectedDates();
144
- }
145
-
146
- private _pickerMoment: T;
147
- @Input()
148
- get pickerMoment() {
149
- return this._pickerMoment;
150
- }
151
-
152
- set pickerMoment(value: T) {
153
- const oldMoment = this._pickerMoment;
154
- value = this.dateTimeAdapter.deserialize(value);
155
- this._pickerMoment =
156
- this.getValidDate(value) || this.dateTimeAdapter.now();
157
-
158
- this.firstDateOfMonth = this.dateTimeAdapter.createDate(
159
- this.dateTimeAdapter.getYear(this._pickerMoment),
160
- this.dateTimeAdapter.getMonth(this._pickerMoment),
161
- 1
162
- );
163
-
164
- if (
165
- !this.isSameMonth(oldMoment, this._pickerMoment) &&
166
- this.initiated
167
- ) {
168
- this.generateCalendar();
169
- }
170
- }
171
-
172
- /**
173
- * A function used to filter which dates are selectable
174
- * */
175
- private _dateFilter: (date: T) => boolean;
176
- @Input()
177
- get dateFilter() {
178
- return this._dateFilter;
179
- }
180
-
181
- set dateFilter(filter: (date: T) => boolean) {
182
- this._dateFilter = filter;
183
- if (this.initiated) {
184
- this.generateCalendar();
185
- this.cdRef.markForCheck();
186
- }
187
- }
188
-
189
- /** The minimum selectable date. */
190
- private _minDate: T | null;
191
- @Input()
192
- get minDate(): T | null {
193
- return this._minDate;
194
- }
195
-
196
- set minDate(value: T | null) {
197
- value = this.dateTimeAdapter.deserialize(value);
198
- this._minDate = this.getValidDate(value);
199
- if (this.initiated) {
200
- this.generateCalendar();
201
- this.cdRef.markForCheck();
202
- }
203
- }
204
-
205
- /** The maximum selectable date. */
206
- private _maxDate: T | null;
207
- @Input()
208
- get maxDate(): T | null {
209
- return this._maxDate;
210
- }
211
-
212
- set maxDate(value: T | null) {
213
- value = this.dateTimeAdapter.deserialize(value);
214
- this._maxDate = this.getValidDate(value);
215
-
216
- if (this.initiated) {
217
- this.generateCalendar();
218
- this.cdRef.markForCheck();
219
- }
220
- }
221
-
222
- private _weekdays: Array<{ long: string; short: string; narrow: string }>;
223
- get weekdays() {
224
- return this._weekdays;
225
- }
226
-
227
- private _days: CalendarCell[][];
228
- get days() {
229
- return this._days;
230
- }
231
-
232
- get activeCell(): number {
233
- if (this.pickerMoment) {
234
- return (
235
- this.dateTimeAdapter.getDate(this.pickerMoment) +
236
- this.firstRowOffset -
237
- 1
238
- );
239
- }
240
- }
241
-
242
- get isInSingleMode(): boolean {
243
- return this.selectMode === 'single';
244
- }
245
-
246
- get isInRangeMode(): boolean {
247
- return (
248
- this.selectMode === 'range' ||
249
- this.selectMode === 'rangeFrom' ||
250
- this.selectMode === 'rangeTo'
251
- );
252
- }
253
-
254
- private firstDateOfMonth: T;
255
-
256
- private localeSub: Subscription = Subscription.EMPTY;
257
-
258
- private initiated = false;
259
-
260
- private dateNames: string[];
261
-
262
- /**
263
- * The date of the month that today falls on.
264
- * */
265
- public todayDate: number | null;
266
-
267
- /**
268
- * Week day numbers
269
- * */
270
- public weekNumbers: number[];
271
-
272
- /**
273
- * An array to hold all selectedDates' value
274
- * the value is the day number in current month
275
- * */
276
- public selectedDates: number[] = [];
277
-
278
- // the index of cell that contains the first date of the month
279
- public firstRowOffset: number;
280
-
281
- /**
282
- * Callback to invoke when a new date is selected
283
- * */
284
- @Output()
285
- readonly selectedChange = new EventEmitter<T | null>();
286
-
287
- /**
288
- * Callback to invoke when any date is selected.
289
- * */
290
- @Output()
291
- readonly userSelection = new EventEmitter<void>();
292
-
293
- /** Emits when any date is activated. */
294
- @Output()
295
- readonly pickerMomentChange: EventEmitter<T> = new EventEmitter<T>();
296
-
297
- /** The body of calendar table */
298
- @ViewChild(OwlCalendarBodyComponent, { static: true })
299
- calendarBodyElm: OwlCalendarBodyComponent;
300
-
301
- get owlDTCalendarView(): boolean {
302
- return true;
303
- }
304
-
305
- constructor(
306
- private cdRef: ChangeDetectorRef,
307
- @Optional() private dateTimeAdapter: DateTimeAdapter<T>,
308
- @Optional()
309
- @Inject(OWL_DATE_TIME_FORMATS)
310
- private dateTimeFormats: OwlDateTimeFormats
311
- ) {}
312
-
313
- public ngOnInit() {
314
- this.updateFirstDayOfWeek(this.dateTimeAdapter.getLocale());
315
- this.generateWeekDays();
316
-
317
- this.localeSub = this.dateTimeAdapter.localeChanges.subscribe(
318
- locale => {
319
- this.updateFirstDayOfWeek(locale);
320
- this.generateWeekDays();
321
- this.generateCalendar();
322
- this.cdRef.markForCheck();
323
- }
324
- );
325
- }
326
-
327
- public ngAfterContentInit(): void {
328
- this.generateCalendar();
329
- this.initiated = true;
330
- }
331
-
332
- public ngOnDestroy(): void {
333
- this.localeSub.unsubscribe();
334
- }
335
-
336
- /**
337
- * Handle a calendarCell selected
338
- */
339
- public selectCalendarCell(cell: CalendarCell): void {
340
- // Cases in which the date would not be selected
341
- // 1, the calendar cell is NOT enabled (is NOT valid)
342
- // 2, the selected date is NOT in current picker's month and the hideOtherMonths is enabled
343
- if (!cell.enabled || (this.hideOtherMonths && cell.out)) {
344
- return;
345
- }
346
-
347
- this.selectDate(cell.value);
348
- }
349
-
350
- /**
351
- * Handle a new date selected
352
- */
353
- private selectDate(date: number): void {
354
- const daysDiff = date - 1;
355
- const selected = this.dateTimeAdapter.addCalendarDays(
356
- this.firstDateOfMonth,
357
- daysDiff
358
- );
359
-
360
- this.selectedChange.emit(selected);
361
- this.userSelection.emit();
362
- }
363
-
364
- /**
365
- * Handle keydown event on calendar body
366
- */
367
- public handleCalendarKeydown(event: KeyboardEvent): void {
368
- let moment;
369
- switch (event.keyCode) {
370
- // minus 1 day
371
- case LEFT_ARROW:
372
- moment = this.dateTimeAdapter.addCalendarDays(
373
- this.pickerMoment,
374
- -1
375
- );
376
- this.pickerMomentChange.emit(moment);
377
- break;
378
-
379
- // add 1 day
380
- case RIGHT_ARROW:
381
- moment = this.dateTimeAdapter.addCalendarDays(
382
- this.pickerMoment,
383
- 1
384
- );
385
- this.pickerMomentChange.emit(moment);
386
- break;
387
-
388
- // minus 1 week
389
- case UP_ARROW:
390
- moment = this.dateTimeAdapter.addCalendarDays(
391
- this.pickerMoment,
392
- -7
393
- );
394
- this.pickerMomentChange.emit(moment);
395
- break;
396
-
397
- // add 1 week
398
- case DOWN_ARROW:
399
- moment = this.dateTimeAdapter.addCalendarDays(
400
- this.pickerMoment,
401
- 7
402
- );
403
- this.pickerMomentChange.emit(moment);
404
- break;
405
-
406
- // move to first day of current month
407
- case HOME:
408
- moment = this.dateTimeAdapter.addCalendarDays(
409
- this.pickerMoment,
410
- 1 - this.dateTimeAdapter.getDate(this.pickerMoment)
411
- );
412
- this.pickerMomentChange.emit(moment);
413
- break;
414
-
415
- // move to last day of current month
416
- case END:
417
- moment = this.dateTimeAdapter.addCalendarDays(
418
- this.pickerMoment,
419
- this.dateTimeAdapter.getNumDaysInMonth(this.pickerMoment) -
420
- this.dateTimeAdapter.getDate(this.pickerMoment)
421
- );
422
- this.pickerMomentChange.emit(moment);
423
- break;
424
-
425
- // minus 1 month (or 1 year)
426
- case PAGE_UP:
427
- moment = event.altKey
428
- ? this.dateTimeAdapter.addCalendarYears(
429
- this.pickerMoment,
430
- -1
431
- )
432
- : this.dateTimeAdapter.addCalendarMonths(
433
- this.pickerMoment,
434
- -1
435
- );
436
- this.pickerMomentChange.emit(moment);
437
- break;
438
-
439
- // add 1 month (or 1 year)
440
- case PAGE_DOWN:
441
- moment = event.altKey
442
- ? this.dateTimeAdapter.addCalendarYears(
443
- this.pickerMoment,
444
- 1
445
- )
446
- : this.dateTimeAdapter.addCalendarMonths(
447
- this.pickerMoment,
448
- 1
449
- );
450
- this.pickerMomentChange.emit(moment);
451
- break;
452
-
453
- // select the pickerMoment
454
- case ENTER:
455
- if (!this.dateFilter || this.dateFilter(this.pickerMoment)) {
456
- this.selectDate(
457
- this.dateTimeAdapter.getDate(this.pickerMoment)
458
- );
459
- }
460
- break;
461
- default:
462
- return;
463
- }
464
-
465
- this.focusActiveCell();
466
- event.preventDefault();
467
- }
468
-
469
- /**
470
- * Generate the calendar weekdays array
471
- * */
472
- private generateWeekDays(): void {
473
- const longWeekdays = this.dateTimeAdapter.getDayOfWeekNames('long');
474
- const shortWeekdays = this.dateTimeAdapter.getDayOfWeekNames('short');
475
- const narrowWeekdays = this.dateTimeAdapter.getDayOfWeekNames('narrow');
476
- const firstDayOfWeek = this.firstDayOfWeek;
477
-
478
- const weekdays = longWeekdays.map((long, i) => {
479
- return { long, short: shortWeekdays[i], narrow: narrowWeekdays[i] };
480
- });
481
-
482
- this._weekdays = weekdays
483
- .slice(firstDayOfWeek-this.dateTimeAdapter.firstDayOfTheWeek)
484
- .concat(weekdays.slice(0, firstDayOfWeek-this.dateTimeAdapter.firstDayOfTheWeek));
485
-
486
- this.dateNames = this.dateTimeAdapter.getDateNames();
487
-
488
- return;
489
- }
490
-
491
- /**
492
- * Generate the calendar days array
493
- * */
494
- private generateCalendar(): void {
495
- if (!this.pickerMoment) {
496
- return;
497
- }
498
-
499
- this.todayDate = null;
500
- this.weekNumbers = [];
501
-
502
- const startWeekdayOfMonth = this.dateTimeAdapter.getDay(
503
- this.firstDateOfMonth
504
- );
505
- const firstDayOfWeek = this.firstDayOfWeek;
506
-
507
- let daysDiff =
508
- 0 -
509
- ((startWeekdayOfMonth + (DAYS_PER_WEEK - firstDayOfWeek)) %
510
- DAYS_PER_WEEK);
511
-
512
- this.firstRowOffset = Math.abs(daysDiff);
513
-
514
- this._days = [];
515
-
516
- for (let i = 0; i < WEEKS_PER_VIEW; i++) {
517
- const week = [];
518
- const weekStartDate = this.dateTimeAdapter.addCalendarDays(
519
- this.firstDateOfMonth,
520
- daysDiff
521
- );
522
-
523
- for (let j = 0; j < DAYS_PER_WEEK; j++) {
524
- const date = this.dateTimeAdapter.addCalendarDays(
525
- this.firstDateOfMonth,
526
- daysDiff
527
- );
528
-
529
- const dateCell = this.createDateCell(date, daysDiff);
530
-
531
- if (
532
- this.dateTimeAdapter.isSameDay(
533
- this.dateTimeAdapter.now(),
534
- date
535
- )
536
- ) {
537
- this.todayDate = daysDiff + 1;
538
- }
539
-
540
- week.push(dateCell);
541
- daysDiff += 1;
542
- }
543
-
544
- this._days.push(week);
545
-
546
- if (this.showCalendarWeeks) {
547
- const weekNumber = this.getISOWeekFromDate(weekStartDate);
548
- this.weekNumbers.push(weekNumber);
549
- }
550
- }
551
-
552
- this.setSelectedDates();
553
- }
554
-
555
- public getISOWeek(d: Date): number {
556
- const clonedDate = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()));
557
- // Make Sunday's day number 7
558
- clonedDate.setUTCDate(clonedDate.getUTCDate() + 4 - (clonedDate.getUTCDay()||7));
559
- // Get first day of year
560
- const yearStart = new Date(Date.UTC(clonedDate.getUTCFullYear(),0,1));
561
- // Calculate full weeks to nearest Thursday
562
- const weekNo = Math.ceil(( ( (+clonedDate - +yearStart) / 86400000) + 1)/7);
563
- return weekNo;
564
- }
565
-
566
- private updateFirstDayOfWeek(locale: string): void {
567
- if (this.isDefaultFirstDayOfWeek) {
568
- try {
569
- this._firstDayOfWeek = getLocaleFirstDayOfWeek(locale);
570
- } catch {
571
- this._firstDayOfWeek = 0;
572
- }
573
- }
574
- }
575
-
576
- /**
577
- * Creates CalendarCell for days.
578
- */
579
- private createDateCell(date: T, daysDiff: number): CalendarCell {
580
- // total days of the month
581
- const daysInMonth = this.dateTimeAdapter.getNumDaysInMonth(
582
- this.pickerMoment
583
- );
584
- const dateNum = this.dateTimeAdapter.getDate(date);
585
- // const dateName = this.dateNames[dateNum - 1];
586
- const dateName = dateNum.toString();
587
- const ariaLabel = this.dateTimeAdapter.format(
588
- date,
589
- this.dateTimeFormats.dateA11yLabel
590
- );
591
-
592
- // check if the date if selectable
593
- const enabled = this.isDateEnabled(date);
594
-
595
- // check if date is not in current month
596
- const dayValue = daysDiff + 1;
597
- const out = dayValue < 1 || dayValue > daysInMonth;
598
- const cellClass = 'owl-dt-day-' + this.dateTimeAdapter.getDay(date);
599
-
600
- return new CalendarCell(
601
- dayValue,
602
- dateName,
603
- ariaLabel,
604
- enabled,
605
- out,
606
- cellClass
607
- );
608
- }
609
-
610
- /**
611
- * Check if the date is valid
612
- */
613
- private isDateEnabled(date: T): boolean {
614
- return (
615
- !!date &&
616
- (!this.dateFilter || this.dateFilter(date)) &&
617
- (!this.minDate ||
618
- this.dateTimeAdapter.compare(date, this.minDate) >= 0) &&
619
- (!this.maxDate ||
620
- this.dateTimeAdapter.compare(date, this.maxDate) <= 0)
621
- );
622
- }
623
-
624
- /**
625
- * Get a valid date object
626
- */
627
- private getValidDate(obj: any): T | null {
628
- return this.dateTimeAdapter.isDateInstance(obj) &&
629
- this.dateTimeAdapter.isValid(obj)
630
- ? obj
631
- : null;
632
- }
633
-
634
- /**
635
- * Check if the give dates are none-null and in the same month
636
- */
637
- public isSameMonth(dateLeft: T, dateRight: T): boolean {
638
- return (
639
- dateLeft &&
640
- dateRight &&
641
- this.dateTimeAdapter.isValid(dateLeft) &&
642
- this.dateTimeAdapter.isValid(dateRight) &&
643
- this.dateTimeAdapter.getYear(dateLeft) ===
644
- this.dateTimeAdapter.getYear(dateRight) &&
645
- this.dateTimeAdapter.getMonth(dateLeft) ===
646
- this.dateTimeAdapter.getMonth(dateRight)
647
- );
648
- }
649
-
650
- private getISOWeekFromDate(date: T): number {
651
- const jsDate = new Date(Date.UTC(
652
- this.dateTimeAdapter.getYear(date),
653
- this.dateTimeAdapter.getMonth(date),
654
- this.dateTimeAdapter.getDate(date),
655
- ));
656
-
657
- jsDate.setUTCDate(
658
- jsDate.getUTCDate() + 4 - (jsDate.getUTCDay() || 7)
659
- );
660
-
661
- const yearStart = new Date(Date.UTC(jsDate.getUTCFullYear(), 0, 1));
662
-
663
- return Math.ceil((((+jsDate - +yearStart) / 86400000) + 1) / 7);
664
- }
665
-
666
- /**
667
- * Set the selectedDates value.
668
- * In single mode, it has only one value which represent the selected date
669
- * In range mode, it would has two values, one for the fromValue and the other for the toValue
670
- * */
671
- private setSelectedDates(): void {
672
- this.selectedDates = [];
673
-
674
- if (!this.firstDateOfMonth) {
675
- return;
676
- }
677
-
678
- if (this.isInSingleMode && this.selected) {
679
- const dayDiff = this.dateTimeAdapter.differenceInCalendarDays(
680
- this.selected,
681
- this.firstDateOfMonth
682
- );
683
- this.selectedDates[0] = dayDiff + 1;
684
- return;
685
- }
686
-
687
- if (this.isInRangeMode && this.selecteds) {
688
- this.selectedDates = this.selecteds.map(selected => {
689
- if (this.dateTimeAdapter.isValid(selected)) {
690
- const dayDiff = this.dateTimeAdapter.differenceInCalendarDays(
691
- selected,
692
- this.firstDateOfMonth
693
- );
694
- return dayDiff + 1;
695
- } else {
696
- return null;
697
- }
698
- });
699
- }
700
- }
701
-
702
- private focusActiveCell() {
703
- this.calendarBodyElm.focusActiveCell();
704
- }
705
- }