@imihai/angular-datetime-picker 21.0.2 → 22.0.0

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/.browserslistrc +9 -0
  2. package/.editorconfig +13 -0
  3. package/.eslintrc.js +208 -0
  4. package/.github/workflows/ci_test.yml +35 -0
  5. package/.prettierrc +2 -0
  6. package/.travis.yml +16 -0
  7. package/angular.json +221 -0
  8. package/e2e/protractor.conf.js +28 -0
  9. package/e2e/src/app.e2e-spec.ts +14 -0
  10. package/e2e/src/app.po.ts +11 -0
  11. package/e2e/tsconfig.e2e.json +13 -0
  12. package/package.json +77 -33
  13. package/projects/picker/karma.conf.js +62 -0
  14. package/projects/picker/ng-package.json +7 -0
  15. package/projects/picker/package.json +23 -0
  16. package/projects/picker/src/lib/date-time/adapter/date-time-adapter.class.ts +313 -0
  17. package/projects/picker/src/lib/date-time/adapter/date-time-format.class.ts +18 -0
  18. package/projects/picker/src/lib/date-time/adapter/luxon-date-time-adapter.class.ts +307 -0
  19. package/projects/picker/src/lib/date-time/adapter/luxon-date-time-format.class.ts +11 -0
  20. package/projects/picker/src/lib/date-time/adapter/luxon-date-time.module.ts +31 -0
  21. package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time-adapter.class.ts +356 -0
  22. package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time-format.class.ts +14 -0
  23. package/projects/picker/src/lib/date-time/adapter/unix-timestamp-adapter/unix-timestamp-date-time.module.ts +26 -0
  24. package/projects/picker/src/lib/date-time/calendar-body.component.html +38 -0
  25. package/projects/picker/src/lib/date-time/calendar-body.component.scss +0 -0
  26. package/projects/picker/src/lib/date-time/calendar-body.component.spec.ts +120 -0
  27. package/projects/picker/src/lib/date-time/calendar-body.component.ts +190 -0
  28. package/projects/picker/src/lib/date-time/calendar-month-view.component.html +47 -0
  29. package/projects/picker/src/lib/date-time/calendar-month-view.component.scss +16 -0
  30. package/projects/picker/src/lib/date-time/calendar-month-view.component.spec.ts +394 -0
  31. package/projects/picker/src/lib/date-time/calendar-month-view.component.ts +705 -0
  32. package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.html +44 -0
  33. package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.scss +0 -0
  34. package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.spec.ts +343 -0
  35. package/projects/picker/src/lib/date-time/calendar-multi-year-view.component.ts +465 -0
  36. package/projects/picker/src/lib/date-time/calendar-year-view.component.html +16 -0
  37. package/projects/picker/src/lib/date-time/calendar-year-view.component.scss +0 -0
  38. package/projects/picker/src/lib/date-time/calendar-year-view.component.spec.ts +381 -0
  39. package/projects/picker/src/lib/date-time/calendar-year-view.component.ts +549 -0
  40. package/projects/picker/src/lib/date-time/calendar.component.html +169 -0
  41. package/projects/picker/src/lib/date-time/calendar.component.scss +0 -0
  42. package/projects/picker/src/lib/date-time/calendar.component.spec.ts +592 -0
  43. package/projects/picker/src/lib/date-time/calendar.component.ts +496 -0
  44. package/projects/picker/src/lib/date-time/date-time-inline.component.html +1 -0
  45. package/projects/picker/src/lib/date-time/date-time-inline.component.scss +4 -0
  46. package/projects/picker/src/lib/date-time/date-time-inline.component.ts +365 -0
  47. package/projects/picker/src/lib/date-time/date-time-picker-animation-event.ts +4 -0
  48. package/projects/picker/src/lib/date-time/date-time-picker-container.component.html +126 -0
  49. package/projects/picker/src/lib/date-time/date-time-picker-container.component.scss +0 -0
  50. package/projects/picker/src/lib/date-time/date-time-picker-container.component.ts +631 -0
  51. package/projects/picker/src/lib/date-time/date-time-picker-input.directive.ts +851 -0
  52. package/projects/picker/src/lib/date-time/date-time-picker-intl.service.ts +76 -0
  53. package/projects/picker/src/lib/date-time/date-time-picker-trigger.directive.ts +88 -0
  54. package/projects/picker/src/lib/date-time/date-time-picker.component.html +0 -0
  55. package/projects/picker/src/lib/date-time/date-time-picker.component.scss +0 -0
  56. package/projects/picker/src/lib/date-time/date-time-picker.component.spec.ts +2648 -0
  57. package/projects/picker/src/lib/date-time/date-time-picker.component.ts +731 -0
  58. package/projects/picker/src/lib/date-time/date-time.class.ts +256 -0
  59. package/projects/picker/src/lib/date-time/date-time.module.ts +61 -0
  60. package/projects/picker/src/lib/date-time/numberedFixLen.pipe.ts +28 -0
  61. package/projects/picker/src/lib/date-time/options-provider.ts +44 -0
  62. package/projects/picker/src/lib/date-time/timer-box.component.html +79 -0
  63. package/projects/picker/src/lib/date-time/timer-box.component.scss +0 -0
  64. package/projects/picker/src/lib/date-time/timer-box.component.ts +175 -0
  65. package/projects/picker/src/lib/date-time/timer.component.html +58 -0
  66. package/projects/picker/src/lib/date-time/timer.component.scss +0 -0
  67. package/projects/picker/src/lib/date-time/timer.component.spec.ts +399 -0
  68. package/projects/picker/src/lib/date-time/timer.component.ts +371 -0
  69. package/projects/picker/src/lib/dialog/dialog-config.class.ts +220 -0
  70. package/projects/picker/src/lib/dialog/dialog-container.component.html +1 -0
  71. package/projects/picker/src/lib/dialog/dialog-container.component.scss +0 -0
  72. package/projects/picker/src/lib/dialog/dialog-container.component.ts +231 -0
  73. package/projects/picker/src/lib/dialog/dialog-ref.class.ts +178 -0
  74. package/projects/picker/src/lib/dialog/dialog.module.ts +25 -0
  75. package/projects/picker/src/lib/dialog/dialog.service.ts +353 -0
  76. package/projects/picker/src/lib/utils/array.utils.ts +12 -0
  77. package/projects/picker/src/lib/utils/constants.ts +59 -0
  78. package/projects/picker/src/lib/utils/date.utils.ts +97 -0
  79. package/projects/picker/src/lib/utils/index.ts +5 -0
  80. package/projects/picker/src/lib/utils/object.utils.ts +29 -0
  81. package/projects/picker/src/public_api.ts +56 -0
  82. package/projects/picker/src/sass/picker.scss +743 -0
  83. package/projects/picker/src/test-helpers.ts +125 -0
  84. package/projects/picker/src/test.ts +52 -0
  85. package/projects/picker/tsconfig.lib.json +19 -0
  86. package/projects/picker/tsconfig.lib.prod.json +7 -0
  87. package/projects/picker/tsconfig.spec.json +17 -0
  88. package/projects/picker/tslint.json +8 -0
  89. package/src/app/app.component.html +77 -0
  90. package/src/app/app.component.scss +32 -0
  91. package/src/app/app.component.spec.ts +16 -0
  92. package/src/app/app.component.ts +35 -0
  93. package/src/assets/.gitkeep +0 -0
  94. package/src/environments/environment.prod.ts +3 -0
  95. package/src/environments/environment.ts +16 -0
  96. package/src/favicon.ico +0 -0
  97. package/src/index.html +14 -0
  98. package/src/karma.conf.js +31 -0
  99. package/src/main.ts +16 -0
  100. package/src/polyfills.ts +53 -0
  101. package/src/styles.scss +7 -0
  102. package/src/test.ts +50 -0
  103. package/src/tsconfig.app.json +16 -0
  104. package/src/tsconfig.spec.json +18 -0
  105. package/src/tslint.json +17 -0
  106. package/tsconfig.base.json +31 -0
  107. package/tsconfig.json +30 -0
  108. package/tslint.json +130 -0
  109. package/assets/style/picker.min.css +0 -1
  110. package/fesm2022/imihai-angular-datetime-picker.mjs +0 -5845
  111. package/fesm2022/imihai-angular-datetime-picker.mjs.map +0 -1
  112. package/imihai-angular-datetime-picker-21.0.2.tgz +0 -0
  113. package/types/imihai-angular-datetime-picker.d.ts +0 -2193
@@ -0,0 +1,549 @@
1
+ /**
2
+ * calendar-year-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
+
42
+ const MONTHS_PER_YEAR = 12;
43
+ const MONTHS_PER_ROW = 3;
44
+
45
+ @Component({
46
+ selector: 'owl-date-time-year-view',
47
+ exportAs: 'owlMonthView',
48
+ templateUrl: './calendar-year-view.component.html',
49
+ styleUrls: ['./calendar-year-view.component.scss'],
50
+ host: {
51
+ '[class.owl-dt-calendar-view]': 'owlDTCalendarView'
52
+ },
53
+ standalone: false,
54
+ preserveWhitespaces: false,
55
+ changeDetection: ChangeDetectionStrategy.OnPush
56
+ })
57
+ export class OwlYearViewComponent<T>
58
+ implements OnInit, AfterContentInit, OnDestroy {
59
+ /**
60
+ * The select mode of the picker;
61
+ * */
62
+ private _selectMode: SelectMode = 'single';
63
+ @Input()
64
+ get selectMode(): SelectMode {
65
+ return this._selectMode;
66
+ }
67
+
68
+ set selectMode(val: SelectMode) {
69
+ this._selectMode = val;
70
+ if (this.initiated) {
71
+ this.generateMonthList();
72
+ this.cdRef.markForCheck();
73
+ }
74
+ }
75
+
76
+ /** The currently selected date. */
77
+ private _selected: T | null;
78
+ @Input()
79
+ get selected(): T | null {
80
+ return this._selected;
81
+ }
82
+
83
+ set selected(value: T | null) {
84
+ value = this.dateTimeAdapter.deserialize(value);
85
+ this._selected = this.getValidDate(value);
86
+ this.setSelectedMonths();
87
+ }
88
+
89
+ private _selecteds: T[] = [];
90
+ @Input()
91
+ get selecteds(): T[] {
92
+ return this._selecteds;
93
+ }
94
+
95
+ set selecteds(values: T[]) {
96
+ this._selecteds = [];
97
+ for (let i = 0; i < values.length; i++) {
98
+ const value = this.dateTimeAdapter.deserialize(values[i]);
99
+ this._selecteds.push(this.getValidDate(value));
100
+ }
101
+
102
+ this.setSelectedMonths();
103
+ }
104
+
105
+ private _pickerMoment: T | null;
106
+ @Input()
107
+ get pickerMoment() {
108
+ return this._pickerMoment;
109
+ }
110
+
111
+ set pickerMoment(value: T) {
112
+ const oldMoment = this._pickerMoment;
113
+ value = this.dateTimeAdapter.deserialize(value);
114
+ this._pickerMoment =
115
+ this.getValidDate(value) || this.dateTimeAdapter.now();
116
+
117
+ if (
118
+ !this.hasSameYear(oldMoment, this._pickerMoment) &&
119
+ this.initiated
120
+ ) {
121
+ this.generateMonthList();
122
+ }
123
+ }
124
+
125
+ /**
126
+ * A function used to filter which dates are selectable
127
+ * */
128
+ private _dateFilter: (date: T) => boolean;
129
+ @Input()
130
+ get dateFilter() {
131
+ return this._dateFilter;
132
+ }
133
+
134
+ set dateFilter(filter: (date: T) => boolean) {
135
+ this._dateFilter = filter;
136
+ if (this.initiated) {
137
+ this.generateMonthList();
138
+ }
139
+ }
140
+
141
+ /** The minimum selectable date. */
142
+ private _minDate: T | null;
143
+ @Input()
144
+ get minDate(): T | null {
145
+ return this._minDate;
146
+ }
147
+
148
+ set minDate(value: T | null) {
149
+ value = this.dateTimeAdapter.deserialize(value);
150
+ this._minDate = this.getValidDate(value);
151
+ if (this.initiated) {
152
+ this.generateMonthList();
153
+ }
154
+ }
155
+
156
+ /** The maximum selectable date. */
157
+ private _maxDate: T | null;
158
+ @Input()
159
+ get maxDate(): T | null {
160
+ return this._maxDate;
161
+ }
162
+
163
+ set maxDate(value: T | null) {
164
+ value = this.dateTimeAdapter.deserialize(value);
165
+ this._maxDate = this.getValidDate(value);
166
+ if (this.initiated) {
167
+ this.generateMonthList();
168
+ }
169
+ }
170
+
171
+ private readonly monthNames: string[];
172
+
173
+ private _months: CalendarCell[][];
174
+ get months() {
175
+ return this._months;
176
+ }
177
+
178
+ get activeCell(): number {
179
+ if (this._pickerMoment) {
180
+ return this.dateTimeAdapter.getMonth(this._pickerMoment);
181
+ }
182
+ }
183
+
184
+ get isInSingleMode(): boolean {
185
+ return this.selectMode === 'single';
186
+ }
187
+
188
+ get isInRangeMode(): boolean {
189
+ return (
190
+ this.selectMode === 'range' ||
191
+ this.selectMode === 'rangeFrom' ||
192
+ this.selectMode === 'rangeTo'
193
+ );
194
+ }
195
+
196
+ private localeSub: Subscription = Subscription.EMPTY;
197
+
198
+ private initiated = false;
199
+
200
+ public todayMonth: number | null;
201
+
202
+ /**
203
+ * An array to hold all selectedDates' month value
204
+ * the value is the month number in current year
205
+ * */
206
+ public selectedMonths: number[] = [];
207
+
208
+ /**
209
+ * Callback to invoke when a new month is selected
210
+ * */
211
+ @Output()
212
+ readonly change = new EventEmitter<T>();
213
+
214
+ /**
215
+ * Emits the selected year. This doesn't imply a change on the selected date
216
+ * */
217
+ @Output()
218
+ readonly monthSelected = new EventEmitter<T>();
219
+
220
+ /** Emits when any date is activated. */
221
+ @Output()
222
+ readonly pickerMomentChange: EventEmitter<T> = new EventEmitter<T>();
223
+
224
+ /** Emits when use keyboard enter to select a calendar cell */
225
+ @Output()
226
+ readonly keyboardEnter: EventEmitter<any> = new EventEmitter<any>();
227
+
228
+ /** The body of calendar table */
229
+ @ViewChild(OwlCalendarBodyComponent, { static: true })
230
+ calendarBodyElm: OwlCalendarBodyComponent;
231
+
232
+ get owlDTCalendarView(): boolean {
233
+ return true;
234
+ }
235
+
236
+ constructor(
237
+ private cdRef: ChangeDetectorRef,
238
+ @Optional() private dateTimeAdapter: DateTimeAdapter<T>,
239
+ @Optional()
240
+ @Inject(OWL_DATE_TIME_FORMATS)
241
+ private dateTimeFormats: OwlDateTimeFormats
242
+ ) {
243
+ this.monthNames = this.dateTimeAdapter.getMonthNames('short');
244
+ }
245
+
246
+ public ngOnInit() {
247
+ this.localeSub = this.dateTimeAdapter.localeChanges.subscribe(() => {
248
+ this.generateMonthList();
249
+ this.cdRef.markForCheck();
250
+ });
251
+ }
252
+
253
+ public ngAfterContentInit(): void {
254
+ this.generateMonthList();
255
+ this.initiated = true;
256
+ }
257
+
258
+ public ngOnDestroy(): void {
259
+ this.localeSub.unsubscribe();
260
+ }
261
+
262
+ /**
263
+ * Handle a calendarCell selected
264
+ */
265
+ public selectCalendarCell(cell: CalendarCell): void {
266
+ this.selectMonth(cell.value);
267
+ }
268
+
269
+ /**
270
+ * Handle a new month selected
271
+ */
272
+ private selectMonth(month: number): void {
273
+ const firstDateOfMonth = this.dateTimeAdapter.createDate(
274
+ this.dateTimeAdapter.getYear(this.pickerMoment),
275
+ month,
276
+ 1
277
+ );
278
+
279
+ this.monthSelected.emit(firstDateOfMonth);
280
+
281
+ const daysInMonth = this.dateTimeAdapter.getNumDaysInMonth(
282
+ firstDateOfMonth
283
+ );
284
+ const result = this.dateTimeAdapter.createDate(
285
+ this.dateTimeAdapter.getYear(this.pickerMoment),
286
+ month,
287
+ Math.min(
288
+ daysInMonth,
289
+ this.dateTimeAdapter.getDate(this.pickerMoment)
290
+ ),
291
+ this.dateTimeAdapter.getHours(this.pickerMoment),
292
+ this.dateTimeAdapter.getMinutes(this.pickerMoment),
293
+ this.dateTimeAdapter.getSeconds(this.pickerMoment)
294
+ );
295
+
296
+ this.change.emit(result);
297
+ }
298
+
299
+ /**
300
+ * Handle keydown event on calendar body
301
+ */
302
+ public handleCalendarKeydown(event: KeyboardEvent): void {
303
+ let moment;
304
+ switch (event.keyCode) {
305
+ // minus 1 month
306
+ case LEFT_ARROW:
307
+ moment = this.dateTimeAdapter.addCalendarMonths(
308
+ this.pickerMoment,
309
+ -1
310
+ );
311
+ this.pickerMomentChange.emit(moment);
312
+ break;
313
+
314
+ // add 1 month
315
+ case RIGHT_ARROW:
316
+ moment = this.dateTimeAdapter.addCalendarMonths(
317
+ this.pickerMoment,
318
+ 1
319
+ );
320
+ this.pickerMomentChange.emit(moment);
321
+ break;
322
+
323
+ // minus 3 months
324
+ case UP_ARROW:
325
+ moment = this.dateTimeAdapter.addCalendarMonths(
326
+ this.pickerMoment,
327
+ -3
328
+ );
329
+ this.pickerMomentChange.emit(moment);
330
+ break;
331
+
332
+ // add 3 months
333
+ case DOWN_ARROW:
334
+ moment = this.dateTimeAdapter.addCalendarMonths(
335
+ this.pickerMoment,
336
+ 3
337
+ );
338
+ this.pickerMomentChange.emit(moment);
339
+ break;
340
+
341
+ // move to first month of current year
342
+ case HOME:
343
+ moment = this.dateTimeAdapter.addCalendarMonths(
344
+ this.pickerMoment,
345
+ -this.dateTimeAdapter.getMonth(this.pickerMoment)
346
+ );
347
+ this.pickerMomentChange.emit(moment);
348
+ break;
349
+
350
+ // move to last month of current year
351
+ case END:
352
+ moment = this.dateTimeAdapter.addCalendarMonths(
353
+ this.pickerMoment,
354
+ 11 - this.dateTimeAdapter.getMonth(this.pickerMoment)
355
+ );
356
+ this.pickerMomentChange.emit(moment);
357
+ break;
358
+
359
+ // minus 1 year (or 10 year)
360
+ case PAGE_UP:
361
+ moment = this.dateTimeAdapter.addCalendarYears(
362
+ this.pickerMoment,
363
+ event.altKey ? -10 : -1
364
+ );
365
+ this.pickerMomentChange.emit(moment);
366
+ break;
367
+
368
+ // add 1 year (or 10 year)
369
+ case PAGE_DOWN:
370
+ moment = this.dateTimeAdapter.addCalendarYears(
371
+ this.pickerMoment,
372
+ event.altKey ? 10 : 1
373
+ );
374
+ this.pickerMomentChange.emit(moment);
375
+ break;
376
+
377
+ // Select current month
378
+ case ENTER:
379
+ this.selectMonth(
380
+ this.dateTimeAdapter.getMonth(this.pickerMoment)
381
+ );
382
+ this.keyboardEnter.emit();
383
+ break;
384
+ default:
385
+ return;
386
+ }
387
+
388
+ this.focusActiveCell();
389
+ event.preventDefault();
390
+ }
391
+
392
+ /**
393
+ * Generate the calendar month list
394
+ * */
395
+ private generateMonthList(): void {
396
+ if (!this.pickerMoment) {
397
+ return;
398
+ }
399
+
400
+ this.setSelectedMonths();
401
+ this.todayMonth = this.getMonthInCurrentYear(
402
+ this.dateTimeAdapter.now()
403
+ );
404
+
405
+ this._months = [];
406
+ for (let i = 0; i < MONTHS_PER_YEAR / MONTHS_PER_ROW; i++) {
407
+ const row = [];
408
+
409
+ for (let j = 0; j < MONTHS_PER_ROW; j++) {
410
+ const month = j + i * MONTHS_PER_ROW + this.dateTimeAdapter.firstMonthOfTheYear;
411
+ const monthCell = this.createMonthCell(month);
412
+ row.push(monthCell);
413
+ }
414
+
415
+ this._months.push(row);
416
+ }
417
+
418
+ return;
419
+ }
420
+
421
+ /**
422
+ * Creates an CalendarCell for the given month.
423
+ */
424
+ private createMonthCell(month: number): CalendarCell {
425
+ const startDateOfMonth = this.dateTimeAdapter.createDate(
426
+ this.dateTimeAdapter.getYear(this.pickerMoment),
427
+ month,
428
+ 1
429
+ );
430
+ const ariaLabel = this.dateTimeAdapter.format(
431
+ startDateOfMonth,
432
+ this.dateTimeFormats.monthYearA11yLabel
433
+ );
434
+ const cellClass = 'owl-dt-month-' + month;
435
+ return new CalendarCell(
436
+ month,
437
+ this.monthNames[month-this.dateTimeAdapter.firstMonthOfTheYear],
438
+ ariaLabel,
439
+ this.isMonthEnabled(month),
440
+ false,
441
+ cellClass
442
+ );
443
+ }
444
+
445
+ /**
446
+ * Check if the given month is enable
447
+ */
448
+ private isMonthEnabled(month: number): boolean {
449
+ const firstDateOfMonth = this.dateTimeAdapter.createDate(
450
+ this.dateTimeAdapter.getYear(this.pickerMoment),
451
+ month,
452
+ 1
453
+ );
454
+
455
+ // If any date in the month is selectable,
456
+ // we count the month as enable
457
+ for (
458
+ let date = firstDateOfMonth;
459
+ this.dateTimeAdapter.getMonth(date) === month;
460
+ date = this.dateTimeAdapter.addCalendarDays(date, 1)
461
+ ) {
462
+ if (
463
+ !!date &&
464
+ (!this.dateFilter || this.dateFilter(date)) &&
465
+ (!this.minDate ||
466
+ this.dateTimeAdapter.compare(date, this.minDate) >= 0) &&
467
+ (!this.maxDate ||
468
+ this.dateTimeAdapter.compare(date, this.maxDate) <= 0)
469
+ ) {
470
+ return true;
471
+ }
472
+ }
473
+
474
+ return false;
475
+ }
476
+
477
+ /**
478
+ * Gets the month in this year that the given Date falls on.
479
+ * Returns null if the given Date is in another year.
480
+ */
481
+ private getMonthInCurrentYear(date: T | null): number {
482
+ if (this.getValidDate(date) && this.getValidDate(this._pickerMoment)) {
483
+ const result = this.dateTimeAdapter.compareYear(
484
+ date,
485
+ this._pickerMoment
486
+ );
487
+
488
+ // < 0 : the given date's year is before pickerMoment's year, we return -1 as selected month value.
489
+ // > 0 : the given date's year is after pickerMoment's year, we return 12 as selected month value.
490
+ // 0 : the give date's year is same as the pickerMoment's year, we return the actual month value.
491
+ if (result < 0) {
492
+ return -1;
493
+ } else if (result > 0) {
494
+ return 12;
495
+ } else {
496
+ return this.dateTimeAdapter.getMonth(date);
497
+ }
498
+ } else {
499
+ return null;
500
+ }
501
+ }
502
+
503
+ /**
504
+ * Set the selectedMonths value
505
+ * In single mode, it has only one value which represent the month the selected date in
506
+ * In range mode, it would has two values, one for the month the fromValue in and the other for the month the toValue in
507
+ * */
508
+ private setSelectedMonths(): void {
509
+ this.selectedMonths = [];
510
+ if (this.isInSingleMode && this.selected) {
511
+ this.selectedMonths[0] = this.getMonthInCurrentYear(this.selected);
512
+ }
513
+
514
+ if (this.isInRangeMode && this.selecteds) {
515
+ this.selectedMonths[0] = this.getMonthInCurrentYear(
516
+ this.selecteds[0]
517
+ );
518
+ this.selectedMonths[1] = this.getMonthInCurrentYear(
519
+ this.selecteds[1]
520
+ );
521
+ }
522
+ }
523
+
524
+ /**
525
+ * Check the given dates are in the same year
526
+ */
527
+ private hasSameYear(dateLeft: T, dateRight: T) {
528
+ return !!(
529
+ dateLeft &&
530
+ dateRight &&
531
+ this.dateTimeAdapter.getYear(dateLeft) ===
532
+ this.dateTimeAdapter.getYear(dateRight)
533
+ );
534
+ }
535
+
536
+ /**
537
+ * Get a valid date object
538
+ */
539
+ private getValidDate(obj: any): T | null {
540
+ return this.dateTimeAdapter.isDateInstance(obj) &&
541
+ this.dateTimeAdapter.isValid(obj)
542
+ ? obj
543
+ : null;
544
+ }
545
+
546
+ private focusActiveCell() {
547
+ this.calendarBodyElm.focusActiveCell();
548
+ }
549
+ }