@syncfusion/ej2-base 24.2.8 → 25.1.35-579988
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 +2 -1
- package/CHANGELOG.md +641 -677
- package/{README.md → ReadMe.md} +100 -100
- package/dist/ej2-base.umd.min.js +1 -10
- package/dist/ej2-base.umd.min.js.map +1 -1
- package/dist/es6/ej2-base.es2015.js +178 -1025
- package/dist/es6/ej2-base.es2015.js.map +1 -1
- package/dist/es6/ej2-base.es5.js +226 -934
- package/dist/es6/ej2-base.es5.js.map +1 -1
- package/dist/global/ej2-base.min.js +1 -10
- package/dist/global/ej2-base.min.js.map +1 -1
- package/dist/global/index.d.ts +0 -9
- package/dist/ts/ajax.ts +236 -0
- package/dist/ts/animation.ts +544 -0
- package/dist/ts/base.ts +357 -0
- package/dist/ts/browser.ts +387 -0
- package/dist/ts/child-property.ts +192 -0
- package/dist/ts/component.ts +519 -0
- package/dist/ts/dom.ts +488 -0
- package/dist/ts/draggable.ts +1155 -0
- package/dist/ts/droppable.ts +172 -0
- package/dist/ts/event-handler.ts +169 -0
- package/dist/ts/internationalization.ts +369 -0
- package/dist/ts/intl/date-formatter.ts +317 -0
- package/dist/ts/intl/date-parser.ts +426 -0
- package/dist/ts/intl/intl-base.ts +1104 -0
- package/dist/ts/intl/number-formatter.ts +411 -0
- package/dist/ts/intl/number-parser.ts +158 -0
- package/dist/ts/intl/parser-base.ts +394 -0
- package/dist/ts/keyboard.ts +238 -0
- package/dist/ts/l10n.ts +94 -0
- package/dist/ts/module-loader.ts +149 -0
- package/dist/ts/notify-property-change.ts +726 -0
- package/dist/ts/observer.ts +236 -0
- package/dist/ts/sanitize-helper.ts +224 -0
- package/dist/ts/template-engine.ts +191 -0
- package/dist/ts/template.ts +329 -0
- package/dist/ts/touch.ts +544 -0
- package/dist/ts/util.ts +523 -0
- package/dist/ts/validate-lic.ts +0 -0
- package/e2e/crypto.js +16 -16
- package/e2e/m.protractor.config.js +286 -286
- package/e2e/modified-protractor/protractor.config.js +316 -316
- package/e2e/protractor.config.js +389 -332
- package/helpers/e2e/index.js +3 -3
- package/license +10 -10
- package/package.json +225 -174
- package/src/ajax.d.ts +1 -1
- package/src/ajax.js +3 -8
- package/src/animation-model.d.ts +41 -41
- package/src/animation.d.ts +6 -6
- package/src/animation.js +25 -25
- package/src/base.d.ts +2 -1
- package/src/base.js +9 -7
- package/src/component-model.d.ts +16 -16
- package/src/component.d.ts +9 -3
- package/src/component.js +50 -38
- package/src/draggable-model.d.ts +113 -113
- package/src/draggable.d.ts +2 -0
- package/src/draggable.js +45 -29
- package/src/droppable-model.d.ts +23 -23
- package/src/droppable.js +19 -19
- package/src/event-handler.js +2 -1
- package/src/index.d.ts +0 -3
- package/src/index.js +0 -3
- package/src/intl/date-formatter.js +2 -6
- package/src/intl/date-parser.js +1 -20
- package/src/intl/intl-base.js +1 -164
- package/src/intl/number-formatter.d.ts +3 -0
- package/src/intl/number-formatter.js +7 -7
- package/src/intl/number-parser.js +1 -0
- package/src/keyboard-model.d.ts +16 -16
- package/src/keyboard.js +19 -19
- package/src/module-loader.d.ts +12 -0
- package/src/module-loader.js +11 -0
- package/src/notify-property-change.js +3 -2
- package/src/observer.js +2 -0
- package/src/sanitize-helper.js +5 -0
- package/src/template-engine.js +1 -0
- package/src/template.js +3 -2
- package/src/touch-model.d.ts +39 -39
- package/src/touch.js +19 -19
- package/src/validate-lic.d.ts +0 -11
- package/src/validate-lic.js +1 -259
- package/styles/_all.scss +2 -2
- package/styles/_bds-dark-definition.scss +15 -0
- package/styles/_bds-definition.scss +15 -0
- package/styles/_bootstrap-dark-definition.scss +42 -42
- package/styles/_bootstrap-definition.scss +42 -42
- package/styles/_bootstrap4-definition.scss +11 -11
- package/styles/_bootstrap5-dark-definition.scss +9 -9
- package/styles/_bootstrap5-definition.scss +8 -8
- package/styles/_fabric-dark-definition.scss +42 -42
- package/styles/_fabric-definition.scss +42 -42
- package/styles/_fluent-dark-definition.scss +9 -9
- package/styles/_fluent-definition.scss +9 -9
- package/styles/_fluent2-definition.scss +9 -0
- package/styles/_fusionnew-dark-definition.scss +8 -8
- package/styles/_fusionnew-definition.scss +8 -8
- package/styles/_highcontrast-definition.scss +42 -42
- package/styles/_highcontrast-light-definition.scss +42 -42
- package/styles/_material-dark-definition.scss +48 -48
- package/styles/_material-definition.scss +49 -49
- package/styles/_material3-dark-definition.scss +14 -14
- package/styles/_material3-definition.scss +15 -15
- package/styles/_tailwind-dark-definition.scss +15 -15
- package/styles/_tailwind-definition.scss +15 -15
- package/styles/animation/_all.scss +560 -560
- package/styles/bootstrap-dark.css +10 -1
- package/styles/bootstrap.css +10 -1
- package/styles/bootstrap4.css +10 -1
- package/styles/bootstrap5-dark.css +10 -1
- package/styles/bootstrap5.css +10 -1
- package/styles/common/_all.scss +2 -2
- package/styles/common/_core.scss +117 -117
- package/styles/common/_mixin.scss +9 -9
- package/styles/definition/_bds-dark.scss +1179 -0
- package/styles/definition/_bds.scss +1474 -0
- package/styles/definition/_bootstrap-dark.scss +219 -219
- package/styles/definition/_bootstrap.scss +215 -215
- package/styles/definition/_bootstrap4.scss +167 -167
- package/styles/definition/_bootstrap5-dark.scss +493 -493
- package/styles/definition/_bootstrap5.scss +494 -494
- package/styles/definition/_fabric-dark.scss +200 -200
- package/styles/definition/_fabric.scss +198 -198
- package/styles/definition/_fluent-dark.scss +557 -557
- package/styles/definition/_fluent.scss +558 -558
- package/styles/definition/_fluent2.scss +2198 -0
- package/styles/definition/_fusionnew-dark.scss +362 -362
- package/styles/definition/_fusionnew.scss +363 -363
- package/styles/definition/_highcontrast-light.scss +193 -193
- package/styles/definition/_highcontrast.scss +195 -195
- package/styles/definition/_material-dark.scss +198 -198
- package/styles/definition/_material.scss +192 -192
- package/styles/definition/_material3-dark.scss +710 -710
- package/styles/definition/_material3.scss +792 -792
- package/styles/definition/_tailwind-dark.scss +488 -488
- package/styles/definition/_tailwind.scss +485 -485
- package/styles/fabric-dark.css +10 -1
- package/styles/fabric.css +10 -1
- package/styles/fluent-dark.css +10 -1
- package/styles/fluent.css +10 -1
- package/styles/highcontrast-light.css +10 -1
- package/styles/highcontrast.css +10 -1
- package/styles/material-dark.css +10 -1
- package/styles/material.css +10 -1
- package/styles/material3-dark.css +10 -1
- package/styles/material3.css +10 -1
- package/styles/offline-theme/material-dark.css +10 -1
- package/styles/offline-theme/material.css +10 -1
- package/styles/offline-theme/tailwind-dark.css +10 -1
- package/styles/offline-theme/tailwind.css +10 -1
- package/styles/tailwind-dark.css +10 -1
- package/styles/tailwind.css +10 -1
- package/.github/PULL_REQUEST_TEMPLATE/Bug.md +0 -60
- package/.github/PULL_REQUEST_TEMPLATE/feature.md +0 -42
- package/bin/syncfusion-license.js +0 -2
- package/dist/ej2-base.min.js +0 -10
- package/e2e/index.d.ts +0 -27
- package/src/fetch.d.ts +0 -114
- package/src/fetch.js +0 -116
- package/src/hijri-parser.d.ts +0 -19
- package/src/hijri-parser.js +0 -204
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import { DateFormatOptions } from '../internationalization';
|
|
2
|
+
import { IntlBase as base } from './intl-base';
|
|
3
|
+
import { ParserBase as parser, NumericOptions, NumberMapper } from './parser-base';
|
|
4
|
+
import { isUndefined, throwError, getValue, isNullOrUndefined, isBlazor } from '../util';
|
|
5
|
+
import { datePartMatcher } from './date-formatter';
|
|
6
|
+
const standalone: string = 'stand-alone';
|
|
7
|
+
const latnRegex: RegExp = /^[0-9]*$/;
|
|
8
|
+
const timeSetter: Object = {
|
|
9
|
+
minute: 'setMinutes',
|
|
10
|
+
hour: 'setHours',
|
|
11
|
+
second: 'setSeconds',
|
|
12
|
+
day: 'setDate',
|
|
13
|
+
month: 'setMonth',
|
|
14
|
+
milliseconds: 'setMilliseconds'
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Interface for date parsing options
|
|
18
|
+
*/
|
|
19
|
+
interface ParseOptions {
|
|
20
|
+
month?: Object;
|
|
21
|
+
weekday?: string[];
|
|
22
|
+
pattern?: string;
|
|
23
|
+
designator?: Object;
|
|
24
|
+
timeZone?: base.TimeZoneOptions;
|
|
25
|
+
era?: Object;
|
|
26
|
+
hour12?: boolean;
|
|
27
|
+
parserRegex?: RegExp;
|
|
28
|
+
evalposition?: { [key: string]: ValuePosition };
|
|
29
|
+
isIslamic?: boolean;
|
|
30
|
+
culture?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Interface for the date options
|
|
35
|
+
*/
|
|
36
|
+
interface DateParts {
|
|
37
|
+
month?: number;
|
|
38
|
+
day?: number;
|
|
39
|
+
year?: number;
|
|
40
|
+
hour?: number;
|
|
41
|
+
minute?: number;
|
|
42
|
+
second?: number;
|
|
43
|
+
designator?: string;
|
|
44
|
+
timeZone?: number;
|
|
45
|
+
hour12?: boolean;
|
|
46
|
+
}
|
|
47
|
+
const month: string = 'months';
|
|
48
|
+
/**
|
|
49
|
+
* Interface for value position
|
|
50
|
+
*/
|
|
51
|
+
interface ValuePosition {
|
|
52
|
+
isNumber: boolean;
|
|
53
|
+
pos: number;
|
|
54
|
+
hourOnly?: boolean;
|
|
55
|
+
}
|
|
56
|
+
/* tslint:disable no-any */
|
|
57
|
+
/**
|
|
58
|
+
* Date Parser.
|
|
59
|
+
*
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
export class DateParser {
|
|
64
|
+
/**
|
|
65
|
+
* Returns the parser function for given skeleton.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} culture - Specifies the culture name to be which formatting.
|
|
68
|
+
* @param {DateFormatOptions} option - Specific the format in which string date will be parsed.
|
|
69
|
+
* @param {Object} cldr - Specifies the global cldr data collection.
|
|
70
|
+
* @returns {Function} ?
|
|
71
|
+
*/
|
|
72
|
+
public static dateParser(culture: string, option: DateFormatOptions, cldr: Object): Function {
|
|
73
|
+
const dependable: base.Dependables = base.getDependables(cldr, culture, option.calendar);
|
|
74
|
+
const numOptions: NumericOptions =
|
|
75
|
+
parser.getCurrentNumericOptions(dependable.parserObject, parser.getNumberingSystem(cldr), false, isBlazor());
|
|
76
|
+
let parseOptions: ParseOptions = {};
|
|
77
|
+
if (isBlazor() && option.isServerRendered) {
|
|
78
|
+
option = base.compareBlazorDateFormats(option, culture);
|
|
79
|
+
}
|
|
80
|
+
let resPattern: string = option.format ||
|
|
81
|
+
base.getResultantPattern(option.skeleton, dependable.dateObject, option.type, false, isBlazor() ? culture : '');
|
|
82
|
+
let regexString: string = '';
|
|
83
|
+
let hourOnly: boolean;
|
|
84
|
+
if (isUndefined(resPattern)) {
|
|
85
|
+
throwError('Format options or type given must be invalid');
|
|
86
|
+
} else {
|
|
87
|
+
resPattern = base.ConvertDateToWeekFormat(resPattern);
|
|
88
|
+
parseOptions = { isIslamic: base.islamicRegex.test(option.calendar), pattern: resPattern, evalposition: {}, culture: culture };
|
|
89
|
+
const patternMatch: string[] = resPattern.match(base.dateParseRegex) || [];
|
|
90
|
+
const length: number = patternMatch.length;
|
|
91
|
+
let gmtCorrection: number = 0;
|
|
92
|
+
let zCorrectTemp: number = 0;
|
|
93
|
+
let isgmtTraversed: boolean = false;
|
|
94
|
+
const nRegx: string = numOptions.numericRegex;
|
|
95
|
+
// eslint-disable-next-line
|
|
96
|
+
let numMapper: NumberMapper = isBlazor() ? (dependable.parserObject as any).numbers :
|
|
97
|
+
parser.getNumberMapper(dependable.parserObject, parser.getNumberingSystem(cldr));
|
|
98
|
+
for (let i: number = 0; i < length; i++) {
|
|
99
|
+
const str: string = patternMatch[parseInt(i.toString(), 10)];
|
|
100
|
+
const len: number = str.length;
|
|
101
|
+
const char: string = (str[0] === 'K') ? 'h' : str[0];
|
|
102
|
+
let isNumber: boolean;
|
|
103
|
+
let canUpdate: boolean;
|
|
104
|
+
// eslint-disable-next-line
|
|
105
|
+
let charKey: any = datePartMatcher[char];
|
|
106
|
+
const optional: string = (len === 2) ? '' : '?';
|
|
107
|
+
if (isgmtTraversed) {
|
|
108
|
+
gmtCorrection = zCorrectTemp;
|
|
109
|
+
isgmtTraversed = false;
|
|
110
|
+
}
|
|
111
|
+
switch (char) {
|
|
112
|
+
case 'E':
|
|
113
|
+
case 'c':
|
|
114
|
+
// eslint-disable-next-line
|
|
115
|
+
let weekData: Object;
|
|
116
|
+
if (isBlazor()) {
|
|
117
|
+
// eslint-disable-next-line
|
|
118
|
+
weekData = getValue('days.' + (base as any).monthIndex[len], dependable.dateObject);
|
|
119
|
+
} else {
|
|
120
|
+
// eslint-disable-next-line
|
|
121
|
+
weekData = (<any>dependable.dateObject)[base.days][standalone][(<any>base).monthIndex[len]];
|
|
122
|
+
}
|
|
123
|
+
// eslint-disable-next-line
|
|
124
|
+
let weekObject: Object = parser.reverseObject(weekData);
|
|
125
|
+
// tslint:enable
|
|
126
|
+
regexString += '(' + Object.keys(weekObject).join('|') + ')';
|
|
127
|
+
break;
|
|
128
|
+
case 'M':
|
|
129
|
+
case 'L':
|
|
130
|
+
case 'd':
|
|
131
|
+
case 'm':
|
|
132
|
+
case 's':
|
|
133
|
+
case 'h':
|
|
134
|
+
case 'H':
|
|
135
|
+
case 'f':
|
|
136
|
+
canUpdate = true;
|
|
137
|
+
if ((char === 'M' || char === 'L') && len > 2) {
|
|
138
|
+
let monthData: Object;
|
|
139
|
+
if (isBlazor()) {
|
|
140
|
+
// eslint-disable-next-line
|
|
141
|
+
monthData = getValue('months.' + (base as any).monthIndex[len], dependable.dateObject);
|
|
142
|
+
} else {
|
|
143
|
+
// eslint-disable-next-line
|
|
144
|
+
monthData = (<any>dependable).dateObject[month][standalone][(<any>base).monthIndex[len]];
|
|
145
|
+
}
|
|
146
|
+
// eslint-disable-next-line
|
|
147
|
+
(<any>parseOptions)[charKey] = parser.reverseObject(monthData);
|
|
148
|
+
// eslint-disable-next-line
|
|
149
|
+
regexString += '(' + Object.keys((<any>parseOptions)[charKey]).join('|') + ')';
|
|
150
|
+
} else if (char === 'f') {
|
|
151
|
+
if (len > 3) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
isNumber = true;
|
|
155
|
+
regexString += '(' + nRegx + nRegx + '?' + nRegx + '?' + ')';
|
|
156
|
+
} else {
|
|
157
|
+
isNumber = true;
|
|
158
|
+
regexString += '(' + nRegx + nRegx + optional + ')';
|
|
159
|
+
}
|
|
160
|
+
if (char === 'h') {
|
|
161
|
+
parseOptions.hour12 = true;
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
case 'W':
|
|
165
|
+
// eslint-disable-next-line
|
|
166
|
+
let opt: string = len === 1 ? '?' : '';
|
|
167
|
+
regexString += '(' + nRegx + opt + nRegx + ')';
|
|
168
|
+
break;
|
|
169
|
+
case 'y':
|
|
170
|
+
canUpdate = isNumber = true;
|
|
171
|
+
if (len === 2) {
|
|
172
|
+
regexString += '(' + nRegx + nRegx + ')';
|
|
173
|
+
} else {
|
|
174
|
+
regexString += '(' + nRegx + '{' + len + ',})';
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
177
|
+
case 'a':
|
|
178
|
+
canUpdate = true;
|
|
179
|
+
// eslint-disable-next-line
|
|
180
|
+
let periodValur: Object = isBlazor() ?
|
|
181
|
+
getValue('dayPeriods', dependable.dateObject) :
|
|
182
|
+
getValue('dayPeriods.format.wide', dependable.dateObject);
|
|
183
|
+
// eslint-disable-next-line
|
|
184
|
+
(<any>parseOptions)[charKey] = parser.reverseObject(periodValur);
|
|
185
|
+
// eslint-disable-next-line
|
|
186
|
+
regexString += '(' + Object.keys((<any>parseOptions)[charKey]).join('|') + ')';
|
|
187
|
+
break;
|
|
188
|
+
case 'G':
|
|
189
|
+
canUpdate = true;
|
|
190
|
+
// eslint-disable-next-line
|
|
191
|
+
let eText: string = (len <= 3) ? 'eraAbbr' : (len === 4) ? 'eraNames' : 'eraNarrow';
|
|
192
|
+
// eslint-disable-next-line
|
|
193
|
+
(<any>parseOptions)[charKey] = parser.reverseObject(isBlazor() ?
|
|
194
|
+
getValue('eras', dependable.dateObject) : getValue('eras.' + eText, dependable.dateObject));
|
|
195
|
+
// eslint-disable-next-line
|
|
196
|
+
regexString += '(' + Object.keys((<any>parseOptions)[charKey]).join('|') + '?)';
|
|
197
|
+
break;
|
|
198
|
+
case 'z':
|
|
199
|
+
// eslint-disable-next-line
|
|
200
|
+
let tval: number = new Date().getTimezoneOffset();
|
|
201
|
+
canUpdate = (tval !== 0);
|
|
202
|
+
// eslint-disable-next-line
|
|
203
|
+
(<any>parseOptions)[charKey] = getValue('dates.timeZoneNames', dependable.parserObject);
|
|
204
|
+
// eslint-disable-next-line
|
|
205
|
+
let tzone: base.TimeZoneOptions = (<any>parseOptions)[charKey];
|
|
206
|
+
hourOnly = (len < 4);
|
|
207
|
+
// eslint-disable-next-line
|
|
208
|
+
let hpattern: string = hourOnly ? '+H;-H' : tzone.hourFormat;
|
|
209
|
+
hpattern = hpattern.replace(/:/g, numMapper.timeSeparator);
|
|
210
|
+
regexString += '(' + this.parseTimeZoneRegx(hpattern, tzone, nRegx) + ')?';
|
|
211
|
+
isgmtTraversed = true;
|
|
212
|
+
zCorrectTemp = hourOnly ? 6 : 12;
|
|
213
|
+
break;
|
|
214
|
+
case '\'':
|
|
215
|
+
// eslint-disable-next-line
|
|
216
|
+
let iString: string = str.replace(/'/g, '');
|
|
217
|
+
regexString += '(' + iString + ')?';
|
|
218
|
+
break;
|
|
219
|
+
default:
|
|
220
|
+
regexString += '([\\D])';
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
if (canUpdate) {
|
|
224
|
+
parseOptions.evalposition[`${charKey}`] = { isNumber: isNumber, pos: i + 1 + gmtCorrection, hourOnly: hourOnly };
|
|
225
|
+
}
|
|
226
|
+
if (i === length - 1 && !isNullOrUndefined(regexString)) {
|
|
227
|
+
const regExp: RegExpConstructor = RegExp;
|
|
228
|
+
parseOptions.parserRegex = new regExp('^' + regexString + '$', 'i');
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return (value: string): Date => {
|
|
233
|
+
const parsedDateParts: DateParts = this.internalDateParse(value, parseOptions, numOptions);
|
|
234
|
+
if (isNullOrUndefined(parsedDateParts) || !Object.keys(parsedDateParts).length) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
return this.getDateObject(parsedDateParts);
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/* tslint:disable */
|
|
241
|
+
/**
|
|
242
|
+
* Returns date object for provided date options
|
|
243
|
+
*
|
|
244
|
+
* @param {DateParts} options ?
|
|
245
|
+
* @param {Date} value ?
|
|
246
|
+
* @returns {Date} ?
|
|
247
|
+
*/
|
|
248
|
+
private static getDateObject(options: DateParts, value?: Date): Date {
|
|
249
|
+
const res: Date = value || new Date();
|
|
250
|
+
res.setMilliseconds(0);
|
|
251
|
+
const tKeys: string[] = ['hour', 'minute', 'second', 'milliseconds', 'month', 'day'];
|
|
252
|
+
let y: number = options.year;
|
|
253
|
+
const desig: string = options.designator;
|
|
254
|
+
const tzone: number = options.timeZone;
|
|
255
|
+
if (!isUndefined(y)) {
|
|
256
|
+
const len: number = (y + '').length;
|
|
257
|
+
if (len <= 2) {
|
|
258
|
+
const century: number = Math.floor(res.getFullYear() / 100) * 100;
|
|
259
|
+
y += century;
|
|
260
|
+
}
|
|
261
|
+
res.setFullYear(y);
|
|
262
|
+
}
|
|
263
|
+
for (const key of tKeys) {
|
|
264
|
+
// eslint-disable-next-line
|
|
265
|
+
let tValue: number = (<any>options)[key];
|
|
266
|
+
if (isUndefined(tValue) && key === 'day') {
|
|
267
|
+
res.setDate(1);
|
|
268
|
+
}
|
|
269
|
+
if (!isUndefined(tValue)) {
|
|
270
|
+
if (key === 'month') {
|
|
271
|
+
tValue -= 1;
|
|
272
|
+
if (tValue < 0 || tValue > 11) {
|
|
273
|
+
return new Date('invalid');
|
|
274
|
+
}
|
|
275
|
+
const pDate: number = res.getDate();
|
|
276
|
+
res.setDate(1);
|
|
277
|
+
// eslint-disable-next-line
|
|
278
|
+
(<any>res)[(<any>timeSetter)[key]](tValue);
|
|
279
|
+
const lDate: number = new Date(res.getFullYear(), tValue + 1, 0).getDate();
|
|
280
|
+
res.setDate(pDate < lDate ? pDate : lDate);
|
|
281
|
+
} else {
|
|
282
|
+
if (key === 'day') {
|
|
283
|
+
const lastDay: number = new Date(res.getFullYear(), res.getMonth() + 1, 0).getDate();
|
|
284
|
+
if ((tValue < 1 || tValue > lastDay)) {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// eslint-disable-next-line
|
|
289
|
+
(<any>res)[(<any>timeSetter)[key]](tValue);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (!isUndefined(desig)) {
|
|
294
|
+
const hour: number = res.getHours();
|
|
295
|
+
if (desig === 'pm') {
|
|
296
|
+
res.setHours(hour + (hour === 12 ? 0 : 12));
|
|
297
|
+
} else if (hour === 12) {
|
|
298
|
+
res.setHours(0);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (!isUndefined(tzone)) {
|
|
302
|
+
const tzValue: number = tzone - res.getTimezoneOffset();
|
|
303
|
+
if (tzValue !== 0) {
|
|
304
|
+
res.setMinutes(res.getMinutes() + tzValue);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return res;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Returns date parsing options for provided value along with parse and numeric options
|
|
311
|
+
*
|
|
312
|
+
* @param {string} value ?
|
|
313
|
+
* @param {ParseOptions} parseOptions ?
|
|
314
|
+
* @param {NumericOptions} num ?
|
|
315
|
+
* @returns {DateParts} ?
|
|
316
|
+
*/
|
|
317
|
+
private static internalDateParse(value: string, parseOptions: ParseOptions, num: NumericOptions): DateParts {
|
|
318
|
+
const matches: string[] = value.match(parseOptions.parserRegex);
|
|
319
|
+
const retOptions: DateParts = { 'hour': 0, 'minute': 0, 'second': 0 };
|
|
320
|
+
if (isNullOrUndefined(matches)) {
|
|
321
|
+
return null;
|
|
322
|
+
} else {
|
|
323
|
+
const props: string[] = Object.keys(parseOptions.evalposition);
|
|
324
|
+
for (const prop of props) {
|
|
325
|
+
const curObject: ValuePosition = parseOptions.evalposition[`${prop}`];
|
|
326
|
+
let matchString: string = matches[curObject.pos];
|
|
327
|
+
if (curObject.isNumber) {
|
|
328
|
+
// eslint-disable-next-line
|
|
329
|
+
(<any>retOptions)[prop] = this.internalNumberParser(matchString, num);
|
|
330
|
+
} else {
|
|
331
|
+
if (prop === 'timeZone' && !isUndefined(matchString)) {
|
|
332
|
+
const pos: number = curObject.pos;
|
|
333
|
+
let val: number;
|
|
334
|
+
const tmatch: string = matches[pos + 1];
|
|
335
|
+
const flag: boolean = !isUndefined(tmatch);
|
|
336
|
+
if (curObject.hourOnly) {
|
|
337
|
+
val = this.getZoneValue(flag, tmatch, matches[pos + 4], num) * 60;
|
|
338
|
+
} else {
|
|
339
|
+
val = this.getZoneValue(flag, tmatch, matches[pos + 7], num) * 60;
|
|
340
|
+
val += this.getZoneValue(flag, matches[pos + 4], matches[pos + 10], num);
|
|
341
|
+
|
|
342
|
+
}
|
|
343
|
+
if (!isNullOrUndefined(val)) {
|
|
344
|
+
retOptions[`${prop}`] = val;
|
|
345
|
+
}
|
|
346
|
+
} else {
|
|
347
|
+
const cultureOptions: string[] = ['en-US', 'en-MH', 'en-MP'];
|
|
348
|
+
// eslint-disable-next-line
|
|
349
|
+
matchString = ((prop === 'month') && (!(<any>parseOptions).isIslamic) && ((<any>parseOptions).culture === 'en' || (<any>parseOptions).culture === 'en-GB' || (<any>parseOptions).culture === 'en-US'))
|
|
350
|
+
? matchString[0].toUpperCase() + matchString.substring(1).toLowerCase() : matchString;
|
|
351
|
+
// eslint-disable-next-line
|
|
352
|
+
matchString = ((prop !== 'month') && (prop === 'designator') && <any>parseOptions.culture && (<any>parseOptions).culture.indexOf('en-') !== -1 && cultureOptions.indexOf(<any>parseOptions.culture) === -1)
|
|
353
|
+
? matchString.toLowerCase() : matchString;
|
|
354
|
+
// eslint-disable-next-line
|
|
355
|
+
(<any>retOptions)[prop] = (<any>parseOptions)[prop][matchString];
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
if (parseOptions.hour12) {
|
|
360
|
+
retOptions.hour12 = true;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return retOptions;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Returns parsed number for provided Numeric string and Numeric Options
|
|
367
|
+
*
|
|
368
|
+
* @param {string} value ?
|
|
369
|
+
* @param {NumericOptions} option ?
|
|
370
|
+
* @returns {number} ?
|
|
371
|
+
*/
|
|
372
|
+
private static internalNumberParser(value: string, option: NumericOptions): number {
|
|
373
|
+
value = parser.convertValueParts(value, option.numberParseRegex, option.numericPair);
|
|
374
|
+
if (latnRegex.test(value)) {
|
|
375
|
+
return +value;
|
|
376
|
+
}
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Returns parsed time zone RegExp for provided hour format and time zone
|
|
381
|
+
*
|
|
382
|
+
* @param {string} hourFormat ?
|
|
383
|
+
* @param {base.TimeZoneOptions} tZone ?
|
|
384
|
+
* @param {string} nRegex ?
|
|
385
|
+
* @returns {string} ?
|
|
386
|
+
*/
|
|
387
|
+
private static parseTimeZoneRegx(hourFormat: string, tZone: base.TimeZoneOptions, nRegex: string): string {
|
|
388
|
+
const pattern: string = tZone.gmtFormat;
|
|
389
|
+
let ret: string;
|
|
390
|
+
const cRegex: string = '(' + nRegex + ')' + '(' + nRegex + ')';
|
|
391
|
+
let splitStr: string[];
|
|
392
|
+
|
|
393
|
+
ret = hourFormat.replace('+', '\\+');
|
|
394
|
+
if (hourFormat.indexOf('HH') !== -1) {
|
|
395
|
+
ret = ret.replace(/HH|mm/g, '(' + cRegex + ')');
|
|
396
|
+
} else {
|
|
397
|
+
ret = ret.replace(/H|m/g, '(' + cRegex + '?)');
|
|
398
|
+
}
|
|
399
|
+
// eslint-disable-next-line
|
|
400
|
+
splitStr = (ret.split(';').map((str: string): string => {
|
|
401
|
+
return pattern.replace('{0}', str);
|
|
402
|
+
}));
|
|
403
|
+
ret = splitStr.join('|') + '|' + tZone.gmtZeroFormat;
|
|
404
|
+
return ret;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Returns zone based value.
|
|
408
|
+
*
|
|
409
|
+
* @param {boolean} flag ?
|
|
410
|
+
* @param {string} val1 ?
|
|
411
|
+
* @param {string} val2 ?
|
|
412
|
+
* @param {NumericOptions} num ?
|
|
413
|
+
* @returns {number} ?
|
|
414
|
+
*/
|
|
415
|
+
private static getZoneValue(flag: boolean, val1: string, val2: string, num: NumericOptions): number {
|
|
416
|
+
const ival: string = flag ? val1 : val2;
|
|
417
|
+
if (!ival) {
|
|
418
|
+
return 0;
|
|
419
|
+
}
|
|
420
|
+
const value: number = this.internalNumberParser(ival, num);
|
|
421
|
+
if (flag) {
|
|
422
|
+
return -value;
|
|
423
|
+
}
|
|
424
|
+
return value;
|
|
425
|
+
}
|
|
426
|
+
}
|