@imihai/angular-datetime-picker 22.0.0 → 22.0.8

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.8.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,313 +0,0 @@
1
- /**
2
- * date-time-adapter.class
3
- */
4
- import { Observable, Subject } from 'rxjs';
5
- import { inject, InjectionToken, LOCALE_ID } from '@angular/core';
6
-
7
- /** InjectionToken for date time picker that can be used to override default locale code. */
8
- export const OWL_DATE_TIME_LOCALE = new InjectionToken<string>(
9
- 'OWL_DATE_TIME_LOCALE',
10
- {
11
- providedIn: 'root',
12
- factory: OWL_DATE_TIME_LOCALE_FACTORY
13
- }
14
- );
15
-
16
- /** @docs-private */
17
- export function OWL_DATE_TIME_LOCALE_FACTORY(): string {
18
- return inject(LOCALE_ID);
19
- }
20
-
21
- /** Provider for OWL_DATE_TIME_LOCALE injection token. */
22
- export const OWL_DATE_TIME_LOCALE_PROVIDER = {
23
- provide: OWL_DATE_TIME_LOCALE,
24
- useExisting: LOCALE_ID
25
- };
26
-
27
- export abstract class DateTimeAdapter<T> {
28
- /** The locale to use for all dates. */
29
- protected locale: any;
30
-
31
- /** A stream that emits when the locale changes. */
32
- protected _localeChanges = new Subject<string>();
33
- get localeChanges(): Observable<string> {
34
- return this._localeChanges;
35
- }
36
-
37
- public firstMonthOfTheYear: number = 0;
38
- public firstDayOfTheWeek: number = 0;
39
-
40
- /** total milliseconds in a day. */
41
- protected readonly millisecondsInDay = 86400000;
42
-
43
- /** total milliseconds in a minute. */
44
- protected readonly millisecondsInMinute = 60000;
45
-
46
- /**
47
- * Get the year of the given date
48
- */
49
- abstract getYear(date: T): number;
50
-
51
- /**
52
- * Get the month of the given date
53
- * 0 -- January
54
- * 11 -- December
55
- * */
56
- abstract getMonth(date: T): number;
57
-
58
- /**
59
- * Get the day of the week of the given date
60
- * 0 -- Sunday
61
- * 6 -- Saturday
62
- * */
63
- abstract getDay(date: T): number;
64
-
65
- /**
66
- * Get the day num of the given date
67
- */
68
- abstract getDate(date: T): number;
69
-
70
- /**
71
- * Get the hours of the given date
72
- */
73
- abstract getHours(date: T): number;
74
-
75
- /**
76
- * Get the minutes of the given date
77
- */
78
- abstract getMinutes(date: T): number;
79
-
80
- /**
81
- * Get the seconds of the given date
82
- */
83
- abstract getSeconds(date: T): number;
84
-
85
- /**
86
- * Get the milliseconds timestamp of the given date
87
- */
88
- abstract getTime(date: T): number;
89
-
90
- /**
91
- * Gets the number of days in the month of the given date.
92
- */
93
- abstract getNumDaysInMonth(date: T): number;
94
-
95
- /**
96
- * Get the number of calendar days between the given dates.
97
- * If dateLeft is before dateRight, it would return positive value
98
- * If dateLeft is after dateRight, it would return negative value
99
- */
100
- abstract differenceInCalendarDays(dateLeft: T, dateRight: T): number;
101
-
102
- /**
103
- * Gets the name for the year of the given date.
104
- */
105
- abstract getYearName(date: T): string;
106
-
107
- /**
108
- * Get a list of month names
109
- */
110
- abstract getMonthNames(style: 'long' | 'short' | 'narrow'): string[];
111
-
112
- /**
113
- * Get a list of week names
114
- */
115
- abstract getDayOfWeekNames(style: 'long' | 'short' | 'narrow'): string[];
116
-
117
- /**
118
- * Gets a list of names for the dates of the month.
119
- */
120
- abstract getDateNames(): string[];
121
-
122
- /**
123
- * Return a Date object as a string, using the ISO standard
124
- */
125
- abstract toIso8601(date: T): string;
126
-
127
- /**
128
- * Check if the give dates are equal
129
- */
130
- abstract isEqual(dateLeft: T, dateRight: T): boolean;
131
-
132
- /**
133
- * Check if the give dates are the same day
134
- */
135
- abstract isSameDay(dateLeft: T, dateRight: T): boolean;
136
-
137
- /**
138
- * Checks whether the given date is valid.
139
- */
140
- abstract isValid(date: T): boolean;
141
-
142
- /**
143
- * Gets date instance that is not valid.
144
- */
145
- abstract invalid(): T;
146
-
147
- /**
148
- * Checks whether the given object is considered a date instance by this DateTimeAdapter.
149
- */
150
- abstract isDateInstance(obj: any): boolean;
151
-
152
- /**
153
- * Add the specified number of years to the given date
154
- */
155
- abstract addCalendarYears(date: T, amount: number): T;
156
-
157
- /**
158
- * Add the specified number of months to the given date
159
- */
160
- abstract addCalendarMonths(date: T, amount: number): T;
161
-
162
- /**
163
- * Add the specified number of days to the given date
164
- */
165
- abstract addCalendarDays(date: T, amount: number): T;
166
-
167
- /**
168
- * Set the hours to the given date.
169
- */
170
- abstract setHours(date: T, amount: number): T;
171
-
172
- /**
173
- * Set the minutes to the given date.
174
- */
175
- abstract setMinutes(date: T, amount: number): T;
176
-
177
- /**
178
- * Set the seconds to the given date.
179
- */
180
- abstract setSeconds(date: T, amount: number): T;
181
-
182
- /**
183
- * Creates a date with the given year, month, date, hour, minute and second. Does not allow over/under-flow of the
184
- * month and date.
185
- */
186
- abstract createDate(year: number, month: number, date: number): T;
187
- abstract createDate(
188
- year: number,
189
- month: number,
190
- date: number,
191
- hours: number,
192
- minutes: number,
193
- seconds: number
194
- ): T;
195
-
196
- /**
197
- * Clone the given date
198
- */
199
- abstract clone(date: T): T;
200
-
201
- /**
202
- * Get a new moment
203
- * */
204
- abstract now(): T;
205
-
206
- /**
207
- * Formats a date as a string according to the given format.
208
- */
209
- abstract format(date: T, displayFormat: any): string;
210
-
211
- /**
212
- * Parse a user-provided value to a Date Object
213
- */
214
- abstract parse(value: any, parseFormat: any): T | null;
215
-
216
- /**
217
- * Compare two given dates
218
- * 1 if the first date is after the second,
219
- * -1 if the first date is before the second
220
- * 0 if dates are equal.
221
- * */
222
- compare(first: T, second: T): number {
223
- if (!this.isValid(first) || !this.isValid(second)) {
224
- throw Error('JSNativeDate: Cannot compare invalid dates.');
225
- }
226
-
227
- const dateFirst = this.clone(first);
228
- const dateSecond = this.clone(second);
229
-
230
- const diff = this.getTime(dateFirst) - this.getTime(dateSecond);
231
-
232
- if (diff < 0) {
233
- return -1;
234
- } else if (diff > 0) {
235
- return 1;
236
- } else {
237
- // Return 0 if diff is 0; return NaN if diff is NaN
238
- return diff;
239
- }
240
- }
241
-
242
- /**
243
- * Check if two given dates are in the same year
244
- * 1 if the first date's year is after the second,
245
- * -1 if the first date's year is before the second
246
- * 0 if two given dates are in the same year
247
- * */
248
- compareYear(first: T, second: T): number {
249
- if (!this.isValid(first) || !this.isValid(second)) {
250
- throw Error('JSNativeDate: Cannot compare invalid dates.');
251
- }
252
-
253
- const yearLeft = this.getYear(first);
254
- const yearRight = this.getYear(second);
255
-
256
- const diff = yearLeft - yearRight;
257
-
258
- if (diff < 0) {
259
- return -1;
260
- } else if (diff > 0) {
261
- return 1;
262
- } else {
263
- return 0;
264
- }
265
- }
266
-
267
- /**
268
- * Attempts to deserialize a value to a valid date object. This is different from parsing in that
269
- * deserialize should only accept non-ambiguous, locale-independent formats (e.g. a ISO 8601
270
- * string). The default implementation does not allow any deserialization, it simply checks that
271
- * the given value is already a valid date object or null. The `<mat-datepicker>` will call this
272
- * method on all of it's `@Input()` properties that accept dates. It is therefore possible to
273
- * support passing values from your backend directly to these properties by overriding this method
274
- * to also deserialize the format used by your backend.
275
- */
276
- deserialize(value: any): T | null {
277
- if (
278
- value == null ||
279
- (this.isDateInstance(value) && this.isValid(value))
280
- ) {
281
- return value;
282
- }
283
- return this.invalid();
284
- }
285
-
286
- /**
287
- * Sets the locale used for all dates.
288
- */
289
- setLocale(locale: string) {
290
- this.locale = locale;
291
- this._localeChanges.next(locale);
292
- }
293
-
294
- /**
295
- * Get the locale used for all dates.
296
- * */
297
- getLocale() {
298
- return this.locale;
299
- }
300
-
301
- /**
302
- * Clamp the given date between min and max dates.
303
- */
304
- clampDate(date: T, min?: T | null, max?: T | null): T {
305
- if (min && this.compare(date, min) < 0) {
306
- return min;
307
- }
308
- if (max && this.compare(date, max) > 0) {
309
- return max;
310
- }
311
- return date;
312
- }
313
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * date-time-format.class
3
- */
4
-
5
- import { InjectionToken } from '@angular/core';
6
-
7
- export interface OwlDateTimeFormats {
8
- parseInput: any;
9
- fullPickerInput: any;
10
- datePickerInput: any;
11
- timePickerInput: any;
12
- monthYearLabel: any;
13
- dateA11yLabel: any;
14
- monthYearA11yLabel: any;
15
- }
16
-
17
- /** InjectionToken for date time picker that can be used to override default format. */
18
- export const OWL_DATE_TIME_FORMATS = new InjectionToken<OwlDateTimeFormats>('OWL_DATE_TIME_FORMATS');
@@ -1,307 +0,0 @@
1
- /**
2
- * luxon-date-time-adapter.class
3
- */
4
-
5
- import { Inject, Injectable, Optional } from '@angular/core';
6
- import { DateTime, Info, Settings } from 'luxon';
7
-
8
- import {
9
- DateTimeAdapter,
10
- OWL_DATE_TIME_LOCALE,
11
- } from './date-time-adapter.class';
12
-
13
- @Injectable()
14
- export class LuxonDateTimeAdapter extends DateTimeAdapter<DateTime> {
15
- public firstMonthOfTheYear = 0;
16
-
17
- /**
18
- * 0 - Sunday
19
- * 1 - Monday
20
- * ...
21
- * 6 - Saturday
22
- */
23
- public firstDayOfTheWeek = 0;
24
-
25
- public constructor(
26
- @Optional()
27
- @Inject(OWL_DATE_TIME_LOCALE)
28
- private owlDateTimeLocale: string,
29
- ) {
30
- super();
31
-
32
- this.setLocale(owlDateTimeLocale || Settings.defaultLocale || 'ru');
33
- }
34
-
35
- public getYear(date: DateTime): number {
36
- return date.year;
37
- }
38
-
39
- /**
40
- * Picker expects month index:
41
- * 0 - January
42
- * 11 - December
43
- *
44
- * Luxon uses:
45
- * 1 - January
46
- * 12 - December
47
- */
48
- public getMonth(date: DateTime): number {
49
- return date.month - 1;
50
- }
51
-
52
- /**
53
- * Picker expects:
54
- * 0 - Sunday
55
- * 6 - Saturday
56
- *
57
- * Luxon weekday:
58
- * 1 - Monday
59
- * 7 - Sunday
60
- */
61
- public getDay(date: DateTime): number {
62
- return date.weekday % 7;
63
- }
64
-
65
- public getDate(date: DateTime): number {
66
- return date.day;
67
- }
68
-
69
- public getHours(date: DateTime): number {
70
- return date.hour;
71
- }
72
-
73
- public getMinutes(date: DateTime): number {
74
- return date.minute;
75
- }
76
-
77
- public getSeconds(date: DateTime): number {
78
- return date.second;
79
- }
80
-
81
- public getTime(date: DateTime): number {
82
- return date.toMillis();
83
- }
84
-
85
- public getNumDaysInMonth(date: DateTime): number {
86
- return date.daysInMonth ?? 0;
87
- }
88
-
89
- public differenceInCalendarDays(dateLeft: DateTime, dateRight: DateTime): number {
90
- if (this.isValid(dateLeft) && this.isValid(dateRight)) {
91
- return Math.round(
92
- dateLeft.startOf('day').diff(dateRight.startOf('day'), 'days').days,
93
- );
94
- }
95
-
96
- return null;
97
- }
98
-
99
- public getYearName(date: DateTime): string {
100
- return date.setLocale(this.locale).toFormat('yyyy');
101
- }
102
-
103
- public getMonthNames(style: 'long' | 'short' | 'narrow'): string[] {
104
- return Info.months(style, { locale: this.locale });
105
- }
106
-
107
- public getDayOfWeekNames(style: 'long' | 'short' | 'narrow'): string[] {
108
- const weekdays = Info.weekdays(style, { locale: this.locale });
109
-
110
- // Luxon returns Monday..Sunday.
111
- // Existing picker expects Sunday..Saturday.
112
- return [
113
- weekdays[6],
114
- ...weekdays.slice(0, 6),
115
- ];
116
- }
117
-
118
- public getDateNames(): string[] {
119
- return Array.from({ length: 31 }, (_, index) => `${index + 1}`);
120
- }
121
-
122
- public toIso8601(date: DateTime): string {
123
- return date.toISO() ?? '';
124
- }
125
-
126
- public isEqual(dateLeft: DateTime, dateRight: DateTime): boolean {
127
- if (this.isValid(dateLeft) && this.isValid(dateRight)) {
128
- return dateLeft.toMillis() === dateRight.toMillis();
129
- }
130
-
131
- return false;
132
- }
133
-
134
- public isSameDay(dateLeft: DateTime, dateRight: DateTime): boolean {
135
- if (this.isValid(dateLeft) && this.isValid(dateRight)) {
136
- return (
137
- dateLeft.year === dateRight.year &&
138
- dateLeft.month === dateRight.month &&
139
- dateLeft.day === dateRight.day
140
- );
141
- }
142
-
143
- return false;
144
- }
145
-
146
- public isValid(date: DateTime): boolean {
147
- return DateTime.isDateTime(date) && date.isValid;
148
- }
149
-
150
- public invalid(): DateTime {
151
- return DateTime.invalid('Invalid date');
152
- }
153
-
154
- public isDateInstance(obj: unknown): boolean {
155
- return DateTime.isDateTime(obj);
156
- }
157
-
158
- public addCalendarYears(date: DateTime, amount: number): DateTime {
159
- return date.plus({ years: Number(amount) });
160
- }
161
-
162
- public addCalendarMonths(date: DateTime, amount: number): DateTime {
163
- return date.plus({ months: Number(amount) });
164
- }
165
-
166
- public addCalendarDays(date: DateTime, amount: number): DateTime {
167
- return date.plus({ days: Number(amount) });
168
- }
169
-
170
- public setHours(date: DateTime, amount: number): DateTime {
171
- return date.set({ hour: amount });
172
- }
173
-
174
- public setMinutes(date: DateTime, amount: number): DateTime {
175
- return date.set({ minute: amount });
176
- }
177
-
178
- public setSeconds(date: DateTime, amount: number): DateTime {
179
- return date.set({ second: amount });
180
- }
181
-
182
- public createDate(
183
- year: number,
184
- month: number,
185
- date: number,
186
- hours = 0,
187
- minutes = 0,
188
- seconds = 0,
189
- ): DateTime {
190
- const result = DateTime.local(
191
- year,
192
- month + 1,
193
- date,
194
- hours,
195
- minutes,
196
- seconds,
197
- 0,
198
- ).setLocale(this.locale);
199
-
200
- if (!result.isValid) {
201
- throw Error(
202
- `LuxonDateTimeAdapter: Invalid date "${date}" for month with index "${month}".`,
203
- );
204
- }
205
-
206
- return result;
207
- }
208
-
209
- public clone(date: DateTime): DateTime {
210
- return DateTime.fromMillis(date.toMillis(), {
211
- zone: date.zone,
212
- locale: date.locale,
213
- });
214
- }
215
-
216
- public now(): DateTime {
217
- return DateTime.local().setLocale(this.locale);
218
- }
219
-
220
- public format(date: DateTime, displayFormat: string): string {
221
- if (!this.isValid(date)) {
222
- throw Error('LuxonDateTimeAdapter: Cannot format invalid date.');
223
- }
224
-
225
- return date.setLocale(this.locale).toFormat(displayFormat);
226
- }
227
-
228
- public parse(value: unknown, parseFormat: string | string[]): DateTime | null {
229
- if (value == null || value === '') {
230
- return null;
231
- }
232
-
233
- if (DateTime.isDateTime(value)) {
234
- return value.isValid ? value.setLocale(this.locale) : this.invalid();
235
- }
236
-
237
- if (value instanceof Date) {
238
- const date = DateTime.fromJSDate(value).setLocale(this.locale);
239
-
240
- return date.isValid ? date : this.invalid();
241
- }
242
-
243
- if (typeof value === 'number') {
244
- const date = DateTime.fromMillis(value).setLocale(this.locale);
245
-
246
- return date.isValid ? date : this.invalid();
247
- }
248
-
249
- if (typeof value !== 'string') {
250
- return this.invalid();
251
- }
252
-
253
- const formats = Array.isArray(parseFormat) ? parseFormat : [parseFormat];
254
-
255
- for (const format of formats) {
256
- const parsed = DateTime.fromFormat(value, format, {
257
- locale: this.locale,
258
- });
259
-
260
- if (parsed.isValid) {
261
- return parsed;
262
- }
263
- }
264
-
265
- const iso = DateTime.fromISO(value, {
266
- locale: this.locale,
267
- });
268
-
269
- return iso.isValid ? iso : this.invalid();
270
- }
271
-
272
- public deserialize(value: unknown): DateTime | null {
273
- if (value == null || value === '') {
274
- return null;
275
- }
276
-
277
- if (DateTime.isDateTime(value)) {
278
- return value.isValid ? value.setLocale(this.locale) : this.invalid();
279
- }
280
-
281
- if (value instanceof Date) {
282
- const date = DateTime.fromJSDate(value).setLocale(this.locale);
283
-
284
- return date.isValid ? date : this.invalid();
285
- }
286
-
287
- if (typeof value === 'number') {
288
- const date = DateTime.fromMillis(value).setLocale(this.locale);
289
-
290
- return date.isValid ? date : this.invalid();
291
- }
292
-
293
- if (typeof value === 'string') {
294
- const date = DateTime.fromISO(value, {
295
- locale: this.locale,
296
- });
297
-
298
- return date.isValid ? date : this.invalid();
299
- }
300
-
301
- return this.invalid();
302
- }
303
-
304
- public override setLocale(locale: string): void {
305
- super.setLocale(locale || 'ru');
306
- }
307
- }
@@ -1,11 +0,0 @@
1
- import { OwlDateTimeFormats } from './date-time-format.class';
2
-
3
- export const OWL_LUXON_DATE_TIME_FORMATS: OwlDateTimeFormats = {
4
- parseInput: 'dd.MM.yyyy HH:mm',
5
- fullPickerInput: 'dd.MM.yyyy HH:mm',
6
- datePickerInput: 'dd.MM.yyyy',
7
- timePickerInput: 'HH:mm',
8
- monthYearLabel: 'LLL yyyy',
9
- dateA11yLabel: 'dd.MM.yyyy',
10
- monthYearA11yLabel: 'LLLL yyyy',
11
- };
@@ -1,31 +0,0 @@
1
- /**
2
- * luxon-date-time.module
3
- */
4
-
5
- import { NgModule } from '@angular/core';
6
-
7
- import { DateTimeAdapter } from './date-time-adapter.class';
8
- import { OWL_DATE_TIME_FORMATS } from './date-time-format.class';
9
- import { LuxonDateTimeAdapter } from './luxon-date-time-adapter.class';
10
- import { OWL_LUXON_DATE_TIME_FORMATS } from './luxon-date-time-format.class';
11
-
12
- @NgModule({
13
- providers: [
14
- {
15
- provide: DateTimeAdapter,
16
- useClass: LuxonDateTimeAdapter,
17
- },
18
- ],
19
- })
20
- export class LuxonDateTimeModule {}
21
-
22
- @NgModule({
23
- imports: [LuxonDateTimeModule],
24
- providers: [
25
- {
26
- provide: OWL_DATE_TIME_FORMATS,
27
- useValue: OWL_LUXON_DATE_TIME_FORMATS,
28
- },
29
- ],
30
- })
31
- export class OwlLuxonDateTimeModule {}