@progress/kendo-dateinputs-common 0.1.0 → 0.2.0-dev.202301061353

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 (55) hide show
  1. package/README.md +34 -3
  2. package/dist/cdn/js/kendo-dateinputs-common.js +1 -0
  3. package/dist/cdn/main.js +1 -1
  4. package/dist/es/common/constants.js +6 -0
  5. package/dist/es/common/dateobject.js +1159 -0
  6. package/dist/es/common/key.js +16 -0
  7. package/dist/es/common/keycode.js +16 -0
  8. package/dist/es/common/mask.js +8 -0
  9. package/dist/es/common/observable.js +32 -0
  10. package/dist/es/common/utils.js +128 -0
  11. package/dist/es/dateinput/dateinput.js +1011 -0
  12. package/dist/es/dateinput/interaction-mode.js +6 -0
  13. package/dist/es/dateinput/utils.js +93 -0
  14. package/dist/es/main.js +1 -1
  15. package/dist/es2015/common/constants.js +6 -0
  16. package/dist/es2015/common/dateobject.js +1137 -0
  17. package/dist/es2015/common/key.js +16 -0
  18. package/dist/es2015/common/keycode.js +16 -0
  19. package/dist/es2015/common/mask.js +6 -0
  20. package/dist/es2015/common/observable.js +29 -0
  21. package/dist/es2015/common/utils.js +117 -0
  22. package/dist/es2015/dateinput/dateinput.js +969 -0
  23. package/dist/es2015/dateinput/interaction-mode.js +6 -0
  24. package/dist/es2015/dateinput/utils.js +92 -0
  25. package/dist/es2015/main.js +1 -1
  26. package/dist/npm/common/constants.d.ts +6 -0
  27. package/dist/npm/common/constants.js +8 -0
  28. package/dist/npm/common/dateobject.d.ts +172 -0
  29. package/dist/npm/common/dateobject.js +1161 -0
  30. package/dist/npm/common/key.d.ts +16 -0
  31. package/dist/npm/common/key.js +18 -0
  32. package/dist/npm/common/keycode.d.ts +16 -0
  33. package/dist/npm/common/keycode.js +18 -0
  34. package/dist/npm/common/mask.d.ts +4 -0
  35. package/dist/npm/common/mask.js +10 -0
  36. package/dist/npm/common/observable.d.ts +9 -0
  37. package/dist/npm/common/observable.js +34 -0
  38. package/dist/npm/common/utils.d.ts +60 -0
  39. package/dist/npm/common/utils.js +130 -0
  40. package/dist/npm/dateinput/dateinput.d.ts +204 -0
  41. package/dist/npm/dateinput/dateinput.js +1013 -0
  42. package/dist/npm/dateinput/interaction-mode.d.ts +5 -0
  43. package/dist/npm/dateinput/interaction-mode.js +8 -0
  44. package/dist/npm/dateinput/utils.d.ts +27 -0
  45. package/dist/npm/dateinput/utils.js +95 -0
  46. package/dist/npm/main.d.ts +1 -1
  47. package/dist/npm/main.js +2 -2
  48. package/dist/systemjs/kendo-dateinputs-common.js +1 -0
  49. package/package.json +10 -8
  50. package/dist/cdn/js/kendo-typescript-package-base.js +0 -1
  51. package/dist/es/my-class.js +0 -15
  52. package/dist/es2015/my-class.js +0 -11
  53. package/dist/npm/my-class.d.ts +0 -9
  54. package/dist/npm/my-class.js +0 -17
  55. package/dist/systemjs/kendo-typescript-package-base.js +0 -1
@@ -0,0 +1,1159 @@
1
+ import { addMonths, cloneDate, createDate, isEqual, getDate, lastDayOfMonth } from '@progress/kendo-date-math';
2
+ import { Mask } from './mask';
3
+ import { dateSymbolMap, padZero, unpadZero } from '../dateinput/utils';
4
+ import { extend, isPresent, cropTwoDigitYear, setYears, parseToInt, clamp, areDatePartsEqualTo, isNumber } from './utils';
5
+ import { Constants } from './constants';
6
+ var PREVIOUS_CENTURY_BASE = 1900;
7
+ var CURRENT_CENTURY_BASE = 2000;
8
+ var SHORT_PATTERN_LENGTH_REGEXP = /d|M|H|h|m|s/;
9
+ var MONTH_PART_WITH_WORDS_THRESHOLD = 2;
10
+ var MONTH_SYMBOL = "M";
11
+ // JS months start from 0 (January) instead of 1 (January)
12
+ var JS_MONTH_OFFSET = 1;
13
+ var DateObject = /** @class */ (function () {
14
+ function DateObject(_a) {
15
+ var intlService = _a.intlService, formatPlaceholder = _a.formatPlaceholder, format = _a.format, _b = _a.cycleTime, cycleTime = _b === void 0 ? false : _b, _c = _a.twoDigitYearMax, twoDigitYearMax = _c === void 0 ? Constants.twoDigitYearMax : _c, _d = _a.value, value = _d === void 0 ? null : _d, _e = _a.autoCorrectParts, autoCorrectParts = _e === void 0 ? true : _e;
16
+ this.year = true;
17
+ this.month = true;
18
+ this.date = true;
19
+ this.hours = true;
20
+ this.minutes = true;
21
+ this.seconds = true;
22
+ this.milliseconds = true;
23
+ this.leadingZero = null;
24
+ this.typedMonthPart = '';
25
+ this.knownParts = 'adHhmMsEyS';
26
+ this.symbols = {
27
+ 'E': 'E',
28
+ 'H': 'H',
29
+ 'M': 'M',
30
+ 'a': 'a',
31
+ 'd': 'd',
32
+ 'h': 'h',
33
+ 'm': 'm',
34
+ 's': 's',
35
+ 'y': 'y',
36
+ 'S': 'S'
37
+ };
38
+ this._value = getDate(new Date());
39
+ this.cycleTime = false;
40
+ this._partiallyInvalidDate = {
41
+ startDate: null,
42
+ invalidDateParts: {
43
+ 'E': { value: null, date: null, startDateOffset: 0 },
44
+ 'H': { value: null, date: null, startDateOffset: 0 },
45
+ 'M': { value: null, date: null, startDateOffset: 0 },
46
+ 'a': { value: null, date: null, startDateOffset: 0 },
47
+ 'd': { value: null, date: null, startDateOffset: 0 },
48
+ 'h': { value: null, date: null, startDateOffset: 0 },
49
+ 'm': { value: null, date: null, startDateOffset: 0 },
50
+ 's': { value: null, date: null, startDateOffset: 0 },
51
+ 'y': { value: null, date: null, startDateOffset: 0 },
52
+ 'S': { value: null, date: null, startDateOffset: 0 }
53
+ }
54
+ };
55
+ this.intl = intlService;
56
+ this.formatPlaceholder = formatPlaceholder || 'wide';
57
+ this.format = format;
58
+ this.cycleTime = cycleTime;
59
+ this.monthNames = this.allFormattedMonths(this.localeId);
60
+ this.dayPeriods = this.allDayPeriods(this.localeId);
61
+ this.twoDigitYearMax = twoDigitYearMax;
62
+ this.autoCorrectParts = autoCorrectParts;
63
+ if (!value) {
64
+ this._value = getDate(new Date());
65
+ var sampleFormat = this.dateFormatString(this.value, this.format).symbols;
66
+ for (var i = 0; i < sampleFormat.length; i++) {
67
+ this.setExisting(sampleFormat[i], false);
68
+ }
69
+ }
70
+ else {
71
+ this._value = cloneDate(value);
72
+ }
73
+ }
74
+ Object.defineProperty(DateObject.prototype, "value", {
75
+ get: function () {
76
+ return this._value;
77
+ },
78
+ set: function (value) {
79
+ if (value && !(value instanceof Date)) {
80
+ // throw new Error("The 'value' should be a valid JavaScript Date instance.");
81
+ return;
82
+ }
83
+ this._value = value;
84
+ this.resetInvalidDate();
85
+ },
86
+ enumerable: true,
87
+ configurable: true
88
+ });
89
+ Object.defineProperty(DateObject.prototype, "localeId", {
90
+ get: function () {
91
+ var localeId = Constants.defaultLocaleId;
92
+ var cldrKeys = Object.keys(this.intl.cldr);
93
+ for (var i = 0; i < cldrKeys.length; i++) {
94
+ var key = cldrKeys[i];
95
+ var value = this.intl.cldr[key];
96
+ if (value.name && value.calendar && value.numbers &&
97
+ value.name !== Constants.defaultLocaleId) {
98
+ localeId = value.name;
99
+ break;
100
+ }
101
+ }
102
+ return localeId;
103
+ },
104
+ enumerable: true,
105
+ configurable: true
106
+ });
107
+ DateObject.prototype.setValue = function (value) {
108
+ if (!value) {
109
+ this._value = getDate(new Date());
110
+ this.modifyExisting(false);
111
+ }
112
+ else if (!isEqual(value, this._value)) {
113
+ this._value = cloneDate(value);
114
+ this.modifyExisting(true);
115
+ }
116
+ this.resetInvalidDate();
117
+ };
118
+ /**
119
+ * @hidden
120
+ */
121
+ DateObject.prototype.hasValue = function () {
122
+ var _this = this;
123
+ var pred = function (a, p) { return a || p.type !== 'literal' && p.type !== 'dayperiod' && _this.getExisting(p.pattern[0]); };
124
+ return this.intl.splitDateFormat(this.format, this.localeId).reduce(pred, false);
125
+ };
126
+ /**
127
+ * @hidden
128
+ */
129
+ DateObject.prototype.getValue = function () {
130
+ for (var i = 0; i < this.knownParts.length; i++) {
131
+ if (!this.getExisting(this.knownParts[i])) {
132
+ return null;
133
+ }
134
+ }
135
+ return cloneDate(this.value);
136
+ };
137
+ /**
138
+ * @hidden
139
+ */
140
+ DateObject.prototype.getFormattedDate = function (format) {
141
+ return this.intl.formatDate(this.getValue(), format, this.localeId);
142
+ };
143
+ /**
144
+ * @hidden
145
+ */
146
+ DateObject.prototype.getTextAndFormat = function (customFormat) {
147
+ if (customFormat === void 0) { customFormat = ""; }
148
+ var format = customFormat || this.format;
149
+ var text = this.intl.formatDate(this.value, format, this.localeId);
150
+ var mask = this.dateFormatString(this.value, format);
151
+ if (!this.autoCorrectParts && this._partiallyInvalidDate.startDate) {
152
+ var partiallyInvalidText = "";
153
+ var formattedDate = this.intl.formatDate(this.value, format, this.localeId);
154
+ var formattedDates = this.getFormattedInvalidDates(format);
155
+ for (var i = 0; i < formattedDate.length; i++) {
156
+ var symbol = mask.symbols[i];
157
+ if (mask.partMap[i].type === "literal") {
158
+ partiallyInvalidText += text[i];
159
+ }
160
+ else if (this.getInvalidDatePartValue(symbol)) {
161
+ if (symbol === "M") {
162
+ if (mask.partMap[i].pattern.length > MONTH_PART_WITH_WORDS_THRESHOLD) {
163
+ partiallyInvalidText += formattedDates[symbol][i];
164
+ }
165
+ else {
166
+ if (this.getInvalidDatePartValue(symbol)) {
167
+ var month = parseToInt(this.getInvalidDatePartValue(symbol) + JS_MONTH_OFFSET).toString();
168
+ var formattedMonth = padZero(Math.abs(mask.partMap[i].pattern.length - month.length)) + month;
169
+ partiallyInvalidText += formattedMonth;
170
+ i += Math.max(0, formattedMonth.length - 1);
171
+ }
172
+ else {
173
+ partiallyInvalidText += formattedDates[symbol][i];
174
+ }
175
+ }
176
+ }
177
+ else {
178
+ if (this.getInvalidDatePartValue(symbol)) {
179
+ partiallyInvalidText += this.getInvalidDatePartValue(symbol);
180
+ i += Math.max(0, this.getInvalidDatePartValue(symbol).toString().length - 1);
181
+ }
182
+ else {
183
+ partiallyInvalidText += formattedDates[symbol][i];
184
+ }
185
+ }
186
+ }
187
+ else {
188
+ partiallyInvalidText += text[i];
189
+ }
190
+ }
191
+ text = partiallyInvalidText;
192
+ }
193
+ var result = this.merge(text, mask);
194
+ return result;
195
+ };
196
+ /**
197
+ * @hidden
198
+ */
199
+ DateObject.prototype.getFormattedInvalidDates = function (customFormat) {
200
+ var _this = this;
201
+ if (customFormat === void 0) { customFormat = ""; }
202
+ var format = customFormat || this.format;
203
+ var formattedDatesForSymbol = {
204
+ 'E': '',
205
+ 'H': '',
206
+ 'M': '',
207
+ 'a': '',
208
+ 'd': '',
209
+ 'h': '',
210
+ 'm': '',
211
+ 's': '',
212
+ 'y': '',
213
+ 'S': ''
214
+ };
215
+ Object.keys(this._partiallyInvalidDate.invalidDateParts).forEach(function (key) {
216
+ var date = _this.getInvalidDatePart(key).date;
217
+ if (date) {
218
+ var formattedInvalidDate = _this.intl.formatDate(date, format, _this.localeId);
219
+ formattedDatesForSymbol[key] = formattedInvalidDate;
220
+ }
221
+ });
222
+ return formattedDatesForSymbol;
223
+ };
224
+ DateObject.prototype.modifyExisting = function (value) {
225
+ var sampleFormat = this.dateFormatString(this.value, this.format).symbols;
226
+ for (var i = 0; i < sampleFormat.length; i++) {
227
+ this.setExisting(sampleFormat[i], value);
228
+ }
229
+ };
230
+ /**
231
+ * @hidden
232
+ */
233
+ DateObject.prototype.getExisting = function (symbol) {
234
+ switch (symbol) {
235
+ case 'y': return this.year;
236
+ case 'M':
237
+ case 'L': return this.month;
238
+ case 'd': return this.date;
239
+ case 'E': return this.date && this.month && this.year;
240
+ case 'h':
241
+ case 'H': return this.hours;
242
+ case 'm': return this.minutes;
243
+ case 's': return this.seconds;
244
+ case "S": return this.milliseconds;
245
+ default:
246
+ return true;
247
+ }
248
+ };
249
+ DateObject.prototype.setExisting = function (symbol, value) {
250
+ switch (symbol) {
251
+ case 'y':
252
+ // allow 2/29 dates
253
+ this.year = value;
254
+ if (value === false) {
255
+ this._value.setFullYear(2000);
256
+ }
257
+ break;
258
+ case 'M':
259
+ // make sure you can type 31 in the day part
260
+ this.month = value;
261
+ if (value === false) {
262
+ if (this.autoCorrectParts) {
263
+ this._value.setMonth(0);
264
+ }
265
+ }
266
+ break;
267
+ case 'd':
268
+ this.date = value;
269
+ break;
270
+ case 'h':
271
+ case 'H':
272
+ this.hours = value;
273
+ break;
274
+ case 'm':
275
+ this.minutes = value;
276
+ break;
277
+ case 's':
278
+ this.seconds = value;
279
+ break;
280
+ case "S":
281
+ this.milliseconds = value;
282
+ break;
283
+ default:
284
+ break;
285
+ }
286
+ if (this.getValue()) {
287
+ this.resetInvalidDate();
288
+ }
289
+ };
290
+ DateObject.prototype.modifyPart = function (symbol, offset) {
291
+ var newValue = cloneDate(this.value);
292
+ var originalValue = cloneDate(this.value);
293
+ var timeModified = false;
294
+ var invalidDateFound;
295
+ var currentInvalidDatePartValue = 0;
296
+ if (!this.autoCorrectParts) {
297
+ var isMonth = symbol === "M";
298
+ var isDay = symbol === "d" || symbol === "E";
299
+ var invalidDateParts = this._partiallyInvalidDate.invalidDateParts || {};
300
+ var invalidDatePart = invalidDateParts[symbol];
301
+ var year = invalidDateParts.y.value || newValue.getFullYear();
302
+ var month = invalidDateParts.M.value || newValue.getMonth();
303
+ var day = invalidDateParts.d.value || invalidDateParts.E.value || newValue.getDate();
304
+ var hour = invalidDateParts.h.value || invalidDateParts.H.value || newValue.getHours();
305
+ var minutes = invalidDateParts.m.value || newValue.getMinutes();
306
+ var seconds = invalidDateParts.s.value || newValue.getSeconds();
307
+ var milliseconds = invalidDateParts.S.value || newValue.getMilliseconds();
308
+ switch (symbol) {
309
+ case 'y':
310
+ year += offset;
311
+ break;
312
+ case 'M':
313
+ month += offset;
314
+ break;
315
+ case 'd':
316
+ case 'E':
317
+ day += offset;
318
+ break;
319
+ case 'h':
320
+ case 'H':
321
+ hour += offset;
322
+ break;
323
+ case 'm':
324
+ minutes += offset;
325
+ break;
326
+ case 's':
327
+ seconds += offset;
328
+ break;
329
+ case 'S':
330
+ milliseconds += offset;
331
+ break;
332
+ // case 'a': newValue.setHours(newValue.getHours() + (12 * offset)); timeModified = true; break;
333
+ default: break;
334
+ }
335
+ if (symbol === "M") {
336
+ if ((month < 0 || month > 11) && this.getExisting(symbol)) {
337
+ // do not cycle months
338
+ this.setExisting(symbol, false);
339
+ return;
340
+ }
341
+ // const mask = this.dateFormatString(this.value, this.format);
342
+ // const monthPart = mask.partMap.filter(x => x.type === "month");
343
+ // if (monthPart && monthPart[0] && monthPart[0].pattern.length > MONTH_PART_WITH_WORDS_THRESHOLD) {
344
+ month = (12 + month) % 12;
345
+ // }
346
+ }
347
+ var dateCandidate = createDate(year, month, day, hour, minutes, seconds, milliseconds);
348
+ var newValueCandidate = isMonth || isDay ?
349
+ this.modifyDateSymbolWithValue(newValue, symbol, isMonth ? month : day) :
350
+ null;
351
+ var dateCandidateExists = areDatePartsEqualTo(dateCandidate, year, month, day, hour, minutes, seconds, milliseconds);
352
+ if (this.getValue() && areDatePartsEqualTo(dateCandidate, year, month, day, hour, minutes, seconds, milliseconds)) {
353
+ newValue = cloneDate(dateCandidate);
354
+ this.markDatePartsAsExisting();
355
+ }
356
+ else if (isMonth && newValueCandidate) {
357
+ if (newValueCandidate.getMonth() === month) {
358
+ if (this.getExisting("d")) {
359
+ if (dateCandidateExists) {
360
+ newValue = cloneDate(dateCandidate);
361
+ this.resetInvalidDateSymbol(symbol);
362
+ }
363
+ else {
364
+ invalidDateFound = true;
365
+ this.setInvalidDatePart(symbol, {
366
+ value: month,
367
+ date: cloneDate(newValueCandidate),
368
+ startDateOffset: offset,
369
+ startDate: cloneDate(this.value)
370
+ });
371
+ this.setExisting(symbol, false);
372
+ }
373
+ }
374
+ else if (dateCandidateExists) {
375
+ this.resetInvalidDateSymbol(symbol);
376
+ newValue = cloneDate(dateCandidate);
377
+ if (this.getExisting("M") && this.getExisting("y")) {
378
+ // changing from 28/Feb to 29/Feb to 29/March
379
+ this.setExisting("d", true);
380
+ this.resetInvalidDateSymbol("d");
381
+ }
382
+ }
383
+ else {
384
+ this.resetInvalidDateSymbol(symbol);
385
+ newValue = cloneDate(newValueCandidate);
386
+ }
387
+ }
388
+ else {
389
+ invalidDateFound = true;
390
+ this.setInvalidDatePart(symbol, {
391
+ value: month,
392
+ date: cloneDate(newValueCandidate),
393
+ startDateOffset: offset,
394
+ startDate: cloneDate(this.value)
395
+ });
396
+ this.setExisting(symbol, false);
397
+ }
398
+ }
399
+ else if (isDay && newValueCandidate) {
400
+ if (newValueCandidate.getDate() === day) {
401
+ if (this.getExisting("M")) {
402
+ if (dateCandidateExists) {
403
+ newValue = cloneDate(dateCandidate);
404
+ this.resetInvalidDateSymbol(symbol);
405
+ }
406
+ else {
407
+ invalidDateFound = true;
408
+ this.setInvalidDatePart(symbol, {
409
+ value: day,
410
+ date: cloneDate(newValueCandidate),
411
+ startDateOffset: offset,
412
+ startDate: cloneDate(this.value)
413
+ });
414
+ this.setExisting(symbol, false);
415
+ }
416
+ }
417
+ else if (dateCandidateExists) {
418
+ newValue = cloneDate(dateCandidate);
419
+ this.resetInvalidDateSymbol(symbol);
420
+ if (this.getExisting("d") && this.getExisting("y")) {
421
+ // changing from 31/Jan to 31/Feb to 28/Feb
422
+ this.setExisting("M", true);
423
+ this.resetInvalidDateSymbol("M");
424
+ }
425
+ }
426
+ else {
427
+ this.resetInvalidDateSymbol(symbol);
428
+ newValue = cloneDate(newValueCandidate);
429
+ }
430
+ }
431
+ else {
432
+ invalidDateFound = true;
433
+ this.setInvalidDatePart(symbol, {
434
+ value: day,
435
+ date: cloneDate(this.value),
436
+ startDateOffset: offset,
437
+ startDate: cloneDate(this.value)
438
+ });
439
+ this.setExisting(symbol, false);
440
+ }
441
+ }
442
+ else {
443
+ // this.modifyDateSymbol()
444
+ switch (symbol) {
445
+ case 'y':
446
+ newValue.setFullYear(newValue.getFullYear() + offset);
447
+ break;
448
+ case 'M':
449
+ newValue = addMonths(this.value, offset);
450
+ break;
451
+ case 'd':
452
+ case 'E':
453
+ newValue.setDate(newValue.getDate() + offset);
454
+ break;
455
+ case 'h':
456
+ case 'H':
457
+ newValue.setHours(newValue.getHours() + offset);
458
+ timeModified = true;
459
+ break;
460
+ case 'm':
461
+ newValue.setMinutes(newValue.getMinutes() + offset);
462
+ timeModified = true;
463
+ break;
464
+ case 's':
465
+ newValue.setSeconds(newValue.getSeconds() + offset);
466
+ timeModified = true;
467
+ break;
468
+ case "S":
469
+ newValue.setMilliseconds(newValue.getMilliseconds() + offset);
470
+ break;
471
+ case 'a':
472
+ newValue.setHours(newValue.getHours() + (12 * offset));
473
+ timeModified = true;
474
+ break;
475
+ default: break;
476
+ }
477
+ invalidDateFound = true;
478
+ if (invalidDatePart && invalidDatePart.value) {
479
+ currentInvalidDatePartValue = parseToInt(invalidDatePart.value);
480
+ }
481
+ else {
482
+ if (!isPresent(invalidDatePart.value)) {
483
+ newValue = cloneDate(originalValue);
484
+ // this.modifyDateSymbol()
485
+ switch (symbol) {
486
+ case 'y':
487
+ currentInvalidDatePartValue = originalValue.getFullYear();
488
+ break;
489
+ case 'M':
490
+ currentInvalidDatePartValue = originalValue.getMonth();
491
+ break;
492
+ case 'd':
493
+ case 'E':
494
+ currentInvalidDatePartValue = originalValue.getDate();
495
+ break;
496
+ case 'h':
497
+ case 'H':
498
+ currentInvalidDatePartValue = originalValue.getHours();
499
+ break;
500
+ case 'm':
501
+ currentInvalidDatePartValue = originalValue.getMinutes();
502
+ break;
503
+ case 's':
504
+ currentInvalidDatePartValue = originalValue.getSeconds();
505
+ break;
506
+ case 'S':
507
+ currentInvalidDatePartValue = originalValue.getMilliseconds();
508
+ break;
509
+ // case 'a': newValue.setHours(newValue.getHours() + (12 * offset)); timeModified = true; break;
510
+ default: break;
511
+ }
512
+ }
513
+ else {
514
+ }
515
+ }
516
+ var invalidDatePartValue = Math.max(0, currentInvalidDatePartValue + offset);
517
+ if (symbol !== "y") {
518
+ invalidDatePartValue = clamp(currentInvalidDatePartValue + offset, 0, 99);
519
+ }
520
+ this.setInvalidDatePart(symbol, {
521
+ value: invalidDatePartValue,
522
+ date: cloneDate(newValue),
523
+ startDateOffset: (this.getInvalidDatePart(symbol).startDateOffset || 0) + offset,
524
+ startDate: cloneDate(this.value)
525
+ });
526
+ this.setExisting(symbol, false);
527
+ }
528
+ }
529
+ else {
530
+ switch (symbol) {
531
+ case 'y':
532
+ newValue.setFullYear(newValue.getFullYear() + offset);
533
+ break;
534
+ case 'M':
535
+ newValue = addMonths(this.value, offset);
536
+ break;
537
+ case 'd':
538
+ case 'E':
539
+ newValue.setDate(newValue.getDate() + offset);
540
+ break;
541
+ case 'h':
542
+ case 'H':
543
+ newValue.setHours(newValue.getHours() + offset);
544
+ timeModified = true;
545
+ break;
546
+ case 'm':
547
+ newValue.setMinutes(newValue.getMinutes() + offset);
548
+ timeModified = true;
549
+ break;
550
+ case 's':
551
+ newValue.setSeconds(newValue.getSeconds() + offset);
552
+ timeModified = true;
553
+ break;
554
+ case "S":
555
+ newValue.setMilliseconds(newValue.getMilliseconds() + offset);
556
+ break;
557
+ case 'a':
558
+ newValue.setHours(newValue.getHours() + (12 * offset));
559
+ timeModified = true;
560
+ break;
561
+ default: break;
562
+ }
563
+ }
564
+ if (this.shouldNormalizeCentury()) {
565
+ newValue = this.normalizeCentury(newValue);
566
+ }
567
+ if (timeModified && !this.cycleTime && newValue.getDate() !== this._value.getDate()) {
568
+ // todo: blazor has this fix, but this fails a unit test
569
+ // newValue.setDate(this._value.getDate());
570
+ // newValue.setMonth(this._value.getMonth());
571
+ // newValue.setFullYear(this._value.getFullYear());
572
+ }
573
+ if (!invalidDateFound) {
574
+ this.setExisting(symbol, true);
575
+ this._value = newValue;
576
+ if (this.getValue()) {
577
+ this.resetInvalidDate();
578
+ }
579
+ }
580
+ };
581
+ /**
582
+ * @hidden
583
+ */
584
+ DateObject.prototype.parsePart = function (_a) {
585
+ var _b;
586
+ var symbol = _a.symbol, currentChar = _a.currentChar, resetSegmentValue = _a.resetSegmentValue, cycleSegmentValue = _a.cycleSegmentValue, rawTextValue = _a.rawTextValue, isDeleting = _a.isDeleting;
587
+ var isInCaretMode = !cycleSegmentValue;
588
+ var dateParts = this.dateFormatString(this.value, this.format);
589
+ var datePartsLiterals = dateParts.partMap
590
+ .filter(function (x) { return x.type === "literal"; })
591
+ .map(function (x, index) {
592
+ return {
593
+ datePartIndex: index,
594
+ literal: x.pattern
595
+ };
596
+ });
597
+ var shouldResetPart = isInCaretMode && symbol === "M" && dateParts.partMap
598
+ .filter(function (x) { return x.type === "month"; })
599
+ .some(function (x) { return x.pattern.length > MONTH_PART_WITH_WORDS_THRESHOLD; });
600
+ var parseResult = {
601
+ value: null,
602
+ switchPart: false,
603
+ resetPart: shouldResetPart
604
+ };
605
+ if (!currentChar) {
606
+ if (isInCaretMode) {
607
+ for (var i = 0; i < datePartsLiterals.length; i++) {
608
+ var literal = datePartsLiterals[i].literal;
609
+ var rawValueStartsWithLiteral = rawTextValue.startsWith(literal);
610
+ var rawValueEndsWithLiteral = rawTextValue.endsWith(literal);
611
+ var rawValueHasConsecutiveLiterals = rawTextValue.indexOf(literal + literal) >= 0;
612
+ if (rawValueStartsWithLiteral || rawValueEndsWithLiteral || rawValueHasConsecutiveLiterals) {
613
+ this.resetLeadingZero();
614
+ this.setExisting(symbol, false);
615
+ this.resetInvalidDateSymbol(symbol);
616
+ return extend(parseResult, { value: null, switchToNext: false });
617
+ }
618
+ }
619
+ }
620
+ else {
621
+ this.resetLeadingZero();
622
+ this.setExisting(symbol, false);
623
+ this.resetInvalidDateSymbol(symbol);
624
+ // return extend(parseResult, { value: null, switchToNext: false });
625
+ return { value: null, switchToNext: false };
626
+ }
627
+ }
628
+ var baseDate = this.intl.formatDate(this.value, this.format, this.localeId);
629
+ var baseFormat = dateParts.symbols;
630
+ var replaced = false;
631
+ var prefix = '';
632
+ var current = '';
633
+ var datePartText = '';
634
+ var suffix = '';
635
+ if (isInCaretMode) {
636
+ var datePartIndex = 0;
637
+ var outOfDatePartBounds = false;
638
+ for (var i = 0; i < baseDate.length; i++) {
639
+ var datePartLiteral = datePartsLiterals[datePartIndex];
640
+ if (datePartLiteral && datePartLiteral === baseDate[i]) {
641
+ datePartIndex++;
642
+ }
643
+ if (baseFormat[i] === symbol) {
644
+ var existing = this.getExisting(symbol);
645
+ current += existing ? baseDate[i] : '0';
646
+ var rawInputChar = rawTextValue[i];
647
+ if (rawInputChar !== baseDate[i] && rawInputChar === datePartsLiterals[datePartIndex].literal) {
648
+ outOfDatePartBounds = true;
649
+ }
650
+ else if (!outOfDatePartBounds) {
651
+ if (rawInputChar === undefined) {
652
+ var formatOffset = Math.abs(this.format.length - baseFormat.length);
653
+ datePartText += rawTextValue[i - formatOffset] || '';
654
+ }
655
+ else {
656
+ datePartText += rawInputChar || '';
657
+ }
658
+ }
659
+ replaced = true;
660
+ }
661
+ else if (!replaced) {
662
+ prefix += baseDate[i];
663
+ }
664
+ else {
665
+ suffix += baseDate[i];
666
+ }
667
+ }
668
+ }
669
+ else {
670
+ for (var i = 0; i < baseDate.length; i++) {
671
+ if (baseFormat[i] === symbol) {
672
+ var existing = this.getExisting(symbol);
673
+ current += existing ? baseDate[i] : '0';
674
+ replaced = true;
675
+ }
676
+ else if (!replaced) {
677
+ prefix += baseDate[i];
678
+ }
679
+ else {
680
+ suffix += baseDate[i];
681
+ }
682
+ }
683
+ }
684
+ var parsedDate = null;
685
+ var month = this.matchMonth(currentChar);
686
+ var dayPeriod = this.matchDayPeriod(currentChar, symbol);
687
+ var isZeroCurrentChar = currentChar === '0';
688
+ var leadingZero = this.leadingZero || {};
689
+ if (isZeroCurrentChar && !isInCaretMode) {
690
+ var valueNumber = parseInt(resetSegmentValue ? currentChar : current + currentChar, 10);
691
+ if (valueNumber === 0 && !this.isAbbrMonth(dateParts.partMap, symbol)) {
692
+ this.incrementLeadingZero(symbol);
693
+ }
694
+ }
695
+ else {
696
+ this.resetLeadingZero();
697
+ }
698
+ var partPattern = this.partPattern(dateParts.partMap, symbol);
699
+ var patternValue = partPattern ? partPattern.pattern : null;
700
+ if (isInCaretMode && isDeleting) {
701
+ var padPrefix = padZero(Math.abs(current.length - datePartText.length));
702
+ current = padPrefix + datePartText;
703
+ }
704
+ if (isInCaretMode) {
705
+ if (isDeleting && !datePartText) {
706
+ this.setExisting(symbol, false);
707
+ return extend(parseResult, { value: null, switchToNext: false });
708
+ }
709
+ }
710
+ var currentMaxLength = current.length - 3;
711
+ var tryParse = true;
712
+ for (var i = Math.max(0, currentMaxLength); i <= current.length; i++) {
713
+ if (!tryParse) {
714
+ break;
715
+ }
716
+ if (!this.autoCorrectParts) {
717
+ tryParse = false;
718
+ }
719
+ var middle = resetSegmentValue ? currentChar : (current.substring(i) + currentChar);
720
+ if (!tryParse && isInCaretMode) {
721
+ // try to make an exact match as there will be only 1 attempt
722
+ middle = unpadZero(middle);
723
+ }
724
+ var middleNumber = parseInt(middle, 10);
725
+ var candidateDateString = prefix + middle + suffix;
726
+ parsedDate = this.intl.parseDate(candidateDateString, this.format, this.localeId);
727
+ var isCurrentCharParsable = !isNaN(parseInt(currentChar, 10)) || (isInCaretMode && isDeleting && currentChar === "");
728
+ if (!parsedDate && !isNaN(middleNumber) && isCurrentCharParsable) {
729
+ if (symbol === MONTH_SYMBOL && !month) {
730
+ // JS months start from 0 (January) instead of 1 (January)
731
+ var monthNumber = middleNumber - JS_MONTH_OFFSET;
732
+ if (monthNumber > -1 && monthNumber < 12) {
733
+ parsedDate = cloneDate(this.value);
734
+ parsedDate.setMonth(monthNumber);
735
+ if (parsedDate.getMonth() !== monthNumber) {
736
+ parsedDate = lastDayOfMonth(addMonths(parsedDate, -1));
737
+ }
738
+ }
739
+ }
740
+ if (symbol === 'y') {
741
+ parsedDate = createDate(parseInt(middle, 10), this.month ? this.value.getMonth() : 0, this.date ? this.value.getDate() : 1, this.hours ? this.value.getHours() : 0, this.minutes ? this.value.getMinutes() : 0, this.seconds ? this.value.getSeconds() : 0, this.milliseconds ? this.value.getMilliseconds() : 0);
742
+ if (this.date && parsedDate.getDate() !== this.value.getDate()) {
743
+ parsedDate = lastDayOfMonth(addMonths(parsedDate, -1));
744
+ }
745
+ }
746
+ }
747
+ if (parsedDate) {
748
+ // move to next segment if the part will overflow with next char
749
+ // when start from empty date (01, then 010), padded zeros should be trimmed
750
+ var peekDate = this.intl.parseDate("" + prefix + this.peek(middle, patternValue) + suffix, this.format, this.localeId);
751
+ var patternLength = this.patternLength(patternValue) || patternValue.length;
752
+ var patternSatisfied = (leadingZero + (unpadZero(middle) || currentChar).length) >= patternLength;
753
+ var switchToNext = peekDate === null || patternSatisfied;
754
+ if (this.shouldNormalizeCentury()) {
755
+ parsedDate = this.normalizeCentury(parsedDate);
756
+ }
757
+ this._value = parsedDate;
758
+ this.setExisting(symbol, true);
759
+ return extend(parseResult, { value: this.value, switchToNext: switchToNext });
760
+ }
761
+ }
762
+ if (month) {
763
+ parsedDate = this.intl.parseDate(prefix + month + suffix, this.format, this.localeId);
764
+ if (parsedDate) {
765
+ this._value = parsedDate;
766
+ this.setExisting(symbol, true);
767
+ return extend(parseResult, { value: this.value, switchToNext: false });
768
+ }
769
+ }
770
+ if (dayPeriod) {
771
+ parsedDate = this.intl.parseDate(prefix + dayPeriod + suffix, this.format);
772
+ if (parsedDate) {
773
+ this._value = parsedDate;
774
+ return extend(parseResult, { value: this.value, switchToNext: true });
775
+ }
776
+ }
777
+ if (isZeroCurrentChar) {
778
+ this.leadingZero = !this.isAbbrMonth(dateParts.partMap, symbol) ? (_b = {}, _b[symbol] = true, _b) : null;
779
+ this.setExisting(symbol, false);
780
+ }
781
+ if (!this.autoCorrectParts) {
782
+ this.setExisting(symbol, false);
783
+ // todo check if string is better
784
+ // const padPrefix = padZero(Math.abs(current.length - datePartText.length));
785
+ // const paddedDatePartText = padPrefix + datePartText;
786
+ var datePartValue = void 0;
787
+ var textToParse = isInCaretMode ? datePartText : current;
788
+ var parsedValue = parseToInt(textToParse);
789
+ if (isNumber(parsedValue)) {
790
+ datePartValue = symbol === "M" ?
791
+ clamp(parsedValue - JS_MONTH_OFFSET, 0, 12 - JS_MONTH_OFFSET) :
792
+ parsedValue;
793
+ }
794
+ if (isNumber(datePartValue)) {
795
+ var newDate = this.modifyDateSymbolWithValue(this.value, symbol, datePartValue);
796
+ this.setInvalidDatePart(symbol, {
797
+ value: datePartValue,
798
+ date: cloneDate(newDate),
799
+ startDate: this._partiallyInvalidDate.startDate || cloneDate(this.value)
800
+ });
801
+ }
802
+ }
803
+ return extend(parseResult, { value: null, switchToNext: false });
804
+ };
805
+ /**
806
+ * @hidden
807
+ */
808
+ DateObject.prototype.symbolMap = function (symbol) {
809
+ return this.intl.splitDateFormat(this.format, this.localeId).reduce(dateSymbolMap, {})[symbol];
810
+ };
811
+ /**
812
+ * @hidden
813
+ */
814
+ DateObject.prototype.resetLeadingZero = function () {
815
+ var hasLeadingZero = this.leadingZero !== null;
816
+ this.setLeadingZero(null);
817
+ return hasLeadingZero;
818
+ };
819
+ DateObject.prototype.setLeadingZero = function (leadingZero) {
820
+ this.leadingZero = leadingZero;
821
+ };
822
+ /**
823
+ * @hidden
824
+ */
825
+ DateObject.prototype.normalizeCentury = function (date) {
826
+ if (!isPresent(date)) {
827
+ return date;
828
+ }
829
+ var twoDigitYear = cropTwoDigitYear(date);
830
+ var centuryBase = this.getNormalizedCenturyBase(twoDigitYear);
831
+ var normalizedDate = setYears(date, centuryBase + twoDigitYear);
832
+ return normalizedDate;
833
+ };
834
+ DateObject.prototype.incrementLeadingZero = function (symbol) {
835
+ var leadingZero = this.leadingZero || {};
836
+ leadingZero[symbol] = (leadingZero[symbol] || 0) + 1;
837
+ this.leadingZero = leadingZero;
838
+ };
839
+ /**
840
+ * @hidden
841
+ */
842
+ DateObject.prototype.isAbbrMonth = function (parts, symbol) {
843
+ var pattern = this.partPattern(parts, symbol);
844
+ return pattern.type === 'month' && pattern.names;
845
+ };
846
+ /**
847
+ * @hidden
848
+ */
849
+ DateObject.prototype.partPattern = function (parts, symbol) {
850
+ return parts.filter(function (part) { return part.pattern.indexOf(symbol) !== -1; })[0];
851
+ };
852
+ /**
853
+ * @hidden
854
+ */
855
+ DateObject.prototype.peek = function (value, pattern) {
856
+ var peekValue = value.replace(/^0*/, '') + '0';
857
+ return padZero(pattern.length - peekValue.length) + peekValue;
858
+ };
859
+ /**
860
+ * @hidden
861
+ */
862
+ DateObject.prototype.matchMonth = function (typedChar) {
863
+ this.typedMonthPart += typedChar.toLowerCase();
864
+ if (this.monthNames.length === 0) {
865
+ return '';
866
+ }
867
+ while (this.typedMonthPart.length > 0) {
868
+ for (var i = 0; i < this.monthNames.length; i++) {
869
+ if (this.monthNames[i].toLowerCase().indexOf(this.typedMonthPart) === 0) {
870
+ return this.monthNames[i];
871
+ }
872
+ }
873
+ var monthAsNum = parseInt(this.typedMonthPart, 10);
874
+ /* ensure they exact match */
875
+ if (monthAsNum >= 1 && monthAsNum <= 12 && monthAsNum.toString() === this.typedMonthPart) {
876
+ return this.monthNames[monthAsNum - 1];
877
+ }
878
+ this.typedMonthPart = this.typedMonthPart.substring(1, this.typedMonthPart.length);
879
+ }
880
+ return '';
881
+ };
882
+ /**
883
+ * @hidden
884
+ */
885
+ DateObject.prototype.matchDayPeriod = function (typedChar, symbol) {
886
+ var lowerChart = typedChar.toLowerCase();
887
+ if (symbol === 'a' && this.dayPeriods) {
888
+ if (this.dayPeriods.am.toLowerCase().startsWith(lowerChart)) {
889
+ return this.dayPeriods.am;
890
+ }
891
+ else if (this.dayPeriods.pm.toLowerCase().startsWith(lowerChart)) {
892
+ return this.dayPeriods.pm;
893
+ }
894
+ }
895
+ return '';
896
+ };
897
+ /**
898
+ * @hidden
899
+ */
900
+ DateObject.prototype.allFormattedMonths = function (locale) {
901
+ if (locale === void 0) { locale = "en"; }
902
+ var dateFormatParts = this.intl.splitDateFormat(this.format, this.localeId);
903
+ for (var i = 0; i < dateFormatParts.length; i++) {
904
+ if (dateFormatParts[i].type === 'month' && dateFormatParts[i].names) {
905
+ // return this.intl.dateFormatNames(dateFormatParts[i].names);
906
+ return this.intl.dateFormatNames(locale, dateFormatParts[i].names);
907
+ }
908
+ }
909
+ return [];
910
+ };
911
+ /**
912
+ * @hidden
913
+ */
914
+ DateObject.prototype.allDayPeriods = function (locale) {
915
+ if (locale === void 0) { locale = "en"; }
916
+ var dateFormatParts = this.intl.splitDateFormat(this.format);
917
+ for (var i = 0; i < dateFormatParts.length; i++) {
918
+ if (dateFormatParts[i].type === "dayperiod" && dateFormatParts[i].names) {
919
+ return this.intl.dateFormatNames(locale, dateFormatParts[i].names);
920
+ }
921
+ }
922
+ return null;
923
+ };
924
+ /**
925
+ * @hidden
926
+ */
927
+ DateObject.prototype.patternLength = function (pattern) {
928
+ if (pattern[0] === 'y') {
929
+ return 4;
930
+ }
931
+ if (SHORT_PATTERN_LENGTH_REGEXP.test(pattern)) {
932
+ return 2;
933
+ }
934
+ return 0;
935
+ };
936
+ /**
937
+ * @hidden
938
+ */
939
+ DateObject.prototype.dateFormatString = function (date, format) {
940
+ var dateFormatParts = this.intl.splitDateFormat(format, this.localeId);
941
+ var parts = [];
942
+ var partMap = [];
943
+ for (var i = 0; i < dateFormatParts.length; i++) {
944
+ var partLength = this.intl.formatDate(date, { pattern: dateFormatParts[i].pattern }, this.localeId).length;
945
+ while (partLength > 0) {
946
+ parts.push(this.symbols[dateFormatParts[i].pattern[0]] || Constants.formatSeparator);
947
+ partMap.push(dateFormatParts[i]);
948
+ partLength--;
949
+ }
950
+ }
951
+ var returnValue = new Mask();
952
+ returnValue.symbols = parts.join('');
953
+ returnValue.partMap = partMap;
954
+ return returnValue;
955
+ };
956
+ /**
957
+ * @hidden
958
+ */
959
+ DateObject.prototype.merge = function (text, mask) {
960
+ // Important: right to left.
961
+ var resultText = '';
962
+ var resultFormat = '';
963
+ var format = mask.symbols;
964
+ for (var formatSymbolIndex = format.length - 1; formatSymbolIndex >= 0; formatSymbolIndex--) {
965
+ if (this.knownParts.indexOf(format[formatSymbolIndex]) === -1 || this.getExisting(format[formatSymbolIndex])) {
966
+ resultText = text[formatSymbolIndex] + resultText;
967
+ resultFormat = format[formatSymbolIndex] + resultFormat;
968
+ }
969
+ else {
970
+ var symbol = format[formatSymbolIndex];
971
+ while (formatSymbolIndex >= 0 && symbol === format[formatSymbolIndex]) {
972
+ formatSymbolIndex--;
973
+ }
974
+ formatSymbolIndex++;
975
+ if (this.leadingZero && this.leadingZero[symbol]) {
976
+ resultText = '0' + resultText;
977
+ }
978
+ else {
979
+ if (!this.autoCorrectParts && this.getInvalidDatePartValue(symbol)) {
980
+ var segmentText = text.substr(formatSymbolIndex, mask.partMap[formatSymbolIndex].pattern.length);
981
+ resultText = segmentText + resultText;
982
+ }
983
+ else {
984
+ resultText = this.dateFieldName(mask.partMap[formatSymbolIndex]) + resultText;
985
+ }
986
+ }
987
+ while (resultFormat.length < resultText.length) {
988
+ resultFormat = format[formatSymbolIndex] + resultFormat;
989
+ }
990
+ }
991
+ }
992
+ return { text: resultText, format: resultFormat };
993
+ };
994
+ /**
995
+ * @hidden
996
+ */
997
+ DateObject.prototype.dateFieldName = function (part) {
998
+ var formatPlaceholder = this.formatPlaceholder || 'wide';
999
+ if (formatPlaceholder[part.type]) {
1000
+ return formatPlaceholder[part.type];
1001
+ }
1002
+ if (formatPlaceholder === 'formatPattern') {
1003
+ return part.pattern;
1004
+ }
1005
+ return this.intl.dateFieldName(Object.assign(part, { nameType: formatPlaceholder }));
1006
+ };
1007
+ /**
1008
+ * @hidden
1009
+ */
1010
+ DateObject.prototype.getNormalizedCenturyBase = function (twoDigitYear) {
1011
+ return twoDigitYear > this.twoDigitYearMax ?
1012
+ PREVIOUS_CENTURY_BASE :
1013
+ CURRENT_CENTURY_BASE;
1014
+ };
1015
+ /**
1016
+ * @hidden
1017
+ */
1018
+ DateObject.prototype.shouldNormalizeCentury = function () {
1019
+ return this.intl.splitDateFormat(this.format).some(function (part) { return part.pattern === 'yy'; });
1020
+ };
1021
+ DateObject.prototype.resetInvalidDate = function () {
1022
+ var _this = this;
1023
+ this._partiallyInvalidDate.startDate = null;
1024
+ Object.keys(this._partiallyInvalidDate.invalidDateParts).forEach(function (key) {
1025
+ _this.resetInvalidDatePart(key);
1026
+ });
1027
+ };
1028
+ DateObject.prototype.resetInvalidDateSymbol = function (symbol) {
1029
+ var _this = this;
1030
+ this.resetInvalidDatePart(symbol);
1031
+ var shouldResetInvalidDate = true;
1032
+ Object.keys(this._partiallyInvalidDate.invalidDateParts).forEach(function (key) {
1033
+ if (_this._partiallyInvalidDate.invalidDateParts[key] &&
1034
+ isPresent(_this._partiallyInvalidDate.invalidDateParts[key].value)) {
1035
+ shouldResetInvalidDate = false;
1036
+ }
1037
+ });
1038
+ if (shouldResetInvalidDate) {
1039
+ this.resetInvalidDate();
1040
+ }
1041
+ };
1042
+ DateObject.prototype.resetInvalidDatePart = function (symbol) {
1043
+ if (this._partiallyInvalidDate.invalidDateParts[symbol]) {
1044
+ this._partiallyInvalidDate.invalidDateParts[symbol] = {
1045
+ value: null,
1046
+ date: null,
1047
+ startDateOffset: 0
1048
+ };
1049
+ }
1050
+ };
1051
+ /**
1052
+ * @hidden
1053
+ */
1054
+ DateObject.prototype.getInvalidDatePart = function (symbol) {
1055
+ var invalidDatePart = this._partiallyInvalidDate.invalidDateParts[symbol];
1056
+ return invalidDatePart || {};
1057
+ };
1058
+ /**
1059
+ * @hidden
1060
+ */
1061
+ DateObject.prototype.getInvalidDatePartValue = function (symbol) {
1062
+ var invalidDatePart = this._partiallyInvalidDate.invalidDateParts[symbol];
1063
+ return (invalidDatePart || {}).value;
1064
+ };
1065
+ DateObject.prototype.setInvalidDatePart = function (symbol, _a) {
1066
+ var _b = _a.value, value = _b === void 0 ? null : _b, _c = _a.date, date = _c === void 0 ? null : _c, _d = _a.startDateOffset, startDateOffset = _d === void 0 ? 0 : _d, _e = _a.startDate, startDate = _e === void 0 ? null : _e;
1067
+ if (this._partiallyInvalidDate.invalidDateParts[symbol]) {
1068
+ this._partiallyInvalidDate.invalidDateParts[symbol].value = value;
1069
+ this._partiallyInvalidDate.invalidDateParts[symbol].date = date;
1070
+ this._partiallyInvalidDate.invalidDateParts[symbol].startDateOffset = startDateOffset;
1071
+ this._partiallyInvalidDate.startDate = startDate;
1072
+ }
1073
+ };
1074
+ /**
1075
+ * @hidden
1076
+ */
1077
+ DateObject.prototype.modifyDateSymbolWithOffset = function (date, symbol, offset) {
1078
+ var newValue = cloneDate(date);
1079
+ var timeModified = false;
1080
+ switch (symbol) {
1081
+ case 'y':
1082
+ newValue.setFullYear(newValue.getFullYear() + offset);
1083
+ break;
1084
+ case 'M':
1085
+ newValue = addMonths(this.value, offset);
1086
+ break;
1087
+ case 'd':
1088
+ case 'E':
1089
+ newValue.setDate(newValue.getDate() + offset);
1090
+ break;
1091
+ case 'h':
1092
+ case 'H':
1093
+ newValue.setHours(newValue.getHours() + offset);
1094
+ timeModified = true;
1095
+ break;
1096
+ case 'm':
1097
+ newValue.setMinutes(newValue.getMinutes() + offset);
1098
+ timeModified = true;
1099
+ break;
1100
+ case 's':
1101
+ newValue.setSeconds(newValue.getSeconds() + offset);
1102
+ timeModified = true;
1103
+ break;
1104
+ case "S":
1105
+ newValue.setMilliseconds(newValue.getMilliseconds() + offset);
1106
+ break;
1107
+ case 'a':
1108
+ newValue.setHours(newValue.getHours() + (12 * offset));
1109
+ timeModified = true;
1110
+ break;
1111
+ default: break;
1112
+ }
1113
+ return {
1114
+ date: newValue,
1115
+ timeModified: timeModified
1116
+ };
1117
+ };
1118
+ /**
1119
+ * @hidden
1120
+ */
1121
+ DateObject.prototype.modifyDateSymbolWithValue = function (date, symbol, value) {
1122
+ var newValue = cloneDate(date);
1123
+ switch (symbol) {
1124
+ case 'y':
1125
+ newValue.setFullYear(value);
1126
+ break;
1127
+ case 'M':
1128
+ newValue = addMonths(date, value - date.getMonth());
1129
+ break;
1130
+ case 'd':
1131
+ case 'E':
1132
+ newValue.setDate(value);
1133
+ break;
1134
+ case 'h':
1135
+ case 'H':
1136
+ newValue.setHours(value);
1137
+ break;
1138
+ case 'm':
1139
+ newValue.setMinutes(value);
1140
+ break;
1141
+ case 's':
1142
+ newValue.setSeconds(value);
1143
+ break;
1144
+ case "S":
1145
+ newValue.setMilliseconds(value);
1146
+ break;
1147
+ case 'a':
1148
+ newValue.setHours(value);
1149
+ break;
1150
+ default: break;
1151
+ }
1152
+ return newValue;
1153
+ };
1154
+ DateObject.prototype.markDatePartsAsExisting = function () {
1155
+ this.modifyExisting(true);
1156
+ };
1157
+ return DateObject;
1158
+ }());
1159
+ export { DateObject };