@sprucelabs/calendar-utils 36.0.22 → 36.0.24
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.
|
@@ -3,20 +3,28 @@ import { AbstractParser } from '../AbstractParser.js';
|
|
|
3
3
|
export default class TimeParser extends AbstractParser {
|
|
4
4
|
parse(str, date, context) {
|
|
5
5
|
var _a;
|
|
6
|
-
const
|
|
6
|
+
const matches = (_a = str.match(/(\d{1,2})(:?(\d{1,2}))?\s*([ap]m?)?/)) !== null && _a !== void 0 ? _a : [];
|
|
7
|
+
let [match, hour, , minutes, ampm] = matches;
|
|
7
8
|
if (!match) {
|
|
8
9
|
return str;
|
|
9
10
|
}
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
if (hour) {
|
|
12
|
+
let parsedHour = parseInt(hour, 10);
|
|
13
|
+
if (parsedHour > 12) {
|
|
14
|
+
minutes = hour[1] + (minutes !== null && minutes !== void 0 ? minutes : '');
|
|
15
|
+
hour = hour[0];
|
|
16
|
+
parsedHour = parseInt(hour, 10);
|
|
17
|
+
}
|
|
18
|
+
date.hour = parsedHour - this.locale.getTimezoneOffsetMinutes() / 60;
|
|
13
19
|
date.minute = 0;
|
|
14
|
-
str = str.replace(match, '');
|
|
15
20
|
}
|
|
16
|
-
if (
|
|
17
|
-
|
|
21
|
+
if (minutes) {
|
|
22
|
+
if (minutes.length === 1) {
|
|
23
|
+
minutes += '0';
|
|
24
|
+
}
|
|
25
|
+
date.minute = parseInt(minutes, 10);
|
|
18
26
|
}
|
|
19
|
-
if (
|
|
27
|
+
if (ampm === null || ampm === void 0 ? void 0 : ampm.includes('p')) {
|
|
20
28
|
date.hour += 12;
|
|
21
29
|
}
|
|
22
30
|
else if (date.hour === 12 && match.includes('am')) {
|
|
@@ -25,6 +33,7 @@ export default class TimeParser extends AbstractParser {
|
|
|
25
33
|
if (!context.hasYear && dateUtil.date(date) < this.now()) {
|
|
26
34
|
date.hour += 12;
|
|
27
35
|
}
|
|
36
|
+
str = str.replace(match, '');
|
|
28
37
|
return str;
|
|
29
38
|
}
|
|
30
39
|
}
|
|
@@ -8,20 +8,28 @@ const AbstractParser_1 = require("../AbstractParser");
|
|
|
8
8
|
class TimeParser extends AbstractParser_1.AbstractParser {
|
|
9
9
|
parse(str, date, context) {
|
|
10
10
|
var _a;
|
|
11
|
-
const
|
|
11
|
+
const matches = (_a = str.match(/(\d{1,2})(:?(\d{1,2}))?\s*([ap]m?)?/)) !== null && _a !== void 0 ? _a : [];
|
|
12
|
+
let [match, hour, , minutes, ampm] = matches;
|
|
12
13
|
if (!match) {
|
|
13
14
|
return str;
|
|
14
15
|
}
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
if (hour) {
|
|
17
|
+
let parsedHour = parseInt(hour, 10);
|
|
18
|
+
if (parsedHour > 12) {
|
|
19
|
+
minutes = hour[1] + (minutes !== null && minutes !== void 0 ? minutes : '');
|
|
20
|
+
hour = hour[0];
|
|
21
|
+
parsedHour = parseInt(hour, 10);
|
|
22
|
+
}
|
|
23
|
+
date.hour = parsedHour - this.locale.getTimezoneOffsetMinutes() / 60;
|
|
18
24
|
date.minute = 0;
|
|
19
|
-
str = str.replace(match, '');
|
|
20
25
|
}
|
|
21
|
-
if (
|
|
22
|
-
|
|
26
|
+
if (minutes) {
|
|
27
|
+
if (minutes.length === 1) {
|
|
28
|
+
minutes += '0';
|
|
29
|
+
}
|
|
30
|
+
date.minute = parseInt(minutes, 10);
|
|
23
31
|
}
|
|
24
|
-
if (
|
|
32
|
+
if (ampm === null || ampm === void 0 ? void 0 : ampm.includes('p')) {
|
|
25
33
|
date.hour += 12;
|
|
26
34
|
}
|
|
27
35
|
else if (date.hour === 12 && match.includes('am')) {
|
|
@@ -30,6 +38,7 @@ class TimeParser extends AbstractParser_1.AbstractParser {
|
|
|
30
38
|
if (!context.hasYear && date_utility_1.default.date(date) < this.now()) {
|
|
31
39
|
date.hour += 12;
|
|
32
40
|
}
|
|
41
|
+
str = str.replace(match, '');
|
|
33
42
|
return str;
|
|
34
43
|
}
|
|
35
44
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "36.0.
|
|
6
|
+
"version": "36.0.24",
|
|
7
7
|
"files": [
|
|
8
8
|
"build/**/*",
|
|
9
9
|
"!build/__tests__",
|
|
@@ -66,11 +66,11 @@
|
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@sprucelabs/error": "^5.1.2",
|
|
69
|
-
"@sprucelabs/mercury-event-emitter": "^40.1.
|
|
70
|
-
"@sprucelabs/mercury-types": "^45.0.
|
|
69
|
+
"@sprucelabs/mercury-event-emitter": "^40.1.25",
|
|
70
|
+
"@sprucelabs/mercury-types": "^45.0.16",
|
|
71
71
|
"@sprucelabs/schema": "^28.6.28",
|
|
72
|
-
"@sprucelabs/spruce-core-schemas": "^38.1.
|
|
73
|
-
"@sprucelabs/spruce-event-utils": "^37.0.
|
|
72
|
+
"@sprucelabs/spruce-core-schemas": "^38.1.16",
|
|
73
|
+
"@sprucelabs/spruce-event-utils": "^37.0.18",
|
|
74
74
|
"date-fns": "^2.30.0",
|
|
75
75
|
"date-fns-tz": "^2.0.0",
|
|
76
76
|
"lodash": "^4.17.21",
|