nxt-pick-datetime 16.0.0-alpha.6 → 16.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 (111) hide show
  1. package/{esm2020 → esm2022}/lib/class/date-time-adapter.class.mjs +96 -96
  2. package/{esm2020 → esm2022}/lib/class/date-time-format.class.mjs +3 -3
  3. package/esm2022/lib/class/date-time.class.mjs +96 -0
  4. package/{esm2020 → esm2022}/lib/class/dialog-config.class.mjs +46 -46
  5. package/{esm2020 → esm2022}/lib/class/dialog-ref.class.mjs +118 -118
  6. package/esm2022/lib/date-time/calendar/calendar.component.mjs +347 -0
  7. package/esm2022/lib/date-time/calendar-body/calendar-body.component.mjs +152 -0
  8. package/esm2022/lib/date-time/calendar-month-view/calendar-month-view.component.mjs +430 -0
  9. package/esm2022/lib/date-time/calendar-multi-year-view/calendar-multi-year-view.component.mjs +359 -0
  10. package/esm2022/lib/date-time/calendar-year-view/calendar-year-view.component.mjs +363 -0
  11. package/esm2022/lib/date-time/date-time-inline/date-time-inline.component.mjs +276 -0
  12. package/esm2022/lib/date-time/date-time-picker/date-time-picker.component.mjs +542 -0
  13. package/{esm2020 → esm2022}/lib/date-time/date-time-picker-container/date-time-picker-container.animations.mjs +18 -18
  14. package/esm2022/lib/date-time/date-time-picker-container/date-time-picker-container.component.mjs +390 -0
  15. package/esm2022/lib/date-time/date-time-picker-input.directive.mjs +619 -0
  16. package/esm2022/lib/date-time/date-time-picker-intl.service.mjs +62 -0
  17. package/esm2022/lib/date-time/date-time-picker-trigger.directive.mjs +71 -0
  18. package/esm2022/lib/date-time/date-time.module.mjs +97 -0
  19. package/esm2022/lib/date-time/number-fixed-len.pipe.mjs +23 -0
  20. package/esm2022/lib/date-time/timer/timer.component.mjs +300 -0
  21. package/esm2022/lib/date-time/timer-box/timer-box.component.mjs +96 -0
  22. package/esm2022/lib/dialog/dialog-container/dialog-container.component.mjs +249 -0
  23. package/esm2022/lib/dialog/dialog.module.mjs +43 -0
  24. package/esm2022/lib/dialog/dialog.service.mjs +252 -0
  25. package/esm2022/lib/utils/object.mjs +24 -0
  26. package/esm2022/moment-adapter/date-time-adapter.class.mjs +221 -0
  27. package/{esm2020 → esm2022}/moment-adapter/date-time-format.class.mjs +12 -12
  28. package/esm2022/moment-adapter/moment-adapter.module.mjs +38 -0
  29. package/{esm2020 → esm2022}/moment-adapter/nxt-pick-datetime-moment-adapter.mjs +4 -4
  30. package/{esm2020 → esm2022}/moment-adapter/public-api.mjs +2 -2
  31. package/esm2022/native-adapter/date-time-adapter.class.mjs +367 -0
  32. package/{esm2020 → esm2022}/native-adapter/date-time-format.class.mjs +12 -12
  33. package/esm2022/native-adapter/native-adapter.module.mjs +38 -0
  34. package/{esm2020 → esm2022}/native-adapter/nxt-pick-datetime-native-adapter.mjs +4 -4
  35. package/{esm2020 → esm2022}/native-adapter/public-api.mjs +1 -1
  36. package/{esm2020 → esm2022}/nxt-pick-datetime.mjs +4 -4
  37. package/{esm2020 → esm2022}/public-api.mjs +13 -13
  38. package/{fesm2020 → fesm2022}/nxt-pick-datetime-moment-adapter.mjs +257 -257
  39. package/{fesm2020 → fesm2022}/nxt-pick-datetime-moment-adapter.mjs.map +1 -1
  40. package/{fesm2020 → fesm2022}/nxt-pick-datetime-native-adapter.mjs +402 -402
  41. package/{fesm2020 → fesm2022}/nxt-pick-datetime-native-adapter.mjs.map +1 -1
  42. package/{fesm2020 → fesm2022}/nxt-pick-datetime.mjs +4858 -4860
  43. package/{fesm2020 → fesm2022}/nxt-pick-datetime.mjs.map +1 -1
  44. package/index.d.ts +5 -5
  45. package/lib/class/date-time-adapter.class.d.ts +176 -176
  46. package/lib/class/date-time-format.class.d.ts +12 -12
  47. package/lib/class/date-time.class.d.ts +76 -76
  48. package/lib/class/dialog-config.class.d.ts +90 -90
  49. package/lib/class/dialog-ref.class.d.ts +50 -50
  50. package/lib/date-time/calendar/calendar.component.d.ts +147 -147
  51. package/lib/date-time/calendar-body/calendar-body.component.d.ts +79 -79
  52. package/lib/date-time/calendar-month-view/calendar-month-view.component.d.ts +139 -139
  53. package/lib/date-time/calendar-multi-year-view/calendar-multi-year-view.component.d.ts +115 -115
  54. package/lib/date-time/calendar-year-view/calendar-year-view.component.d.ts +123 -123
  55. package/lib/date-time/date-time-inline/date-time-inline.component.d.ts +106 -106
  56. package/lib/date-time/date-time-picker/date-time-picker.component.d.ts +172 -172
  57. package/lib/date-time/date-time-picker-container/date-time-picker-container.animations.d.ts +6 -6
  58. package/lib/date-time/date-time-picker-container/date-time-picker-container.component.d.ts +129 -129
  59. package/lib/date-time/date-time-picker-input.directive.d.ts +167 -167
  60. package/lib/date-time/date-time-picker-intl.service.d.ts +51 -51
  61. package/lib/date-time/date-time-picker-trigger.directive.d.ts +22 -22
  62. package/lib/date-time/date-time.module.d.ts +23 -23
  63. package/lib/date-time/number-fixed-len.pipe.d.ts +8 -8
  64. package/lib/date-time/timer/timer.component.d.ts +131 -131
  65. package/lib/date-time/timer-box/timer-box.component.d.ts +37 -37
  66. package/lib/dialog/dialog-container/dialog-container.component.d.ts +69 -69
  67. package/lib/dialog/dialog.module.d.ts +12 -12
  68. package/lib/dialog/dialog.service.d.ts +78 -78
  69. package/lib/utils/object.d.ts +9 -10
  70. package/moment-adapter/date-time-adapter.class.d.ts +64 -64
  71. package/moment-adapter/date-time-format.class.d.ts +5 -5
  72. package/moment-adapter/index.d.ts +5 -5
  73. package/moment-adapter/moment-adapter.module.d.ts +6 -6
  74. package/moment-adapter/public-api.d.ts +2 -2
  75. package/native-adapter/date-time-adapter.class.d.ts +72 -72
  76. package/native-adapter/date-time-format.class.d.ts +5 -5
  77. package/native-adapter/index.d.ts +5 -5
  78. package/native-adapter/native-adapter.module.d.ts +7 -7
  79. package/native-adapter/public-api.d.ts +1 -1
  80. package/package.json +18 -28
  81. package/public-api.d.ts +14 -14
  82. package/esm2020/lib/class/date-time.class.mjs +0 -95
  83. package/esm2020/lib/date-time/calendar/calendar.component.mjs +0 -346
  84. package/esm2020/lib/date-time/calendar-body/calendar-body.component.mjs +0 -151
  85. package/esm2020/lib/date-time/calendar-month-view/calendar-month-view.component.mjs +0 -429
  86. package/esm2020/lib/date-time/calendar-multi-year-view/calendar-multi-year-view.component.mjs +0 -358
  87. package/esm2020/lib/date-time/calendar-year-view/calendar-year-view.component.mjs +0 -362
  88. package/esm2020/lib/date-time/date-time-inline/date-time-inline.component.mjs +0 -275
  89. package/esm2020/lib/date-time/date-time-picker/date-time-picker.component.mjs +0 -541
  90. package/esm2020/lib/date-time/date-time-picker-container/date-time-picker-container.component.mjs +0 -389
  91. package/esm2020/lib/date-time/date-time-picker-input.directive.mjs +0 -618
  92. package/esm2020/lib/date-time/date-time-picker-intl.service.mjs +0 -61
  93. package/esm2020/lib/date-time/date-time-picker-trigger.directive.mjs +0 -70
  94. package/esm2020/lib/date-time/date-time.module.mjs +0 -96
  95. package/esm2020/lib/date-time/number-fixed-len.pipe.mjs +0 -22
  96. package/esm2020/lib/date-time/timer/timer.component.mjs +0 -299
  97. package/esm2020/lib/date-time/timer-box/timer-box.component.mjs +0 -95
  98. package/esm2020/lib/dialog/dialog-container/dialog-container.component.mjs +0 -248
  99. package/esm2020/lib/dialog/dialog.module.mjs +0 -42
  100. package/esm2020/lib/dialog/dialog.service.mjs +0 -252
  101. package/esm2020/lib/utils/object.mjs +0 -25
  102. package/esm2020/moment-adapter/date-time-adapter.class.mjs +0 -220
  103. package/esm2020/moment-adapter/moment-adapter.module.mjs +0 -37
  104. package/esm2020/native-adapter/date-time-adapter.class.mjs +0 -366
  105. package/esm2020/native-adapter/native-adapter.module.mjs +0 -37
  106. package/fesm2015/nxt-pick-datetime-moment-adapter.mjs +0 -274
  107. package/fesm2015/nxt-pick-datetime-moment-adapter.mjs.map +0 -1
  108. package/fesm2015/nxt-pick-datetime-native-adapter.mjs +0 -420
  109. package/fesm2015/nxt-pick-datetime-native-adapter.mjs.map +0 -1
  110. package/fesm2015/nxt-pick-datetime.mjs +0 -5014
  111. package/fesm2015/nxt-pick-datetime.mjs.map +0 -1
@@ -4,414 +4,414 @@ import * as i0 from '@angular/core';
4
4
  import { LOCALE_ID, Injectable, Optional, Inject, NgModule } from '@angular/core';
5
5
  import { DateTimeAdapter, NXT_DATE_TIME_FORMATS } from 'nxt-pick-datetime';
6
6
 
7
- /**
8
- * The default month names to use if Intl API is not available.
9
- *
10
- * @internal
11
- */
12
- const DEFAULT_MONTH_NAMES = {
13
- long: [
14
- 'January',
15
- 'February',
16
- 'March',
17
- 'April',
18
- 'May',
19
- 'June',
20
- 'July',
21
- 'August',
22
- 'September',
23
- 'October',
24
- 'November',
25
- 'December'
26
- ],
27
- short: [
28
- 'Jan',
29
- 'Feb',
30
- 'Mar',
31
- 'Apr',
32
- 'May',
33
- 'Jun',
34
- 'Jul',
35
- 'Aug',
36
- 'Sep',
37
- 'Oct',
38
- 'Nov',
39
- 'Dec'
40
- ],
41
- narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D']
42
- };
43
- /**
44
- * The default day of the week names to use if Intl API is not available.
45
- *
46
- * @internal
47
- */
48
- const DEFAULT_DAY_OF_WEEK_NAMES = {
49
- long: [
50
- 'Sunday',
51
- 'Monday',
52
- 'Tuesday',
53
- 'Wednesday',
54
- 'Thursday',
55
- 'Friday',
56
- 'Saturday'
57
- ],
58
- short: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
59
- narrow: ['S', 'M', 'T', 'W', 'T', 'F', 'S']
60
- };
61
- /**
62
- * The default date names to use if Intl API is not available.
63
- *
64
- * @internal
65
- */
66
- const DEFAULT_DATE_NAMES = range(31, i => String(i + 1));
67
- /**
68
- * Whether the browser supports the Intl API.
69
- *
70
- * @internal
71
- */
72
- const SUPPORTS_INTL_API = typeof Intl !== 'undefined';
73
- /**
74
- * Matches strings that have the form of a valid RFC 3339 string
75
- * (https://tools.ietf.org/html/rfc3339). Note that the string may not actually be a valid date
76
- * because the regex will match strings an with out of bounds month, date, etc.
77
- *
78
- * @internal
79
- */
80
- const ISO_8601_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|(?:(?:\+|-)\d{2}:\d{2}))?)?$/;
81
- /**
82
- * Creates an array and fills it with values.
83
- *
84
- * @internal
85
- */
86
- function range(length, valueFunction) {
87
- const valuesArray = Array(length);
88
- for (let i = 0; i < length; i++) {
89
- valuesArray[i] = valueFunction(i);
90
- }
91
- return valuesArray;
92
- }
93
- class NativeDateTimeAdapter extends DateTimeAdapter {
94
- constructor(platform, dateTimeLocale) {
95
- super();
96
- super.setLocale(dateTimeLocale);
97
- // IE does its own time zone correction, so we disable this on IE.
98
- this.useUtcForDisplay = !platform.TRIDENT;
99
- this._clampDate = platform.TRIDENT || platform.EDGE;
100
- }
101
- getYear(date) {
102
- return date.getFullYear();
103
- }
104
- getMonth(date) {
105
- return date.getMonth();
106
- }
107
- getDay(date) {
108
- return date.getDay();
109
- }
110
- getDate(date) {
111
- return date.getDate();
112
- }
113
- getHours(date) {
114
- return date.getHours();
115
- }
116
- getMinutes(date) {
117
- return date.getMinutes();
118
- }
119
- getSeconds(date) {
120
- return date.getSeconds();
121
- }
122
- getTime(date) {
123
- return date.getTime();
124
- }
125
- getNumDaysInMonth(date) {
126
- const lastDateOfMonth = this.createDateWithOverflow(this.getYear(date), this.getMonth(date) + 1, 0);
127
- return this.getDate(lastDateOfMonth);
128
- }
129
- differenceInCalendarDays(dateLeft, dateRight) {
130
- if (this.isValid(dateLeft) && this.isValid(dateRight)) {
131
- const dateLeftStartOfDay = this.createDate(this.getYear(dateLeft), this.getMonth(dateLeft), this.getDate(dateLeft));
132
- const dateRightStartOfDay = this.createDate(this.getYear(dateRight), this.getMonth(dateRight), this.getDate(dateRight));
133
- const timeStampLeft = this.getTime(dateLeftStartOfDay) -
134
- dateLeftStartOfDay.getTimezoneOffset() *
135
- this.milliseondsInMinute;
136
- const timeStampRight = this.getTime(dateRightStartOfDay) -
137
- dateRightStartOfDay.getTimezoneOffset() *
138
- this.milliseondsInMinute;
139
- return Math.round((timeStampLeft - timeStampRight) / this.millisecondsInDay);
140
- }
141
- else {
142
- return undefined;
143
- }
144
- }
145
- getYearName(date) {
146
- if (SUPPORTS_INTL_API) {
147
- const dtf = new Intl.DateTimeFormat(this.locale, {
148
- year: 'numeric',
149
- timeZone: 'utc'
150
- });
151
- return this.stripDirectionalityCharacters(this._format(dtf, date));
152
- }
153
- return String(this.getYear(date));
154
- }
155
- getMonthNames(style) {
156
- if (SUPPORTS_INTL_API) {
157
- const dtf = new Intl.DateTimeFormat(this.locale, {
158
- month: style,
159
- timeZone: 'utc'
160
- });
161
- return range(12, i => this.stripDirectionalityCharacters(this._format(dtf, new Date(2017, i, 1))));
162
- }
163
- return DEFAULT_MONTH_NAMES[style];
164
- }
165
- getDayOfWeekNames(style) {
166
- if (SUPPORTS_INTL_API) {
167
- const dtf = new Intl.DateTimeFormat(this.locale, {
168
- weekday: style,
169
- timeZone: 'utc'
170
- });
171
- return range(7, i => this.stripDirectionalityCharacters(this._format(dtf, new Date(2017, 0, i + 1))));
172
- }
173
- return DEFAULT_DAY_OF_WEEK_NAMES[style];
174
- }
175
- getDateNames() {
176
- if (SUPPORTS_INTL_API) {
177
- const dtf = new Intl.DateTimeFormat(this.locale, {
178
- day: 'numeric',
179
- timeZone: 'utc'
180
- });
181
- return range(31, i => this.stripDirectionalityCharacters(this._format(dtf, new Date(2017, 0, i + 1))));
182
- }
183
- return DEFAULT_DATE_NAMES;
184
- }
185
- toIso8601(date) {
186
- return date.toISOString();
187
- }
188
- isEqual(dateLeft, dateRight) {
189
- if (this.isValid(dateLeft) && this.isValid(dateRight)) {
190
- return dateLeft.getTime() === dateRight.getTime();
191
- }
192
- else {
193
- return false;
194
- }
195
- }
196
- isSameDay(dateLeft, dateRight) {
197
- if (this.isValid(dateLeft) && this.isValid(dateRight)) {
198
- const dateLeftStartOfDay = this.clone(dateLeft);
199
- const dateRightStartOfDay = this.clone(dateRight);
200
- dateLeftStartOfDay.setHours(0, 0, 0, 0);
201
- dateRightStartOfDay.setHours(0, 0, 0, 0);
202
- return (dateLeftStartOfDay.getTime() === dateRightStartOfDay.getTime());
203
- }
204
- else {
205
- return false;
206
- }
207
- }
208
- isValid(date) {
209
- return date && !isNaN(date.getTime());
210
- }
211
- invalid() {
212
- return new Date(NaN);
213
- }
214
- isDateInstance(obj) {
215
- return obj instanceof Date;
216
- }
217
- addCalendarYears(date, amount) {
218
- return this.addCalendarMonths(date, amount * 12);
219
- }
220
- addCalendarMonths(date, amount) {
221
- const result = this.clone(date);
222
- amount = Number(amount);
223
- const desiredMonth = result.getMonth() + amount;
224
- const dateWithDesiredMonth = new Date(0);
225
- dateWithDesiredMonth.setFullYear(result.getFullYear(), desiredMonth, 1);
226
- dateWithDesiredMonth.setHours(0, 0, 0, 0);
227
- const daysInMonth = this.getNumDaysInMonth(dateWithDesiredMonth);
228
- // Set the last day of the new month
229
- // if the original date was the last day of the longer month
230
- result.setMonth(desiredMonth, Math.min(daysInMonth, result.getDate()));
231
- return result;
232
- }
233
- addCalendarDays(date, amount) {
234
- const result = this.clone(date);
235
- amount = Number(amount);
236
- result.setDate(result.getDate() + amount);
237
- return result;
238
- }
239
- setHours(date, amount) {
240
- const result = this.clone(date);
241
- result.setHours(amount);
242
- return result;
243
- }
244
- setMinutes(date, amount) {
245
- const result = this.clone(date);
246
- result.setMinutes(amount);
247
- return result;
248
- }
249
- setSeconds(date, amount) {
250
- const result = this.clone(date);
251
- result.setSeconds(amount);
252
- return result;
253
- }
254
- createDate(year, month, date, hours = 0, minutes = 0, seconds = 0) {
255
- if (month < 0 || month > 11) {
256
- throw Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
257
- }
258
- if (date < 1) {
259
- throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
260
- }
261
- if (hours < 0 || hours > 23) {
262
- throw Error(`Invalid hours "${hours}". Hours has to be between 0 and 23.`);
263
- }
264
- if (minutes < 0 || minutes > 59) {
265
- throw Error(`Invalid minutes "${minutes}". Minutes has to between 0 and 59.`);
266
- }
267
- if (seconds < 0 || seconds > 59) {
268
- throw Error(`Invalid seconds "${seconds}". Seconds has to be between 0 and 59.`);
269
- }
270
- const result = this.createDateWithOverflow(year, month, date, hours, minutes, seconds);
271
- // Check that the date wasn't above the upper bound for the month, causing the month to overflow
272
- // For example, createDate(2017, 1, 31) would try to create a date 2017/02/31 which is invalid
273
- if (result.getMonth() !== month) {
274
- throw Error(`Invalid date "${date}" for month with index "${month}".`);
275
- }
276
- return result;
277
- }
278
- clone(date) {
279
- return this.createDate(this.getYear(date), this.getMonth(date), this.getDate(date), this.getHours(date), this.getMinutes(date), this.getSeconds(date));
280
- }
281
- now() {
282
- return new Date();
283
- }
284
- format(date, displayFormat) {
285
- if (!this.isValid(date)) {
286
- throw Error('JSNativeDate: Cannot format invalid date.');
287
- }
288
- if (SUPPORTS_INTL_API) {
289
- if (this._clampDate &&
290
- (date.getFullYear() < 1 || date.getFullYear() > 9999)) {
291
- date = this.clone(date);
292
- date.setFullYear(Math.max(1, Math.min(9999, date.getFullYear())));
293
- }
294
- displayFormat = { ...displayFormat, timeZone: 'utc' };
295
- const dtf = new Intl.DateTimeFormat(this.locale, displayFormat);
296
- return this.stripDirectionalityCharacters(this._format(dtf, date));
297
- }
298
- return this.stripDirectionalityCharacters(date.toDateString());
299
- }
300
- parse(value, _parseFormat) {
301
- // There is no way using the native JS Date to set the parse format or locale
302
- if (typeof value === 'number') {
303
- return new Date(value);
304
- }
305
- return value ? new Date(Date.parse(value)) : undefined;
306
- }
307
- /**
308
- * Returns the given value if given a valid Date or undefined. Deserializes valid ISO 8601 strings
309
- * (https://www.ietf.org/rfc/rfc3339.txt) into valid Dates and empty string into undefined. Returns an
310
- * invalid date for all other values.
311
- */
312
- deserialize(value) {
313
- if (typeof value === 'string') {
314
- if (!value) {
315
- return undefined;
316
- }
317
- // The `Date` constructor accepts formats other than ISO 8601, so we need to make sure the
318
- // string is the right format first.
319
- if (ISO_8601_REGEX.test(value)) {
320
- const date = new Date(value);
321
- if (this.isValid(date)) {
322
- return date;
323
- }
324
- }
325
- }
326
- return super.deserialize(value);
327
- }
328
- /**
329
- * Creates a date but allows the month and date to overflow.
330
- */
331
- createDateWithOverflow(year, month, date, hours = 0, minutes = 0, seconds = 0) {
332
- const result = new Date(year, month, date, hours, minutes, seconds);
333
- if (year >= 0 && year < 100) {
334
- result.setFullYear(this.getYear(result) - 1900);
335
- }
336
- return result;
337
- }
338
- /**
339
- * Strip out unicode LTR and RTL characters. Edge and IE insert these into formatted dates while
340
- * other browsers do not. We remove them to make output consistent and because they interfere with
341
- * date parsing.
342
- */
343
- stripDirectionalityCharacters(str) {
344
- return str.replace(/[\u200e\u200f]/g, '');
345
- }
346
- /**
347
- * When converting Date object to string, javascript built-in functions may return wrong
348
- * results because it applies its internal DST rules. The DST rules around the world change
349
- * very frequently, and the current valid rule is not always valid in previous years though.
350
- * We work around this problem building a new Date object which has its internal UTC
351
- * representation with the local date and time.
352
- */
353
- _format(dtf, date) {
354
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
355
- return dtf.format(d);
356
- }
357
- }
358
- NativeDateTimeAdapter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NativeDateTimeAdapter, deps: [{ token: i1.Platform }, { token: LOCALE_ID, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
359
- NativeDateTimeAdapter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NativeDateTimeAdapter });
360
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NativeDateTimeAdapter, decorators: [{
361
- type: Injectable
362
- }], ctorParameters: function () { return [{ type: i1.Platform }, { type: undefined, decorators: [{
363
- type: Optional
364
- }, {
365
- type: Inject,
366
- args: [LOCALE_ID]
7
+ /**
8
+ * The default month names to use if Intl API is not available.
9
+ *
10
+ * @internal
11
+ */
12
+ const DEFAULT_MONTH_NAMES = {
13
+ long: [
14
+ 'January',
15
+ 'February',
16
+ 'March',
17
+ 'April',
18
+ 'May',
19
+ 'June',
20
+ 'July',
21
+ 'August',
22
+ 'September',
23
+ 'October',
24
+ 'November',
25
+ 'December'
26
+ ],
27
+ short: [
28
+ 'Jan',
29
+ 'Feb',
30
+ 'Mar',
31
+ 'Apr',
32
+ 'May',
33
+ 'Jun',
34
+ 'Jul',
35
+ 'Aug',
36
+ 'Sep',
37
+ 'Oct',
38
+ 'Nov',
39
+ 'Dec'
40
+ ],
41
+ narrow: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D']
42
+ };
43
+ /**
44
+ * The default day of the week names to use if Intl API is not available.
45
+ *
46
+ * @internal
47
+ */
48
+ const DEFAULT_DAY_OF_WEEK_NAMES = {
49
+ long: [
50
+ 'Sunday',
51
+ 'Monday',
52
+ 'Tuesday',
53
+ 'Wednesday',
54
+ 'Thursday',
55
+ 'Friday',
56
+ 'Saturday'
57
+ ],
58
+ short: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
59
+ narrow: ['S', 'M', 'T', 'W', 'T', 'F', 'S']
60
+ };
61
+ /**
62
+ * The default date names to use if Intl API is not available.
63
+ *
64
+ * @internal
65
+ */
66
+ const DEFAULT_DATE_NAMES = range(31, i => String(i + 1));
67
+ /**
68
+ * Whether the browser supports the Intl API.
69
+ *
70
+ * @internal
71
+ */
72
+ const SUPPORTS_INTL_API = typeof Intl !== 'undefined';
73
+ /**
74
+ * Matches strings that have the form of a valid RFC 3339 string
75
+ * (https://tools.ietf.org/html/rfc3339). Note that the string may not actually be a valid date
76
+ * because the regex will match strings an with out of bounds month, date, etc.
77
+ *
78
+ * @internal
79
+ */
80
+ const ISO_8601_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|(?:(?:\+|-)\d{2}:\d{2}))?)?$/;
81
+ /**
82
+ * Creates an array and fills it with values.
83
+ *
84
+ * @internal
85
+ */
86
+ function range(length, valueFunction) {
87
+ const valuesArray = Array(length);
88
+ for (let i = 0; i < length; i++) {
89
+ valuesArray[i] = valueFunction(i);
90
+ }
91
+ return valuesArray;
92
+ }
93
+ class NativeDateTimeAdapter extends DateTimeAdapter {
94
+ constructor(platform, dateTimeLocale) {
95
+ super();
96
+ super.setLocale(dateTimeLocale);
97
+ // IE does its own time zone correction, so we disable this on IE.
98
+ this.useUtcForDisplay = !platform.TRIDENT;
99
+ this._clampDate = platform.TRIDENT || platform.EDGE;
100
+ }
101
+ getYear(date) {
102
+ return date.getFullYear();
103
+ }
104
+ getMonth(date) {
105
+ return date.getMonth();
106
+ }
107
+ getDay(date) {
108
+ return date.getDay();
109
+ }
110
+ getDate(date) {
111
+ return date.getDate();
112
+ }
113
+ getHours(date) {
114
+ return date.getHours();
115
+ }
116
+ getMinutes(date) {
117
+ return date.getMinutes();
118
+ }
119
+ getSeconds(date) {
120
+ return date.getSeconds();
121
+ }
122
+ getTime(date) {
123
+ return date.getTime();
124
+ }
125
+ getNumDaysInMonth(date) {
126
+ const lastDateOfMonth = this.createDateWithOverflow(this.getYear(date), this.getMonth(date) + 1, 0);
127
+ return this.getDate(lastDateOfMonth);
128
+ }
129
+ differenceInCalendarDays(dateLeft, dateRight) {
130
+ if (this.isValid(dateLeft) && this.isValid(dateRight)) {
131
+ const dateLeftStartOfDay = this.createDate(this.getYear(dateLeft), this.getMonth(dateLeft), this.getDate(dateLeft));
132
+ const dateRightStartOfDay = this.createDate(this.getYear(dateRight), this.getMonth(dateRight), this.getDate(dateRight));
133
+ const timeStampLeft = this.getTime(dateLeftStartOfDay) -
134
+ dateLeftStartOfDay.getTimezoneOffset() *
135
+ this.milliseondsInMinute;
136
+ const timeStampRight = this.getTime(dateRightStartOfDay) -
137
+ dateRightStartOfDay.getTimezoneOffset() *
138
+ this.milliseondsInMinute;
139
+ return Math.round((timeStampLeft - timeStampRight) / this.millisecondsInDay);
140
+ }
141
+ else {
142
+ return undefined;
143
+ }
144
+ }
145
+ getYearName(date) {
146
+ if (SUPPORTS_INTL_API) {
147
+ const dtf = new Intl.DateTimeFormat(this.locale, {
148
+ year: 'numeric',
149
+ timeZone: 'utc'
150
+ });
151
+ return this.stripDirectionalityCharacters(this._format(dtf, date));
152
+ }
153
+ return String(this.getYear(date));
154
+ }
155
+ getMonthNames(style) {
156
+ if (SUPPORTS_INTL_API) {
157
+ const dtf = new Intl.DateTimeFormat(this.locale, {
158
+ month: style,
159
+ timeZone: 'utc'
160
+ });
161
+ return range(12, i => this.stripDirectionalityCharacters(this._format(dtf, new Date(2017, i, 1))));
162
+ }
163
+ return DEFAULT_MONTH_NAMES[style];
164
+ }
165
+ getDayOfWeekNames(style) {
166
+ if (SUPPORTS_INTL_API) {
167
+ const dtf = new Intl.DateTimeFormat(this.locale, {
168
+ weekday: style,
169
+ timeZone: 'utc'
170
+ });
171
+ return range(7, i => this.stripDirectionalityCharacters(this._format(dtf, new Date(2017, 0, i + 1))));
172
+ }
173
+ return DEFAULT_DAY_OF_WEEK_NAMES[style];
174
+ }
175
+ getDateNames() {
176
+ if (SUPPORTS_INTL_API) {
177
+ const dtf = new Intl.DateTimeFormat(this.locale, {
178
+ day: 'numeric',
179
+ timeZone: 'utc'
180
+ });
181
+ return range(31, i => this.stripDirectionalityCharacters(this._format(dtf, new Date(2017, 0, i + 1))));
182
+ }
183
+ return DEFAULT_DATE_NAMES;
184
+ }
185
+ toIso8601(date) {
186
+ return date.toISOString();
187
+ }
188
+ isEqual(dateLeft, dateRight) {
189
+ if (this.isValid(dateLeft) && this.isValid(dateRight)) {
190
+ return dateLeft.getTime() === dateRight.getTime();
191
+ }
192
+ else {
193
+ return false;
194
+ }
195
+ }
196
+ isSameDay(dateLeft, dateRight) {
197
+ if (this.isValid(dateLeft) && this.isValid(dateRight)) {
198
+ const dateLeftStartOfDay = this.clone(dateLeft);
199
+ const dateRightStartOfDay = this.clone(dateRight);
200
+ dateLeftStartOfDay.setHours(0, 0, 0, 0);
201
+ dateRightStartOfDay.setHours(0, 0, 0, 0);
202
+ return (dateLeftStartOfDay.getTime() === dateRightStartOfDay.getTime());
203
+ }
204
+ else {
205
+ return false;
206
+ }
207
+ }
208
+ isValid(date) {
209
+ return date && !isNaN(date.getTime());
210
+ }
211
+ invalid() {
212
+ return new Date(NaN);
213
+ }
214
+ isDateInstance(obj) {
215
+ return obj instanceof Date;
216
+ }
217
+ addCalendarYears(date, amount) {
218
+ return this.addCalendarMonths(date, amount * 12);
219
+ }
220
+ addCalendarMonths(date, amount) {
221
+ const result = this.clone(date);
222
+ amount = Number(amount);
223
+ const desiredMonth = result.getMonth() + amount;
224
+ const dateWithDesiredMonth = new Date(0);
225
+ dateWithDesiredMonth.setFullYear(result.getFullYear(), desiredMonth, 1);
226
+ dateWithDesiredMonth.setHours(0, 0, 0, 0);
227
+ const daysInMonth = this.getNumDaysInMonth(dateWithDesiredMonth);
228
+ // Set the last day of the new month
229
+ // if the original date was the last day of the longer month
230
+ result.setMonth(desiredMonth, Math.min(daysInMonth, result.getDate()));
231
+ return result;
232
+ }
233
+ addCalendarDays(date, amount) {
234
+ const result = this.clone(date);
235
+ amount = Number(amount);
236
+ result.setDate(result.getDate() + amount);
237
+ return result;
238
+ }
239
+ setHours(date, amount) {
240
+ const result = this.clone(date);
241
+ result.setHours(amount);
242
+ return result;
243
+ }
244
+ setMinutes(date, amount) {
245
+ const result = this.clone(date);
246
+ result.setMinutes(amount);
247
+ return result;
248
+ }
249
+ setSeconds(date, amount) {
250
+ const result = this.clone(date);
251
+ result.setSeconds(amount);
252
+ return result;
253
+ }
254
+ createDate(year, month, date, hours = 0, minutes = 0, seconds = 0) {
255
+ if (month < 0 || month > 11) {
256
+ throw Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
257
+ }
258
+ if (date < 1) {
259
+ throw Error(`Invalid date "${date}". Date has to be greater than 0.`);
260
+ }
261
+ if (hours < 0 || hours > 23) {
262
+ throw Error(`Invalid hours "${hours}". Hours has to be between 0 and 23.`);
263
+ }
264
+ if (minutes < 0 || minutes > 59) {
265
+ throw Error(`Invalid minutes "${minutes}". Minutes has to between 0 and 59.`);
266
+ }
267
+ if (seconds < 0 || seconds > 59) {
268
+ throw Error(`Invalid seconds "${seconds}". Seconds has to be between 0 and 59.`);
269
+ }
270
+ const result = this.createDateWithOverflow(year, month, date, hours, minutes, seconds);
271
+ // Check that the date wasn't above the upper bound for the month, causing the month to overflow
272
+ // For example, createDate(2017, 1, 31) would try to create a date 2017/02/31 which is invalid
273
+ if (result.getMonth() !== month) {
274
+ throw Error(`Invalid date "${date}" for month with index "${month}".`);
275
+ }
276
+ return result;
277
+ }
278
+ clone(date) {
279
+ return this.createDate(this.getYear(date), this.getMonth(date), this.getDate(date), this.getHours(date), this.getMinutes(date), this.getSeconds(date));
280
+ }
281
+ now() {
282
+ return new Date();
283
+ }
284
+ format(date, displayFormat) {
285
+ if (!this.isValid(date)) {
286
+ throw Error('JSNativeDate: Cannot format invalid date.');
287
+ }
288
+ if (SUPPORTS_INTL_API) {
289
+ if (this._clampDate &&
290
+ (date.getFullYear() < 1 || date.getFullYear() > 9999)) {
291
+ date = this.clone(date);
292
+ date.setFullYear(Math.max(1, Math.min(9999, date.getFullYear())));
293
+ }
294
+ displayFormat = { ...displayFormat, timeZone: 'utc' };
295
+ const dtf = new Intl.DateTimeFormat(this.locale, displayFormat);
296
+ return this.stripDirectionalityCharacters(this._format(dtf, date));
297
+ }
298
+ return this.stripDirectionalityCharacters(date.toDateString());
299
+ }
300
+ parse(value, _parseFormat) {
301
+ // There is no way using the native JS Date to set the parse format or locale
302
+ if (typeof value === 'number') {
303
+ return new Date(value);
304
+ }
305
+ return value ? new Date(Date.parse(value)) : undefined;
306
+ }
307
+ /**
308
+ * Returns the given value if given a valid Date or undefined. Deserializes valid ISO 8601 strings
309
+ * (https://www.ietf.org/rfc/rfc3339.txt) into valid Dates and empty string into undefined. Returns an
310
+ * invalid date for all other values.
311
+ */
312
+ deserialize(value) {
313
+ if (typeof value === 'string') {
314
+ if (!value) {
315
+ return undefined;
316
+ }
317
+ // The `Date` constructor accepts formats other than ISO 8601, so we need to make sure the
318
+ // string is the right format first.
319
+ if (ISO_8601_REGEX.test(value)) {
320
+ const date = new Date(value);
321
+ if (this.isValid(date)) {
322
+ return date;
323
+ }
324
+ }
325
+ }
326
+ return super.deserialize(value);
327
+ }
328
+ /**
329
+ * Creates a date but allows the month and date to overflow.
330
+ */
331
+ createDateWithOverflow(year, month, date, hours = 0, minutes = 0, seconds = 0) {
332
+ const result = new Date(year, month, date, hours, minutes, seconds);
333
+ if (year >= 0 && year < 100) {
334
+ result.setFullYear(this.getYear(result) - 1900);
335
+ }
336
+ return result;
337
+ }
338
+ /**
339
+ * Strip out unicode LTR and RTL characters. Edge and IE insert these into formatted dates while
340
+ * other browsers do not. We remove them to make output consistent and because they interfere with
341
+ * date parsing.
342
+ */
343
+ stripDirectionalityCharacters(str) {
344
+ return str.replace(/[\u200e\u200f]/g, '');
345
+ }
346
+ /**
347
+ * When converting Date object to string, javascript built-in functions may return wrong
348
+ * results because it applies its internal DST rules. The DST rules around the world change
349
+ * very frequently, and the current valid rule is not always valid in previous years though.
350
+ * We work around this problem building a new Date object which has its internal UTC
351
+ * representation with the local date and time.
352
+ */
353
+ _format(dtf, date) {
354
+ const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
355
+ return dtf.format(d);
356
+ }
357
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NativeDateTimeAdapter, deps: [{ token: i1.Platform }, { token: LOCALE_ID, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
358
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NativeDateTimeAdapter }); }
359
+ }
360
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NativeDateTimeAdapter, decorators: [{
361
+ type: Injectable
362
+ }], ctorParameters: function () { return [{ type: i1.Platform }, { type: undefined, decorators: [{
363
+ type: Optional
364
+ }, {
365
+ type: Inject,
366
+ args: [LOCALE_ID]
367
367
  }] }]; } });
368
368
 
369
- /**
370
- * @internal
371
- */
372
- const NXT_NATIVE_DATE_TIME_FORMATS = {
373
- parseInput: null,
374
- fullPickerInput: { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric' },
375
- datePickerInput: { year: 'numeric', month: 'numeric', day: 'numeric' },
376
- timePickerInput: { hour: 'numeric', minute: 'numeric' },
377
- monthYearLabel: { year: 'numeric', month: 'short' },
378
- dateA11yLabel: { year: 'numeric', month: 'long', day: 'numeric' },
379
- monthYearA11yLabel: { year: 'numeric', month: 'long' }
369
+ /**
370
+ * @internal
371
+ */
372
+ const NXT_NATIVE_DATE_TIME_FORMATS = {
373
+ parseInput: null,
374
+ fullPickerInput: { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric' },
375
+ datePickerInput: { year: 'numeric', month: 'numeric', day: 'numeric' },
376
+ timePickerInput: { hour: 'numeric', minute: 'numeric' },
377
+ monthYearLabel: { year: 'numeric', month: 'short' },
378
+ dateA11yLabel: { year: 'numeric', month: 'long', day: 'numeric' },
379
+ monthYearA11yLabel: { year: 'numeric', month: 'long' }
380
380
  };
381
381
 
382
- class NativeDateTimeModule {
383
- }
384
- NativeDateTimeModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NativeDateTimeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
385
- NativeDateTimeModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.4", ngImport: i0, type: NativeDateTimeModule, imports: [PlatformModule] });
386
- NativeDateTimeModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NativeDateTimeModule, providers: [
387
- {
388
- provide: DateTimeAdapter,
389
- useClass: NativeDateTimeAdapter
390
- },
391
- {
392
- provide: NXT_DATE_TIME_FORMATS,
393
- useValue: NXT_NATIVE_DATE_TIME_FORMATS
394
- }
395
- ], imports: [PlatformModule] });
396
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NativeDateTimeModule, decorators: [{
397
- type: NgModule,
398
- args: [{
399
- imports: [PlatformModule],
400
- providers: [
401
- {
402
- provide: DateTimeAdapter,
403
- useClass: NativeDateTimeAdapter
404
- },
405
- {
406
- provide: NXT_DATE_TIME_FORMATS,
407
- useValue: NXT_NATIVE_DATE_TIME_FORMATS
408
- }
409
- ]
410
- }]
382
+ class NativeDateTimeModule {
383
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NativeDateTimeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
384
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.0.0", ngImport: i0, type: NativeDateTimeModule, imports: [PlatformModule] }); }
385
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NativeDateTimeModule, providers: [
386
+ {
387
+ provide: DateTimeAdapter,
388
+ useClass: NativeDateTimeAdapter
389
+ },
390
+ {
391
+ provide: NXT_DATE_TIME_FORMATS,
392
+ useValue: NXT_NATIVE_DATE_TIME_FORMATS
393
+ }
394
+ ], imports: [PlatformModule] }); }
395
+ }
396
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: NativeDateTimeModule, decorators: [{
397
+ type: NgModule,
398
+ args: [{
399
+ imports: [PlatformModule],
400
+ providers: [
401
+ {
402
+ provide: DateTimeAdapter,
403
+ useClass: NativeDateTimeAdapter
404
+ },
405
+ {
406
+ provide: NXT_DATE_TIME_FORMATS,
407
+ useValue: NXT_NATIVE_DATE_TIME_FORMATS
408
+ }
409
+ ]
410
+ }]
411
411
  }] });
412
412
 
413
- /**
414
- * Generated bundle index. Do not edit.
413
+ /**
414
+ * Generated bundle index. Do not edit.
415
415
  */
416
416
 
417
417
  export { NativeDateTimeModule };