@singularsystems/neo-core 1.0.16 → 1.0.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/dist/Dates/DateUtils.d.ts +1 -1
- package/dist/Dates/DateUtils.js +35 -28
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ export default class DateUtils {
|
|
|
18
18
|
* @param dateString The string to parse
|
|
19
19
|
* @param format The format string. This is only used to get the order of d/m/y
|
|
20
20
|
* @param requireAllParts True if day month and year must be specified
|
|
21
|
-
* @param refDate Reference date. E.g. if the year is
|
|
21
|
+
* @param refDate Reference date. E.g. if the year is omitted in the date string, then the year from the reference date will be used. Today is used if no reference date is supplied.
|
|
22
22
|
*/
|
|
23
23
|
static tryParse(dateString: string, format?: string, requireAllParts?: boolean, refDate?: Date): Date | null;
|
|
24
24
|
static min(date1: Date, date2: Date): Date;
|
package/dist/Dates/DateUtils.js
CHANGED
|
@@ -70,9 +70,10 @@ var DateUtils = /** @class */ (function () {
|
|
|
70
70
|
* @param dateString The string to parse
|
|
71
71
|
* @param format The format string. This is only used to get the order of d/m/y
|
|
72
72
|
* @param requireAllParts True if day month and year must be specified
|
|
73
|
-
* @param refDate Reference date. E.g. if the year is
|
|
73
|
+
* @param refDate Reference date. E.g. if the year is omitted in the date string, then the year from the reference date will be used. Today is used if no reference date is supplied.
|
|
74
74
|
*/
|
|
75
75
|
DateUtils.tryParse = function (dateString, format, requireAllParts, refDate) {
|
|
76
|
+
var _a;
|
|
76
77
|
if (format === void 0) { format = ""; }
|
|
77
78
|
if (requireAllParts === void 0) { requireAllParts = false; }
|
|
78
79
|
if (!dateString)
|
|
@@ -80,38 +81,36 @@ var DateUtils = /** @class */ (function () {
|
|
|
80
81
|
if (!format)
|
|
81
82
|
format = DateUtils.defaultFormatString;
|
|
82
83
|
var returnDate = !refDate ? new Date() : new Date(refDate);
|
|
84
|
+
var timeString = "", isPM = false;
|
|
83
85
|
// Find the position of d m and y in the format string.
|
|
84
|
-
var d = format.indexOf('d'), m = format.indexOf('M'), y = format.indexOf('y'),
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
|
|
86
|
+
var d = format.indexOf('d'), m = format.indexOf('M'), y = format.indexOf('y'), h = format.indexOf("H"), extra = 100;
|
|
87
|
+
var expectedDateParts = (d < 0 ? 0 : 1) + (m < 0 ? 0 : 1) + (y < 0 ? 0 : 1);
|
|
88
|
+
// Replace common separators in the date string with /
|
|
89
|
+
dateString = dateString.replace(/-/g, '/').replace(/ /g, '/').replace(/\xA0/g, '/');
|
|
90
|
+
// If the user doesn't put in separators, e.g. 0103, then add them to make the string value 01/03
|
|
91
|
+
if ((d == 0 || m == 0) && dateString.indexOf('/') == -1 && dateString.length >= 4 && !isNaN(+dateString)) {
|
|
92
|
+
dateString = dateString.substring(0, 2) + '/' + dateString.substring(2, 4) + (dateString.length == 8 || dateString.length == 6 ? '/' + dateString.substring(4, dateString.length) : '');
|
|
91
93
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
var parts = dateString.split("/");
|
|
95
|
+
if (parts.length > expectedDateParts && (h >= 0)) {
|
|
96
|
+
timeString = parts.pop();
|
|
97
|
+
var pmPos = (_a = /[ap]m/i.exec(timeString)) === null || _a === void 0 ? void 0 : _a.index;
|
|
98
|
+
if (pmPos !== undefined) {
|
|
99
|
+
isPM = timeString.toUpperCase().indexOf("PM") >= 0;
|
|
100
|
+
if (pmPos === 0) {
|
|
101
|
+
timeString = parts.pop();
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
timeString = timeString.substring(0, pmPos);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
101
107
|
}
|
|
102
108
|
// Date component
|
|
103
|
-
if (
|
|
109
|
+
if (expectedDateParts > 0) {
|
|
104
110
|
// Add missing d/m/y on the end.
|
|
105
|
-
d = d == -1 ?
|
|
106
|
-
m = m == -1 ?
|
|
107
|
-
y = y == -1 ?
|
|
108
|
-
// Replace common separators in the date string with /
|
|
109
|
-
var str = dateString.replace(/-/g, '/').replace(/ /g, '/').replace(/\xA0/g, '/');
|
|
110
|
-
// If the user doesnt put in separators, e.g. 0103, then add them to make the string value 01/03
|
|
111
|
-
if ((d == 0 || m == 0) && str.indexOf('/') == -1 && str.length >= 4 && !isNaN(+str)) {
|
|
112
|
-
str = str.substring(0, 2) + '/' + str.substring(2, 4) + (str.length == 8 || str.length == 6 ? '/' + str.substring(4, str.length) : '');
|
|
113
|
-
}
|
|
114
|
-
var parts = str.split('/');
|
|
111
|
+
d = d == -1 ? extra++ : d;
|
|
112
|
+
m = m == -1 ? extra++ : m;
|
|
113
|
+
y = y == -1 ? extra++ : y;
|
|
115
114
|
if (requireAllParts && parts.length < 3)
|
|
116
115
|
return null;
|
|
117
116
|
// if format is dd mmm yyyy, and the user omits the dd, then add 1st day.
|
|
@@ -141,6 +140,14 @@ var DateUtils = /** @class */ (function () {
|
|
|
141
140
|
}
|
|
142
141
|
// Get time component.
|
|
143
142
|
if (timeString) {
|
|
143
|
+
if (timeString.indexOf(":") < 0) {
|
|
144
|
+
if (timeString.length >= 5) {
|
|
145
|
+
timeString = timeString.substring(0, timeString.length - 4) + ":" + timeString.substring(timeString.length - 4, timeString.length - 2) + ":" + timeString.substring(timeString.length - 2);
|
|
146
|
+
}
|
|
147
|
+
else if (timeString.length >= 3) {
|
|
148
|
+
timeString = timeString.substring(0, timeString.length - 2) + ":" + timeString.substring(timeString.length - 2);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
144
151
|
var time = new Date(0);
|
|
145
152
|
time.setHours.apply(time, timeString.split(":").map(function (s) { return parseInt(s); }));
|
|
146
153
|
if (isNaN(time)) {
|