@syncfusion/ej2-calendars 30.1.37 → 31.1.17
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.
- package/.eslintrc.json +263 -0
- package/dist/ej2-calendars.min.js +1 -1
- package/dist/ej2-calendars.umd.min.js +1 -1
- package/dist/global/ej2-calendars.min.js +1 -1
- package/dist/global/index.d.ts +1 -1
- package/dist/ts/calendar/calendar-model.d.ts +340 -0
- package/dist/ts/calendar/calendar.d.ts +733 -0
- package/dist/ts/calendar/calendar.ts +3009 -0
- package/dist/ts/calendar/index.d.ts +6 -0
- package/dist/ts/calendar/index.ts +6 -0
- package/dist/ts/calendar/islamic.d.ts +28 -0
- package/dist/ts/calendar/islamic.ts +597 -0
- package/dist/ts/common/index.d.ts +5 -0
- package/dist/ts/common/index.ts +5 -0
- package/dist/ts/common/maskplaceholder-model.d.ts +57 -0
- package/dist/ts/common/maskplaceholder.d.ts +45 -0
- package/dist/ts/common/maskplaceholder.ts +54 -0
- package/dist/ts/datepicker/datepicker-model.d.ts +364 -0
- package/dist/ts/datepicker/datepicker.d.ts +583 -0
- package/dist/ts/datepicker/datepicker.ts +2528 -0
- package/dist/ts/datepicker/index.d.ts +5 -0
- package/dist/ts/datepicker/index.ts +5 -0
- package/dist/ts/daterangepicker/daterangepicker-model.d.ts +496 -0
- package/dist/ts/daterangepicker/daterangepicker.d.ts +857 -0
- package/dist/ts/daterangepicker/daterangepicker.ts +5096 -0
- package/dist/ts/daterangepicker/index.d.ts +5 -0
- package/dist/ts/daterangepicker/index.ts +5 -0
- package/dist/ts/datetimepicker/datetimepicker-model.d.ts +479 -0
- package/dist/ts/datetimepicker/datetimepicker.d.ts +626 -0
- package/dist/ts/datetimepicker/datetimepicker.ts +2212 -0
- package/dist/ts/datetimepicker/index.d.ts +5 -0
- package/dist/ts/datetimepicker/index.ts +5 -0
- package/dist/ts/index.d.ts +9 -0
- package/dist/ts/index.ts +9 -0
- package/dist/ts/maskbase/index.d.ts +5 -0
- package/dist/ts/maskbase/index.ts +5 -0
- package/dist/ts/maskbase/interface.d.ts +28 -0
- package/dist/ts/maskbase/interface.ts +29 -0
- package/dist/ts/maskbase/masked-date-time.d.ts +77 -0
- package/dist/ts/maskbase/masked-date-time.ts +1013 -0
- package/dist/ts/timepicker/index.d.ts +5 -0
- package/dist/ts/timepicker/index.ts +5 -0
- package/dist/ts/timepicker/timepicker-model.d.ts +393 -0
- package/dist/ts/timepicker/timepicker.d.ts +681 -0
- package/dist/ts/timepicker/timepicker.ts +2944 -0
- package/package.json +59 -16
- package/styles/daterangepicker/_fluent2-definition.scss +2 -1
- package/styles/daterangepicker/fluent2.css +2 -1
- package/styles/datetimepicker/_fluent2-definition.scss +1 -1
- package/styles/datetimepicker/fluent2.css +1 -1
- package/styles/fluent2-lite.css +3 -2
- package/styles/fluent2.css +3 -2
- package/tslint.json +111 -0
|
@@ -0,0 +1,1013 @@
|
|
|
1
|
+
import {IMaskedDateTime} from '../maskbase/interface';
|
|
2
|
+
import { L10n, getValue, getDefaultDateObject, cldrData, KeyboardEventArgs, Browser} from '@syncfusion/ej2-base';
|
|
3
|
+
|
|
4
|
+
const ARROWLEFT: string = 'ArrowLeft';
|
|
5
|
+
const ARROWRIGHT: string = 'ArrowRight';
|
|
6
|
+
const ARROWUP: string = 'ArrowUp';
|
|
7
|
+
const ARROWDOWN: string = 'ArrowDown';
|
|
8
|
+
const TAB: string = 'Tab';
|
|
9
|
+
const SHIFTTAB: string = 'shiftTab';
|
|
10
|
+
const END: string = 'End';
|
|
11
|
+
const HOME: string = 'Home';
|
|
12
|
+
|
|
13
|
+
export class MaskedDateTime {
|
|
14
|
+
private parent : IMaskedDateTime;
|
|
15
|
+
private dateformat : string;
|
|
16
|
+
private mask : string = '';
|
|
17
|
+
private l10n : L10n;
|
|
18
|
+
private defaultConstant : {
|
|
19
|
+
[x : string]: Object;
|
|
20
|
+
} = {
|
|
21
|
+
day: 'day',
|
|
22
|
+
month: 'month',
|
|
23
|
+
year: 'year',
|
|
24
|
+
hour: 'hour',
|
|
25
|
+
minute: 'minute',
|
|
26
|
+
second: 'second',
|
|
27
|
+
dayOfTheWeek: 'day of the week'
|
|
28
|
+
};
|
|
29
|
+
private objectString : string[];
|
|
30
|
+
private hiddenMask : string = '';
|
|
31
|
+
private validCharacters : string = 'dMyhmHfasz';
|
|
32
|
+
private maskDateValue : Date;
|
|
33
|
+
private previousValue : string;
|
|
34
|
+
private previousHiddenMask : string;
|
|
35
|
+
private isDayPart : boolean = false;
|
|
36
|
+
private isMonthPart : boolean = false;
|
|
37
|
+
private isYearPart : boolean = false;
|
|
38
|
+
private isHourPart : boolean = false;
|
|
39
|
+
private isMinutePart : boolean = false;
|
|
40
|
+
private isSecondsPart : boolean = false;
|
|
41
|
+
private isMilliSecondsPart : boolean = false;
|
|
42
|
+
private monthCharacter : string = '';
|
|
43
|
+
private hour : number;
|
|
44
|
+
private periodCharacter : string = '';
|
|
45
|
+
private isHiddenMask : boolean = false;
|
|
46
|
+
private isComplete : boolean = false;
|
|
47
|
+
private previousDate : Date;
|
|
48
|
+
private isNavigate : boolean = false;
|
|
49
|
+
private navigated : boolean = false;
|
|
50
|
+
private isBlur : boolean = false;
|
|
51
|
+
private formatRegex : RegExp = /EEEEE|EEEE|EEE|EE|E|cccc|ccc|dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yyy|yy|y|HH|H|hh|h|mm|m|fff|ff|f|aa|a|ss|s|zzzz|zzz|zz|z|'[^']*'|'[^']*'/g;
|
|
52
|
+
private isDeletion: boolean = false;
|
|
53
|
+
private isShortYear: boolean = false;
|
|
54
|
+
private isDeleteKey: boolean = false;
|
|
55
|
+
private isDateZero: boolean = false;
|
|
56
|
+
private isMonthZero: boolean = false;
|
|
57
|
+
private isYearZero: boolean = false;
|
|
58
|
+
private isLeadingZero: boolean = false;
|
|
59
|
+
private dayTypeCount: number = 0;
|
|
60
|
+
private monthTypeCount: number = 0;
|
|
61
|
+
private hourTypeCount: number = 0;
|
|
62
|
+
private minuteTypeCount: number = 0;
|
|
63
|
+
private secondTypeCount: number = 0;
|
|
64
|
+
public constructor(parent? : IMaskedDateTime) {
|
|
65
|
+
this.parent = parent;
|
|
66
|
+
this.dateformat = this.getCulturedFormat();
|
|
67
|
+
this.maskDateValue = this.parent.value != null ? new Date(+this.parent.value) : new Date();
|
|
68
|
+
this.maskDateValue.setMonth(0);
|
|
69
|
+
this.maskDateValue.setHours(0);
|
|
70
|
+
this.maskDateValue.setMinutes(0);
|
|
71
|
+
this.maskDateValue.setSeconds(0);
|
|
72
|
+
this.previousDate = new Date(this.maskDateValue.getFullYear(), this.maskDateValue.getMonth(),
|
|
73
|
+
this.maskDateValue.getDate(), this.maskDateValue.getHours(),
|
|
74
|
+
this.maskDateValue.getMinutes(), this.maskDateValue.getSeconds());
|
|
75
|
+
this.removeEventListener();
|
|
76
|
+
this.addEventListener();
|
|
77
|
+
}
|
|
78
|
+
public getModuleName(): string {
|
|
79
|
+
return 'MaskedDateTime';
|
|
80
|
+
}
|
|
81
|
+
public addEventListener(): void {
|
|
82
|
+
if (this.parent.isDestroyed) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this.parent.on('createMask', this.createMask, this);
|
|
86
|
+
this.parent.on('setMaskSelection', this.validCharacterCheck, this);
|
|
87
|
+
this.parent.on('inputHandler', this.maskInputHandler, this);
|
|
88
|
+
this.parent.on('keyDownHandler', this.maskKeydownHandler, this);
|
|
89
|
+
this.parent.on('clearHandler', this.clearHandler, this);
|
|
90
|
+
this.parent.on('maskPasteInputHandler', this.maskPasteInputHandler, this);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public removeEventListener(): void {
|
|
94
|
+
if (this.parent.isDestroyed) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.parent.off('createMask', this.createMask);
|
|
98
|
+
this.parent.off('setMaskSelection', this.validCharacterCheck);
|
|
99
|
+
this.parent.off('inputHandler', this.maskInputHandler);
|
|
100
|
+
this.parent.off('keyDownHandler', this.maskKeydownHandler);
|
|
101
|
+
this.parent.off('clearHandler', this.clearHandler);
|
|
102
|
+
this.parent.off('maskPasteInputHandler', this.maskPasteInputHandler);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private createMask(mask: events): void {
|
|
106
|
+
this.isDayPart = this.isMonthPart = this.isYearPart = this.isHourPart = this.isMinutePart = this.isSecondsPart = false;
|
|
107
|
+
this.dateformat = this.getCulturedFormat();
|
|
108
|
+
|
|
109
|
+
if (this.parent.maskPlaceholder.day){
|
|
110
|
+
this.defaultConstant['day'] = this.parent.maskPlaceholder.day; }
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
if (this.parent.maskPlaceholder.month){
|
|
114
|
+
this.defaultConstant['month'] = this.parent.maskPlaceholder.month; }
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
if (this.parent.maskPlaceholder.year){
|
|
118
|
+
this.defaultConstant['year'] = this.parent.maskPlaceholder.year; }
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
if (this.parent.maskPlaceholder.hour){
|
|
122
|
+
this.defaultConstant['hour'] = this.parent.maskPlaceholder.hour; }
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
if (this.parent.maskPlaceholder.minute){
|
|
126
|
+
this.defaultConstant['minute'] = this.parent.maskPlaceholder.minute; }
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
if (this.parent.maskPlaceholder.second){
|
|
130
|
+
this.defaultConstant['second'] = this.parent.maskPlaceholder.second; }
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
if (this.parent.maskPlaceholder.dayOfTheWeek){
|
|
134
|
+
this.defaultConstant['dayOfTheWeek'] = this.parent.maskPlaceholder.dayOfTheWeek.toString(); }
|
|
135
|
+
|
|
136
|
+
this.getCUltureMaskFormat();
|
|
137
|
+
const inputValue: string = this.dateformat.replace(this.formatRegex, this.formatCheck());
|
|
138
|
+
this.isHiddenMask = true;
|
|
139
|
+
this.hiddenMask = this.dateformat.replace(this.formatRegex, this.formatCheck());
|
|
140
|
+
this.isHiddenMask = false;
|
|
141
|
+
this.previousHiddenMask = this.hiddenMask;
|
|
142
|
+
this.mask = this.previousValue = inputValue;
|
|
143
|
+
this.parent.maskedDateValue = this.mask;
|
|
144
|
+
if (this.parent.value) {
|
|
145
|
+
this.navigated = true;
|
|
146
|
+
this.isBlur = mask.isBlur;
|
|
147
|
+
this.setDynamicValue();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private getCUltureMaskFormat(): void {
|
|
152
|
+
this.l10n = new L10n(this.parent.moduleName, this.defaultConstant, this.parent.locale);
|
|
153
|
+
this.objectString = Object.keys(this.defaultConstant);
|
|
154
|
+
for (let i: number = 0; i < this.objectString.length; i++) {
|
|
155
|
+
this.defaultConstant[this.objectString[i as number].toString()] =
|
|
156
|
+
this.l10n.getConstant(this.objectString[i as number].toString());
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private validCharacterCheck(): void {
|
|
161
|
+
let start: number = this.parent.inputElement.selectionStart;
|
|
162
|
+
|
|
163
|
+
if (this.parent.moduleName !== 'timepicker') {
|
|
164
|
+
if (start === this.hiddenMask.length && this.mask === this.parent.inputElement.value) {
|
|
165
|
+
start = 0;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
for (let i: number = start, j: number = start - 1; i < this.hiddenMask.length || j >= 0; i++, j --) {
|
|
170
|
+
if (i < this.hiddenMask.length && this.validCharacters.indexOf(this.hiddenMask[i as number]) !== -1) {
|
|
171
|
+
this.setSelection(this.hiddenMask[i as number]);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (j >= 0 && this.validCharacters.indexOf(this.hiddenMask[j as number]) !== -1) {
|
|
175
|
+
this.setSelection(this.hiddenMask[j as number]);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
private setDynamicValue(): void {
|
|
181
|
+
this.maskDateValue = new Date(+this.parent.value);
|
|
182
|
+
this.isDayPart = this.isMonthPart = this.isYearPart = this.isHourPart = this.isMinutePart = this.isSecondsPart = true;
|
|
183
|
+
this.updateValue();
|
|
184
|
+
if (!this.isBlur)
|
|
185
|
+
{
|
|
186
|
+
this.validCharacterCheck();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
private setSelection(validChar : string): void {
|
|
190
|
+
let start: number = -1;
|
|
191
|
+
let end: number = 0;
|
|
192
|
+
for (let i: number = 0; i < this.hiddenMask.length; i++) {
|
|
193
|
+
if (this.hiddenMask[i as number] === validChar) {
|
|
194
|
+
end = i + 1;
|
|
195
|
+
if (start === -1) {
|
|
196
|
+
start = i;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (start < 0) {
|
|
201
|
+
start = 0;
|
|
202
|
+
}
|
|
203
|
+
this.parent.inputElement.setSelectionRange(start, end);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private maskKeydownHandler(args : events): void {
|
|
207
|
+
if (args.e.key === 'Backspace') {
|
|
208
|
+
const start: number = this.parent.inputElement.selectionStart;
|
|
209
|
+
let formatText: string = '';
|
|
210
|
+
if (this.validCharacters.indexOf(this.hiddenMask[start as number]) !== -1) {
|
|
211
|
+
formatText = this.hiddenMask[start as number];
|
|
212
|
+
}
|
|
213
|
+
switch (formatText) {
|
|
214
|
+
case 'd':
|
|
215
|
+
this.dayTypeCount = Math.max(this.dayTypeCount - 1, 0);
|
|
216
|
+
break;
|
|
217
|
+
case 'M':
|
|
218
|
+
this.monthTypeCount = Math.max(this.monthTypeCount - 1, 0);
|
|
219
|
+
break;
|
|
220
|
+
case 'H':
|
|
221
|
+
case 'h':
|
|
222
|
+
this.hourTypeCount = Math.max(this.hourTypeCount - 1, 0);
|
|
223
|
+
break;
|
|
224
|
+
case 'm':
|
|
225
|
+
this.minuteTypeCount = Math.max(this.minuteTypeCount - 1, 0);
|
|
226
|
+
break;
|
|
227
|
+
case 's':
|
|
228
|
+
this.secondTypeCount = Math.max(this.secondTypeCount - 1, 0);
|
|
229
|
+
break;
|
|
230
|
+
default:
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
this.dayTypeCount = this.monthTypeCount = this.hourTypeCount = this.minuteTypeCount = this.secondTypeCount = 0;
|
|
236
|
+
if (args.e.key === 'Delete')
|
|
237
|
+
{
|
|
238
|
+
this.isDeleteKey = true;
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if ((!args.e.altKey && !args.e.ctrlKey) && (args.e.key === ARROWLEFT || args.e.key === ARROWRIGHT
|
|
242
|
+
|| args.e.key === SHIFTTAB || args.e.key === TAB || args.e.action === SHIFTTAB ||
|
|
243
|
+
args.e.key === END || args.e.key === HOME)) {
|
|
244
|
+
const start: number = this.parent.inputElement.selectionStart;
|
|
245
|
+
const end: number = this.parent.inputElement.selectionEnd;
|
|
246
|
+
const length: number = this.parent.inputElement.value.length;
|
|
247
|
+
if ((start === 0 && end === length) && ( args.e.key === TAB || args.e.action === SHIFTTAB))
|
|
248
|
+
{
|
|
249
|
+
const index: number = args.e.action === SHIFTTAB ? end : 0;
|
|
250
|
+
this.parent.inputElement.selectionStart = this.parent.inputElement.selectionEnd = index;
|
|
251
|
+
}
|
|
252
|
+
if (args.e.key === END || args.e.key === HOME )
|
|
253
|
+
{
|
|
254
|
+
const range: number = args.e.key === END ? length : 0;
|
|
255
|
+
this.parent.inputElement.selectionStart = this.parent.inputElement.selectionEnd = range;
|
|
256
|
+
}
|
|
257
|
+
this.navigateSelection(args.e.key === ARROWLEFT || args.e.action === SHIFTTAB || args.e.key === END ? true : false);
|
|
258
|
+
}
|
|
259
|
+
if ((!args.e.altKey && !args.e.ctrlKey) && (args.e.key === ARROWUP || args.e.key === ARROWDOWN)) {
|
|
260
|
+
let start: number = this.parent.inputElement.selectionStart;
|
|
261
|
+
let formatText: string = '';
|
|
262
|
+
if (this.validCharacters.indexOf(this.hiddenMask[start as number]) !== -1) {
|
|
263
|
+
formatText = this.hiddenMask[start as number];
|
|
264
|
+
}
|
|
265
|
+
this.dateAlteration(args.e.key === ARROWDOWN ? true : false);
|
|
266
|
+
const inputValue: string = this.dateformat.replace(this.formatRegex, this.formatCheck());
|
|
267
|
+
this.isHiddenMask = true;
|
|
268
|
+
this.hiddenMask = this.dateformat.replace(this.formatRegex, this.formatCheck());
|
|
269
|
+
this.isHiddenMask = false;
|
|
270
|
+
this.previousHiddenMask = this.hiddenMask;
|
|
271
|
+
this.previousValue = inputValue;
|
|
272
|
+
this.parent.inputElement.value = inputValue;
|
|
273
|
+
for (let i: number = 0; i < this.hiddenMask.length; i++){
|
|
274
|
+
if (formatText === this.hiddenMask[i as number]){
|
|
275
|
+
start = i;
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
this.parent.inputElement.selectionStart = start;
|
|
280
|
+
this.validCharacterCheck();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
private isPersist(): boolean
|
|
285
|
+
{
|
|
286
|
+
const isPersist: boolean = this.parent.isFocused || this.navigated;
|
|
287
|
+
return isPersist;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
private differenceCheck(): void {
|
|
291
|
+
const start: number = this.parent.inputElement.selectionStart;
|
|
292
|
+
const inputValue: string = this.parent.inputElement.value;
|
|
293
|
+
const previousVal: string = this.previousValue.substring(0, start + this.previousValue.length - inputValue.length);
|
|
294
|
+
const newVal: string = inputValue.substring(0, start);
|
|
295
|
+
const newDateValue: Date = new Date(+this.maskDateValue);
|
|
296
|
+
|
|
297
|
+
const maxDate: number = new Date(newDateValue.getFullYear(), newDateValue.getMonth() + 1, 0).getDate();
|
|
298
|
+
if (previousVal.indexOf(newVal) === 0 && (newVal.length === 0 ||
|
|
299
|
+
this.previousHiddenMask[newVal.length - 1] !== this.previousHiddenMask[newVal.length])) {
|
|
300
|
+
for (let i: number = newVal.length; i < previousVal.length; i++) {
|
|
301
|
+
if (this.previousHiddenMask[i as number] !== '' && this.validCharacters.indexOf(this.previousHiddenMask[i as number]) >= 0) {
|
|
302
|
+
this.isDeletion = this.handleDeletion(this.previousHiddenMask[i as number], false);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (this.isDeletion) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
switch (this.previousHiddenMask[start - 1]) {
|
|
310
|
+
case 'd':
|
|
311
|
+
{
|
|
312
|
+
let date: number = (this.isDayPart && newDateValue.getDate().toString().length < 2 &&
|
|
313
|
+
!this.isPersist() ? newDateValue.getDate() * 10 : 0) + parseInt(newVal[start - 1], 10);
|
|
314
|
+
this.isDateZero = (newVal[start - 1] === '0' );
|
|
315
|
+
this.parent.isFocused = this.parent.isFocused ? false : this.parent.isFocused;
|
|
316
|
+
this.navigated = this.navigated ? false : this.navigated;
|
|
317
|
+
if (isNaN(date)) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
for (let i: number = 0; date > maxDate; i++) {
|
|
321
|
+
date = parseInt(date.toString().slice(1), 10);
|
|
322
|
+
}
|
|
323
|
+
if (date >= 1) {
|
|
324
|
+
newDateValue.setDate(date);
|
|
325
|
+
this.isNavigate = date.toString().length === 2;
|
|
326
|
+
this.previousDate = new Date(newDateValue.getFullYear(), newDateValue.getMonth(), newDateValue.getDate());
|
|
327
|
+
if (newDateValue.getMonth() !== this.maskDateValue.getMonth()) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
this.isDayPart = true;
|
|
331
|
+
const maxDaysInMonth: number = new Date(newDateValue.getFullYear(), newDateValue.getMonth() + 1, 0).getDate();
|
|
332
|
+
this.dayTypeCount += (this.dayTypeCount === 0 && (parseInt(date + '0', 10) > maxDaysInMonth)) ? 2 : 1;
|
|
333
|
+
} else {
|
|
334
|
+
this.isDayPart = false;
|
|
335
|
+
if (!(this.dayTypeCount === 1 && this.isDateZero)) {
|
|
336
|
+
this.dayTypeCount += this.isDateZero ? 1 : 0;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
case 'M':
|
|
342
|
+
{
|
|
343
|
+
let month: number;
|
|
344
|
+
if (newDateValue.getMonth().toString().length < 2 && !this.isPersist())
|
|
345
|
+
{
|
|
346
|
+
month = (this.isMonthPart ? (newDateValue.getMonth() + 1) * 10 : 0) + parseInt(newVal[start - 1], 10);
|
|
347
|
+
}
|
|
348
|
+
else
|
|
349
|
+
{
|
|
350
|
+
month = parseInt(newVal[start - 1], 10);
|
|
351
|
+
}
|
|
352
|
+
this.parent.isFocused = this.parent.isFocused ? false : this.parent.isFocused;
|
|
353
|
+
this.navigated = this.navigated ? false : this.navigated;
|
|
354
|
+
this.isMonthZero = (newVal[start - 1] === '0' );
|
|
355
|
+
if (!isNaN(month)) {
|
|
356
|
+
while (month > 12) {
|
|
357
|
+
month = parseInt(month.toString().slice(1), 10);
|
|
358
|
+
}
|
|
359
|
+
if (month >= 1) {
|
|
360
|
+
newDateValue.setMonth(month - 1);
|
|
361
|
+
if (month >= 10 || month === 1) {
|
|
362
|
+
if ( this.isLeadingZero && month === 1) {
|
|
363
|
+
this.isNavigate = month.toString().length === 1;
|
|
364
|
+
this.isLeadingZero = false;
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
this.isNavigate = month.toString().length === 2;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
this.isNavigate = month.toString().length === 1;
|
|
372
|
+
}
|
|
373
|
+
if (newDateValue.getMonth() !== month - 1) {
|
|
374
|
+
newDateValue.setDate(1);
|
|
375
|
+
newDateValue.setMonth(month - 1);
|
|
376
|
+
}
|
|
377
|
+
if (this.isDayPart) {
|
|
378
|
+
const previousMaxDate: number = new Date(this.previousDate.getFullYear(),
|
|
379
|
+
this.previousDate.getMonth() + 1, 0).getDate();
|
|
380
|
+
const currentMaxDate: number = new Date(newDateValue.getFullYear(), newDateValue.getMonth() + 1, 0).getDate();
|
|
381
|
+
if (this.previousDate.getDate() === previousMaxDate && currentMaxDate <= previousMaxDate) {
|
|
382
|
+
newDateValue.setDate(currentMaxDate);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
this.previousDate = new Date(newDateValue.getFullYear(), newDateValue.getMonth(), newDateValue.getDate());
|
|
386
|
+
this.isMonthPart = true;
|
|
387
|
+
this.monthTypeCount = this.monthTypeCount + 1;
|
|
388
|
+
this.isLeadingZero = false;
|
|
389
|
+
} else {
|
|
390
|
+
newDateValue.setMonth(0);
|
|
391
|
+
this.isLeadingZero = true;
|
|
392
|
+
this.isMonthPart = false;
|
|
393
|
+
if (!(this.monthTypeCount === 1 && this.isMonthZero)) {
|
|
394
|
+
this.monthTypeCount += this.isMonthZero ? 1 : 0;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
const monthString: string[] = <string[]>(this.getCulturedValue('months[stand-alone].wide'));
|
|
399
|
+
const monthValue: string[] = Object.keys(monthString);
|
|
400
|
+
this.monthCharacter += newVal[start - 1].toLowerCase();
|
|
401
|
+
while (this.monthCharacter.length > 0) {
|
|
402
|
+
let i: number = 1;
|
|
403
|
+
for (const months of monthValue) {
|
|
404
|
+
if (monthString[i as number].toLowerCase().indexOf(this.monthCharacter) === 0) {
|
|
405
|
+
newDateValue.setMonth(i - 1);
|
|
406
|
+
this.isMonthPart = true;
|
|
407
|
+
this.maskDateValue = newDateValue;
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
i++;
|
|
411
|
+
}
|
|
412
|
+
this.monthCharacter = this.monthCharacter.substring(1, this.monthCharacter.length);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
case 'y':
|
|
418
|
+
{
|
|
419
|
+
let year: number = (this.isYearPart && (newDateValue.getFullYear().toString().length < 4
|
|
420
|
+
&& !this.isShortYear) ? newDateValue.getFullYear() * 10 : 0) + parseInt(newVal[start - 1], 10);
|
|
421
|
+
let yearValue: number = (this.dateformat.match(/y/g) || []).length;
|
|
422
|
+
yearValue = yearValue !== 2 ? 4 : yearValue;
|
|
423
|
+
this.isShortYear = false;
|
|
424
|
+
this.isYearZero = (newVal[start - 1] === '0' );
|
|
425
|
+
if (isNaN(year)) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
while (year > 9999) {
|
|
429
|
+
year = parseInt(year.toString().slice(1), 10);
|
|
430
|
+
}
|
|
431
|
+
if (year < 1) {
|
|
432
|
+
this.isYearPart = false;
|
|
433
|
+
} else {
|
|
434
|
+
newDateValue.setFullYear(year);
|
|
435
|
+
if (year.toString().length === yearValue)
|
|
436
|
+
{
|
|
437
|
+
this.isNavigate = true;
|
|
438
|
+
}
|
|
439
|
+
this.previousDate = new Date(newDateValue.getFullYear(), newDateValue.getMonth(), newDateValue.getDate());
|
|
440
|
+
this.isYearPart = true;
|
|
441
|
+
}
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
case 'h':
|
|
445
|
+
this.hour = (this.isHourPart && (newDateValue.getHours() % 12 || 12).toString().length < 2
|
|
446
|
+
&& !this.isPersist() ? (newDateValue.getHours() % 12 || 12) * 10 : 0) + parseInt(newVal[start - 1], 10);
|
|
447
|
+
this.parent.isFocused = this.parent.isFocused ? false : this.parent.isFocused;
|
|
448
|
+
this.navigated = this.navigated ? false : this.navigated;
|
|
449
|
+
if (isNaN(this.hour)) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
while (this.hour > 12) {
|
|
453
|
+
this.hour = parseInt(this.hour.toString().slice(1), 10);
|
|
454
|
+
}
|
|
455
|
+
newDateValue.setHours(Math.floor(newDateValue.getHours() / 12) * 12 + (this.hour % 12));
|
|
456
|
+
this.isNavigate = this.hour.toString().length === 2;
|
|
457
|
+
this.isHourPart = true;
|
|
458
|
+
this.hourTypeCount = (this.hourTypeCount === 0 && this.hour && (parseInt(this.hour + '0', 10) > 12)) ? 2 : this.hourTypeCount + 1;
|
|
459
|
+
break;
|
|
460
|
+
case 'H':
|
|
461
|
+
this.hour = (this.isHourPart && newDateValue.getHours().toString().length < 2 &&
|
|
462
|
+
!this.isPersist() ? newDateValue.getHours() * 10 : 0) + parseInt(newVal[start - 1], 10);
|
|
463
|
+
this.parent.isFocused = this.parent.isFocused ? false : this.parent.isFocused;
|
|
464
|
+
this.navigated = this.navigated ? false : this.navigated;
|
|
465
|
+
if (isNaN(this.hour)) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
for (let i: number = 0; this.hour > 23; i++) {
|
|
469
|
+
this.hour = parseInt(this.hour.toString().slice(1), 10);
|
|
470
|
+
}
|
|
471
|
+
newDateValue.setHours(this.hour);
|
|
472
|
+
this.isNavigate = this.hour.toString().length === 2;
|
|
473
|
+
this.isHourPart = true;
|
|
474
|
+
this.hourTypeCount = (this.hourTypeCount === 0 && this.hour && (parseInt(this.hour + '0', 10) > 23)) ? 2 : this.hourTypeCount + 1;
|
|
475
|
+
break;
|
|
476
|
+
case 'm':
|
|
477
|
+
{
|
|
478
|
+
let minutes: number = (this.isMinutePart && newDateValue.getMinutes().toString().length < 2
|
|
479
|
+
&& !this.isPersist() ? newDateValue.getMinutes() * 10 : 0) + parseInt(newVal[start - 1], 10);
|
|
480
|
+
this.parent.isFocused = this.parent.isFocused ? false : this.parent.isFocused;
|
|
481
|
+
this.navigated = this.navigated ? false : this.navigated;
|
|
482
|
+
if (isNaN(minutes)) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
for (let i: number = 0; minutes > 59; i++) {
|
|
486
|
+
minutes = parseInt(minutes.toString().slice(1), 10);
|
|
487
|
+
}
|
|
488
|
+
newDateValue.setMinutes(minutes);
|
|
489
|
+
this.isNavigate = minutes.toString().length === 2;
|
|
490
|
+
this.isMinutePart = true;
|
|
491
|
+
this.minuteTypeCount = (this.minuteTypeCount === 0 && (parseInt(minutes + '0', 10) > 59)) ? 2 : this.minuteTypeCount + 1;
|
|
492
|
+
break;
|
|
493
|
+
}
|
|
494
|
+
case 's':
|
|
495
|
+
{
|
|
496
|
+
let seconds: number = (this.isSecondsPart && newDateValue.getSeconds().toString().length < 2 &&
|
|
497
|
+
!this.isPersist() ? newDateValue.getSeconds() * 10 : 0) + parseInt(newVal[start - 1], 10);
|
|
498
|
+
this.parent.isFocused = this.parent.isFocused ? false : this.parent.isFocused;
|
|
499
|
+
this.navigated = this.navigated ? false : this.navigated;
|
|
500
|
+
if (isNaN(seconds)) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
for (let i: number = 0; seconds > 59; i++) {
|
|
504
|
+
seconds = parseInt(seconds.toString().slice(1), 10);
|
|
505
|
+
}
|
|
506
|
+
newDateValue.setSeconds(seconds);
|
|
507
|
+
this.isNavigate = seconds.toString().length === 2;
|
|
508
|
+
this.isSecondsPart = true;
|
|
509
|
+
this.secondTypeCount = (this.secondTypeCount === 0 && (parseInt(seconds + '0', 10) > 59)) ? 2 : this.secondTypeCount + 1;
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
512
|
+
case 'a':
|
|
513
|
+
{
|
|
514
|
+
this.periodCharacter += newVal[start - 1].toLowerCase();
|
|
515
|
+
const periodString: string[] = <string[]>(this.getCulturedValue('dayPeriods.format.wide'));
|
|
516
|
+
const periodkeys: string[] = Object.keys(periodString);
|
|
517
|
+
for (let i: number = 0; this.periodCharacter.length > 0; i++) {
|
|
518
|
+
if ((periodString[periodkeys[0] as unknown as number].toLowerCase().indexOf(this.periodCharacter) === 0
|
|
519
|
+
&& newDateValue.getHours() >= 12) || (periodString[periodkeys[1] as unknown as number].toLowerCase().
|
|
520
|
+
indexOf(this.periodCharacter) === 0 && newDateValue.getHours() < 12)) {
|
|
521
|
+
newDateValue.setHours((newDateValue.getHours() + 12) % 24);
|
|
522
|
+
this.maskDateValue = newDateValue;
|
|
523
|
+
}
|
|
524
|
+
this.periodCharacter = this.periodCharacter.substring(1, this.periodCharacter.length);
|
|
525
|
+
}
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
default:
|
|
529
|
+
break;
|
|
530
|
+
}
|
|
531
|
+
this.maskDateValue = newDateValue;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
535
|
+
private formatCheck(): any {
|
|
536
|
+
const proxy: this = null || this;
|
|
537
|
+
function formatValueSpecifier(formattext: string): string {
|
|
538
|
+
let result: string;
|
|
539
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
540
|
+
const daysAbbreviated: any = proxy.getCulturedValue('days[stand-alone].abbreviated');
|
|
541
|
+
const dayKeyAbbreviated: string[] = Object.keys(daysAbbreviated);
|
|
542
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
543
|
+
const daysWide: any = <string[]>(proxy.getCulturedValue('days[stand-alone].wide'));
|
|
544
|
+
const dayKeyWide: string[] = Object.keys(daysWide);
|
|
545
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
546
|
+
const daysNarrow: any = <string[]>(proxy.getCulturedValue('days[stand-alone].narrow'));
|
|
547
|
+
const dayKeyNarrow: string[] = Object.keys(daysNarrow);
|
|
548
|
+
const monthAbbreviated: string[] = <string[]>(proxy.getCulturedValue('months[stand-alone].abbreviated'));
|
|
549
|
+
const monthWide: string[] = <string[]>(proxy.getCulturedValue('months[stand-alone].wide'));
|
|
550
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
551
|
+
const periodString: any = <string[]>(proxy.getCulturedValue('dayPeriods.format.wide'));
|
|
552
|
+
const periodkeys: string[] = Object.keys(periodString);
|
|
553
|
+
let milliseconds: number;
|
|
554
|
+
let dateOptions: object;
|
|
555
|
+
switch (formattext) {
|
|
556
|
+
case 'ddd':
|
|
557
|
+
case 'dddd':
|
|
558
|
+
case 'd':
|
|
559
|
+
result = proxy.isDayPart ? proxy.maskDateValue.getDate().toString() : proxy.defaultConstant['day'].toString();
|
|
560
|
+
result = proxy.zeroCheck(proxy.isDateZero , proxy.isDayPart , result );
|
|
561
|
+
if (proxy.dayTypeCount === 2)
|
|
562
|
+
{
|
|
563
|
+
proxy.isNavigate = true;
|
|
564
|
+
proxy.dayTypeCount = 0;
|
|
565
|
+
}
|
|
566
|
+
break;
|
|
567
|
+
case 'dd':
|
|
568
|
+
result = proxy.isDayPart ? proxy.roundOff(proxy.maskDateValue.getDate(), 2) : proxy.defaultConstant['day'].toString();
|
|
569
|
+
result = proxy.zeroCheck(proxy.isDateZero , proxy.isDayPart , result );
|
|
570
|
+
if ( proxy.dayTypeCount === 2)
|
|
571
|
+
{
|
|
572
|
+
proxy.isNavigate = true;
|
|
573
|
+
proxy.dayTypeCount = 0;
|
|
574
|
+
}
|
|
575
|
+
break;
|
|
576
|
+
case 'E' :
|
|
577
|
+
case 'EE':
|
|
578
|
+
case 'EEE':
|
|
579
|
+
case 'ccc':
|
|
580
|
+
result = proxy.isDayPart && proxy.isMonthPart && proxy.isYearPart ? daysAbbreviated[dayKeyAbbreviated[proxy.maskDateValue.getDay()]].toString() : proxy.defaultConstant['dayOfTheWeek'].toString();
|
|
581
|
+
break;
|
|
582
|
+
case 'EEEE':
|
|
583
|
+
case 'cccc':
|
|
584
|
+
result = proxy.isDayPart && proxy.isMonthPart && proxy.isYearPart ? daysWide[dayKeyWide[proxy.maskDateValue.getDay()]].toString() : proxy.defaultConstant['dayOfTheWeek'].toString();
|
|
585
|
+
break;
|
|
586
|
+
case 'EEEEE':
|
|
587
|
+
result = proxy.isDayPart && proxy.isMonthPart && proxy.isYearPart ? daysNarrow[dayKeyNarrow[proxy.maskDateValue.getDay()]].toString() : proxy.defaultConstant['dayOfTheWeek'].toString();
|
|
588
|
+
break;
|
|
589
|
+
case 'M':
|
|
590
|
+
result = proxy.isMonthPart ? (proxy.maskDateValue.getMonth() + 1).toString() : proxy.defaultConstant['month'].toString();
|
|
591
|
+
result = proxy.zeroCheck(proxy.isMonthZero , proxy.isMonthPart , result );
|
|
592
|
+
if ( proxy.monthTypeCount === 2)
|
|
593
|
+
{
|
|
594
|
+
proxy.isNavigate = true;
|
|
595
|
+
proxy.monthTypeCount = 0;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
break;
|
|
599
|
+
case 'MM':
|
|
600
|
+
result = proxy.isMonthPart ? proxy.roundOff(proxy.maskDateValue.getMonth() + 1, 2) : proxy.defaultConstant['month'].toString();
|
|
601
|
+
result = proxy.zeroCheck(proxy.isMonthZero , proxy.isMonthPart , result );
|
|
602
|
+
if ( proxy.monthTypeCount === 2)
|
|
603
|
+
{
|
|
604
|
+
proxy.isNavigate = true;
|
|
605
|
+
proxy.monthTypeCount = 0;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
break;
|
|
609
|
+
case 'MMM':
|
|
610
|
+
result = proxy.isMonthPart ? monthAbbreviated[proxy.maskDateValue.getMonth() + 1] : proxy.defaultConstant['month'].toString();
|
|
611
|
+
break;
|
|
612
|
+
case 'MMMM':
|
|
613
|
+
result = proxy.isMonthPart ? monthWide[proxy.maskDateValue.getMonth() + 1] : proxy.defaultConstant['month'].toString();
|
|
614
|
+
break;
|
|
615
|
+
case 'yy':
|
|
616
|
+
result = proxy.isYearPart ? proxy.roundOff(proxy.maskDateValue.getFullYear() % 100, 2) : proxy.defaultConstant['year'].toString();
|
|
617
|
+
result = proxy.zeroCheck(proxy.isYearZero , proxy.isYearPart , result );
|
|
618
|
+
break;
|
|
619
|
+
case 'y':
|
|
620
|
+
case 'yyy':
|
|
621
|
+
case 'yyyy':
|
|
622
|
+
result = proxy.isYearPart ? proxy.roundOff(proxy.maskDateValue.getFullYear(), 4) : proxy.defaultConstant['year'].toString();
|
|
623
|
+
result = proxy.zeroCheck(proxy.isYearZero , proxy.isYearPart , result );
|
|
624
|
+
break;
|
|
625
|
+
case 'h':
|
|
626
|
+
result = proxy.isHourPart ? (proxy.maskDateValue.getHours() % 12 || 12).toString() : proxy.defaultConstant['hour'].toString();
|
|
627
|
+
if ( proxy.hourTypeCount === 2)
|
|
628
|
+
{
|
|
629
|
+
proxy.isNavigate = true;
|
|
630
|
+
proxy.hourTypeCount = 0;
|
|
631
|
+
}
|
|
632
|
+
break;
|
|
633
|
+
case 'hh':
|
|
634
|
+
result = proxy.isHourPart ? proxy.roundOff(proxy.maskDateValue.getHours() % 12 || 12, 2) : proxy.defaultConstant['hour'].toString();
|
|
635
|
+
if ( proxy.hourTypeCount === 2)
|
|
636
|
+
{
|
|
637
|
+
proxy.isNavigate = true;
|
|
638
|
+
proxy.hourTypeCount = 0;
|
|
639
|
+
}
|
|
640
|
+
break;
|
|
641
|
+
case 'H':
|
|
642
|
+
result = proxy.isHourPart ? proxy.maskDateValue.getHours().toString() : proxy.defaultConstant['hour'].toString();
|
|
643
|
+
if ( proxy.hourTypeCount === 2)
|
|
644
|
+
{
|
|
645
|
+
proxy.isNavigate = true;
|
|
646
|
+
proxy.hourTypeCount = 0;
|
|
647
|
+
}
|
|
648
|
+
break;
|
|
649
|
+
case 'HH':
|
|
650
|
+
result = proxy.isHourPart ? proxy.roundOff(proxy.maskDateValue.getHours(), 2) : proxy.defaultConstant['hour'].toString() ;
|
|
651
|
+
if ( proxy.hourTypeCount === 2)
|
|
652
|
+
{
|
|
653
|
+
proxy.isNavigate = true;
|
|
654
|
+
proxy.hourTypeCount = 0;
|
|
655
|
+
}
|
|
656
|
+
break;
|
|
657
|
+
case 'm':
|
|
658
|
+
result = proxy.isMinutePart ? proxy.maskDateValue.getMinutes().toString() : proxy.defaultConstant['minute'].toString() ;
|
|
659
|
+
if ( proxy.minuteTypeCount === 2)
|
|
660
|
+
{
|
|
661
|
+
proxy.isNavigate = true;
|
|
662
|
+
proxy.minuteTypeCount = 0;
|
|
663
|
+
}
|
|
664
|
+
break;
|
|
665
|
+
case 'mm':
|
|
666
|
+
result = proxy.isMinutePart ? proxy.roundOff(proxy.maskDateValue.getMinutes(), 2) : proxy.defaultConstant['minute'].toString() ;
|
|
667
|
+
if ( proxy.minuteTypeCount === 2)
|
|
668
|
+
{
|
|
669
|
+
proxy.isNavigate = true;
|
|
670
|
+
proxy.minuteTypeCount = 0;
|
|
671
|
+
}
|
|
672
|
+
break;
|
|
673
|
+
case 's':
|
|
674
|
+
result = proxy.isSecondsPart ? proxy.maskDateValue.getSeconds().toString() : proxy.defaultConstant['second'].toString() ;
|
|
675
|
+
if ( proxy.secondTypeCount === 2)
|
|
676
|
+
{
|
|
677
|
+
proxy.isNavigate = true;
|
|
678
|
+
proxy.secondTypeCount = 0;
|
|
679
|
+
}
|
|
680
|
+
break;
|
|
681
|
+
case 'ss':
|
|
682
|
+
result = proxy.isSecondsPart ? proxy.roundOff(proxy.maskDateValue.getSeconds(), 2) : proxy.defaultConstant['second'].toString();
|
|
683
|
+
if ( proxy.secondTypeCount === 2)
|
|
684
|
+
{
|
|
685
|
+
proxy.isNavigate = true;
|
|
686
|
+
proxy.secondTypeCount = 0;
|
|
687
|
+
}
|
|
688
|
+
break;
|
|
689
|
+
case 'f':
|
|
690
|
+
result = Math.floor(proxy.maskDateValue.getMilliseconds() / 100).toString();
|
|
691
|
+
break;
|
|
692
|
+
case 'ff':
|
|
693
|
+
milliseconds = proxy.maskDateValue.getMilliseconds();
|
|
694
|
+
if (proxy.maskDateValue.getMilliseconds() > 99) {
|
|
695
|
+
milliseconds = Math.floor(proxy.maskDateValue.getMilliseconds() / 10);
|
|
696
|
+
}
|
|
697
|
+
result = proxy.roundOff(milliseconds, 2);
|
|
698
|
+
break;
|
|
699
|
+
case 'fff':
|
|
700
|
+
result = proxy.roundOff(proxy.maskDateValue.getMilliseconds(), 3);
|
|
701
|
+
break;
|
|
702
|
+
case 'a':
|
|
703
|
+
case 'aa':
|
|
704
|
+
result = proxy.maskDateValue.getHours() < 12 ? periodString['am'] : periodString['pm'] ;
|
|
705
|
+
break;
|
|
706
|
+
case 'z':
|
|
707
|
+
case 'zz':
|
|
708
|
+
case 'zzz':
|
|
709
|
+
case 'zzzz':
|
|
710
|
+
dateOptions = {
|
|
711
|
+
format: formattext,
|
|
712
|
+
type: 'dateTime', skeleton: 'yMd', calendar: proxy.parent.calendarMode
|
|
713
|
+
};
|
|
714
|
+
result = proxy.parent.globalize.formatDate(proxy.maskDateValue, dateOptions);
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
result = result !== undefined ? result : formattext.slice(1, formattext.length - 1);
|
|
718
|
+
if (proxy.isHiddenMask) {
|
|
719
|
+
let hiddenChar: string = '';
|
|
720
|
+
for (let i: number = 0; i < result.length; i++) {
|
|
721
|
+
hiddenChar += formattext[0];
|
|
722
|
+
}
|
|
723
|
+
return hiddenChar;
|
|
724
|
+
} else {
|
|
725
|
+
return result;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
return formatValueSpecifier;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
private isValidDate(dateString: string): boolean {
|
|
732
|
+
const date: Date = new Date(dateString);
|
|
733
|
+
// Return true if the date is valid, false otherwise
|
|
734
|
+
return !isNaN(date.getTime());
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
private maskPasteInputHandler(): void {
|
|
738
|
+
if (this.isValidDate(this.parent.inputElement.value)) {
|
|
739
|
+
this.maskDateValue = new Date(this.parent.inputElement.value);
|
|
740
|
+
this.isDayPart = this.isMonthPart = this.isYearPart = this.isHourPart = this.isMinutePart = this.isSecondsPart = true;
|
|
741
|
+
this.updateValue();
|
|
742
|
+
if (!this.isBlur) {
|
|
743
|
+
this.validCharacterCheck();
|
|
744
|
+
}
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
else {
|
|
748
|
+
this.maskInputHandler();
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
private maskInputHandler(): void {
|
|
753
|
+
let start: number = this.parent.inputElement.selectionStart;
|
|
754
|
+
let formatText: string = '';
|
|
755
|
+
if (this.validCharacters.indexOf(this.hiddenMask[start as number]) !== -1) {
|
|
756
|
+
formatText = this.hiddenMask[start as number];
|
|
757
|
+
}
|
|
758
|
+
this.differenceCheck();
|
|
759
|
+
const inputValue: string = this.dateformat.replace(this.formatRegex, this.formatCheck());
|
|
760
|
+
this.isHiddenMask = true;
|
|
761
|
+
this.hiddenMask = this.dateformat.replace(this.formatRegex, this.formatCheck());
|
|
762
|
+
this.isDateZero = this.isMonthZero = this.isYearZero = false;
|
|
763
|
+
this.isHiddenMask = false;
|
|
764
|
+
this.previousHiddenMask = this.hiddenMask;
|
|
765
|
+
this.previousValue = inputValue;
|
|
766
|
+
this.parent.inputElement.value = inputValue;
|
|
767
|
+
for (let i: number = 0; i < this.hiddenMask.length; i++){
|
|
768
|
+
if (formatText === this.hiddenMask[i as number]){
|
|
769
|
+
start = i;
|
|
770
|
+
break;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
let scrollPositionY: number;
|
|
774
|
+
if (Browser.isDevice && (Browser.isIos || Browser.isIos7)) {
|
|
775
|
+
const scrollableParent: HTMLElement | null = this.findScrollableParent(this.parent.inputElement);
|
|
776
|
+
scrollPositionY = scrollableParent ? scrollableParent.getBoundingClientRect().top : window.scrollY;
|
|
777
|
+
}
|
|
778
|
+
this.parent.inputElement.selectionStart = start;
|
|
779
|
+
this.validCharacterCheck();
|
|
780
|
+
if ((this.isNavigate || this.isDeletion) && !this.isDeleteKey ) {
|
|
781
|
+
const isbackward: boolean = this.isNavigate ? false : true;
|
|
782
|
+
this.isNavigate = this.isDeletion = false;
|
|
783
|
+
this.navigateSelection(isbackward);
|
|
784
|
+
if (Browser.isDevice && (Browser.isIos || Browser.isIos7)) {
|
|
785
|
+
setTimeout(() => {
|
|
786
|
+
window.scrollTo(0, scrollPositionY);
|
|
787
|
+
}, 0);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
if (this.isDeleteKey)
|
|
791
|
+
{
|
|
792
|
+
this.isDeletion = false;
|
|
793
|
+
}
|
|
794
|
+
this.isDeleteKey = false;
|
|
795
|
+
}
|
|
796
|
+
private findScrollableParent(element: HTMLElement | null): HTMLElement | null {
|
|
797
|
+
while (element) {
|
|
798
|
+
if (this.isScrollable(element)) {
|
|
799
|
+
return element;
|
|
800
|
+
}
|
|
801
|
+
element = element.parentElement;
|
|
802
|
+
}
|
|
803
|
+
return null;
|
|
804
|
+
}
|
|
805
|
+
private isScrollable(element: HTMLElement): boolean {
|
|
806
|
+
const overflowY: string = window.getComputedStyle(element).overflowY;
|
|
807
|
+
return element.scrollHeight > element.clientHeight && (overflowY === 'auto' || overflowY === 'scroll');
|
|
808
|
+
}
|
|
809
|
+
private navigateSelection(isbackward : boolean): void {
|
|
810
|
+
const start: number = this.parent.inputElement.selectionStart;
|
|
811
|
+
const end: number = this.parent.inputElement.selectionEnd;
|
|
812
|
+
let formatIndex: number = isbackward ? start - 1 : end;
|
|
813
|
+
this.navigated = true;
|
|
814
|
+
while (formatIndex < this.hiddenMask.length && formatIndex >= 0) {
|
|
815
|
+
if (this.validCharacters.indexOf(this.hiddenMask[formatIndex as number]) >= 0) {
|
|
816
|
+
this.setSelection(this.hiddenMask[formatIndex as number]);
|
|
817
|
+
break;
|
|
818
|
+
}
|
|
819
|
+
formatIndex = formatIndex + (isbackward ? -1 : 1);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
private roundOff(val : number, count : number): string {
|
|
823
|
+
const valueText: string = val.toString();
|
|
824
|
+
const length: number = count - valueText.length;
|
|
825
|
+
let result: string = '';
|
|
826
|
+
for (let i: number = 0; i < length; i++) {
|
|
827
|
+
result += '0';
|
|
828
|
+
}
|
|
829
|
+
return result + valueText;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
private zeroCheck(isZero: boolean , isDayPart: boolean, resultValue: string): string {
|
|
833
|
+
let result: string = resultValue;
|
|
834
|
+
if (isZero && !isDayPart)
|
|
835
|
+
{
|
|
836
|
+
result = '0';
|
|
837
|
+
}
|
|
838
|
+
return result;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
private handleDeletion(format : string, isSegment : boolean): boolean {
|
|
843
|
+
switch (format) {
|
|
844
|
+
case 'd':
|
|
845
|
+
this.isDayPart = isSegment;
|
|
846
|
+
break;
|
|
847
|
+
case 'M':
|
|
848
|
+
this.isMonthPart = isSegment;
|
|
849
|
+
if (!isSegment) {
|
|
850
|
+
this.maskDateValue.setMonth(0);
|
|
851
|
+
this.monthCharacter = '';
|
|
852
|
+
}
|
|
853
|
+
break;
|
|
854
|
+
case 'y':
|
|
855
|
+
this.isYearPart = isSegment;
|
|
856
|
+
break;
|
|
857
|
+
case 'H':
|
|
858
|
+
case 'h':
|
|
859
|
+
this.isHourPart = isSegment;
|
|
860
|
+
if (!isSegment) {
|
|
861
|
+
this.periodCharacter = '';
|
|
862
|
+
}
|
|
863
|
+
break;
|
|
864
|
+
case 'm':
|
|
865
|
+
this.isMinutePart = isSegment;
|
|
866
|
+
break;
|
|
867
|
+
case 's':
|
|
868
|
+
this.isSecondsPart = isSegment;
|
|
869
|
+
break;
|
|
870
|
+
default:
|
|
871
|
+
return false;
|
|
872
|
+
}
|
|
873
|
+
return true;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
private dateAlteration(isDecrement : boolean): void {
|
|
877
|
+
const start: number = this.parent.inputElement.selectionStart;
|
|
878
|
+
let formatText: string = '';
|
|
879
|
+
if (this.validCharacters.indexOf(this.hiddenMask[start as number]) !== -1) {
|
|
880
|
+
formatText = this.hiddenMask[start as number];
|
|
881
|
+
} else {
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
const newDateValue: Date = new Date(this.maskDateValue.getFullYear(), this.maskDateValue.getMonth(),
|
|
885
|
+
this.maskDateValue.getDate(), this.maskDateValue.getHours(),
|
|
886
|
+
this.maskDateValue.getMinutes(), this.maskDateValue.getSeconds());
|
|
887
|
+
this.previousDate = new Date(this.maskDateValue.getFullYear(), this.maskDateValue.getMonth(),
|
|
888
|
+
this.maskDateValue.getDate(), this.maskDateValue.getHours(),
|
|
889
|
+
this.maskDateValue.getMinutes(), this.maskDateValue.getSeconds());
|
|
890
|
+
const incrementValue: number = isDecrement ? -1 : 1;
|
|
891
|
+
switch (formatText) {
|
|
892
|
+
case 'd':
|
|
893
|
+
newDateValue.setDate(newDateValue.getDate() + incrementValue);
|
|
894
|
+
break;
|
|
895
|
+
case 'M':
|
|
896
|
+
{
|
|
897
|
+
const newMonth: number = newDateValue.getMonth() + incrementValue;
|
|
898
|
+
newDateValue.setDate(1);
|
|
899
|
+
newDateValue.setMonth(newMonth);
|
|
900
|
+
if (this.isDayPart) {
|
|
901
|
+
const previousMaxDate: number = new Date(this.previousDate.getFullYear(), this.previousDate.getMonth() + 1, 0).getDate();
|
|
902
|
+
const currentMaxDate: number = new Date(newDateValue.getFullYear(), newDateValue.getMonth() + 1, 0).getDate();
|
|
903
|
+
if (this.previousDate.getDate() === previousMaxDate && currentMaxDate <= previousMaxDate) {
|
|
904
|
+
newDateValue.setDate(currentMaxDate);
|
|
905
|
+
}
|
|
906
|
+
else
|
|
907
|
+
{
|
|
908
|
+
newDateValue.setDate(this.previousDate.getDate());
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
else
|
|
912
|
+
{
|
|
913
|
+
newDateValue.setDate(this.previousDate.getDate());
|
|
914
|
+
}
|
|
915
|
+
this.previousDate = new Date(newDateValue.getFullYear(), newDateValue.getMonth(), newDateValue.getDate());
|
|
916
|
+
break;
|
|
917
|
+
}
|
|
918
|
+
case 'y':
|
|
919
|
+
newDateValue.setFullYear(newDateValue.getFullYear() + incrementValue);
|
|
920
|
+
break;
|
|
921
|
+
case 'H':
|
|
922
|
+
case 'h':
|
|
923
|
+
newDateValue.setHours(newDateValue.getHours() + incrementValue);
|
|
924
|
+
break;
|
|
925
|
+
case 'm':
|
|
926
|
+
newDateValue.setMinutes(newDateValue.getMinutes() + incrementValue);
|
|
927
|
+
break;
|
|
928
|
+
case 's':
|
|
929
|
+
newDateValue.setSeconds(newDateValue.getSeconds() + incrementValue);
|
|
930
|
+
break;
|
|
931
|
+
case 'a':
|
|
932
|
+
newDateValue.setHours((newDateValue.getHours() + 12) % 24);
|
|
933
|
+
break;
|
|
934
|
+
default:
|
|
935
|
+
break;
|
|
936
|
+
}
|
|
937
|
+
this.maskDateValue = newDateValue.getFullYear() > 0 ? newDateValue : this.maskDateValue;
|
|
938
|
+
if (this.validCharacters.indexOf(this.hiddenMask[start as number]) !== -1) {
|
|
939
|
+
this.handleDeletion(this.hiddenMask[start as number], true);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
private getCulturedValue(format : string): object {
|
|
943
|
+
const locale: string = this.parent.locale;
|
|
944
|
+
let result: object;
|
|
945
|
+
if (locale === 'en' || locale === 'en-US') {
|
|
946
|
+
result = getValue(format, getDefaultDateObject());
|
|
947
|
+
} else {
|
|
948
|
+
result = getValue('main.' + '' + locale + ('.dates.calendars.gregorian.' + format), cldrData);
|
|
949
|
+
}
|
|
950
|
+
return result;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
private getCulturedFormat(): string{
|
|
954
|
+
let formatString: string = (this.getCulturedValue('dateTimeFormats[availableFormats].yMd')).toString();
|
|
955
|
+
if (this.parent.moduleName === 'datepicker')
|
|
956
|
+
{
|
|
957
|
+
formatString = (this.getCulturedValue('dateTimeFormats[availableFormats].yMd')).toString();
|
|
958
|
+
if (this.parent.format && this.parent.formatString)
|
|
959
|
+
{
|
|
960
|
+
formatString = this.parent.formatString;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
if (this.parent.moduleName === 'datetimepicker')
|
|
964
|
+
{
|
|
965
|
+
formatString = (this.getCulturedValue('dateTimeFormats[availableFormats].yMd')).toString();
|
|
966
|
+
if (this.parent.dateTimeFormat)
|
|
967
|
+
{
|
|
968
|
+
formatString = this.parent.dateTimeFormat;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
if (this.parent.moduleName === 'timepicker')
|
|
972
|
+
{
|
|
973
|
+
formatString = this.parent.cldrTimeFormat();
|
|
974
|
+
}
|
|
975
|
+
return formatString;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
private clearHandler(): void {
|
|
979
|
+
|
|
980
|
+
this.isDayPart = this.isMonthPart = this.isYearPart = this.isHourPart = this.isMinutePart = this.isSecondsPart = false;
|
|
981
|
+
this.updateValue();
|
|
982
|
+
if (this.parent.inputElement && this.parent.inputElement.value === this.parent.maskedDateValue && this.parent.inputWrapper && this.parent.inputWrapper.clearButton && !this.parent.inputWrapper.clearButton.classList.contains('e-clear-icon-hide')) {
|
|
983
|
+
this.parent.inputWrapper.clearButton.classList.add('e-clear-icon-hide');
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
private updateValue(): void {
|
|
988
|
+
this.monthCharacter = this.periodCharacter = '';
|
|
989
|
+
const inputValue: string = this.dateformat.replace(this.formatRegex, this.formatCheck());
|
|
990
|
+
this.isHiddenMask = true;
|
|
991
|
+
this.hiddenMask = this.dateformat.replace(this.formatRegex, this.formatCheck());
|
|
992
|
+
this.isHiddenMask = false;
|
|
993
|
+
this.previousHiddenMask = this.hiddenMask;
|
|
994
|
+
this.previousValue = inputValue;
|
|
995
|
+
this.parent.updateInputValue(inputValue);
|
|
996
|
+
if (this.parent.strictMode && (this.dayTypeCount !== 0 || this.monthTypeCount !== 0)) {
|
|
997
|
+
this.isLeadingZero = false;
|
|
998
|
+
}
|
|
999
|
+
this.dayTypeCount = 0;
|
|
1000
|
+
this.monthTypeCount = 0;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
public destroy(): void {
|
|
1004
|
+
this.removeEventListener();
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
export interface events {
|
|
1009
|
+
module: string;
|
|
1010
|
+
e: KeyboardEventArgs;
|
|
1011
|
+
isBlur: boolean;
|
|
1012
|
+
}
|
|
1013
|
+
|