Skip to content

Commit a3475fa

Browse files
committed
chore: merge remote-tracking branch 'upstream/main'
2 parents 96222b0 + c81904c commit a3475fa

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Unit Tests
2-
on: push
2+
on: [push, pull_request]
33
permissions: read-all
44
jobs:
55
vitest:

parse.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
11
// Times are parsed as UTC if no offset is specified
22
export class IsoDateParts {
3-
static DEFAULT_TIMEZONE_OFFSET = {
4-
hours: 0,
5-
minutes: 0,
6-
};
7-
83
static FULL_DATE_REGEX = /^([+-]\d{6}|\d{4})-?([01]\d)-?([0-3]\d)$/;
94
static DATETIME_REGEX = /^([+-]\d{6}|\d{4})-?([01]\d)-?([0-3]\d)[Tt ]([0-2]\d(?:[\.\,]\d+)?)(?::?([0-5]\d(?:[\.\,]\d+)?)(?::?([0-5]\d))?(?:[\.\,](\d{1,9}))?)?(Z|[+-][0-2]\d(?::?[0-5]\d)?)?$/;
105
static TIMEZONE_REGEX = /^([+-]\d{2})(?::?(\d{2}))?$/;
116
static IS_FRACTIONAL_REGEX = /^\d+[\.\,]\d+$/;
127

13-
static getTimezoneOffset(offset = "") {
14-
if(offset === "Z") {
15-
return this.DEFAULT_TIMEZONE_OFFSET;
16-
}
17-
let match = offset.match(this.TIMEZONE_REGEX);
18-
if(!match) {
19-
return this.DEFAULT_TIMEZONE_OFFSET;
20-
}
8+
static getTimezoneOffset(offset = "Z") {
9+
let [, hours = "0", minutes = "0"] = offset.match(this.TIMEZONE_REGEX) ?? [];
2110

22-
let [hours, minutes] = [match[1], match[2]];
11+
let sign = hours[0] === '-' ? -1 : 1;
2312
return {
24-
hours: parseInt(hours, 10) || 0,
25-
minutes: parseInt(minutes, 10) || 0
13+
hours: parseInt(hours, 10),
14+
minutes: parseInt(minutes, 10) * sign
2615
};
2716
}
2817

test/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ export const VALID_TEST_CASES = `
2525
2016-05-25T09+01:00
2626
2016-05-25T09:24+01:00
2727
2016-05-25T09:24:15+01:00
28+
2016-05-25T09:24:15+01:15
2829
2016-05-25T09:24:15.123+01:00
2930
2016-05-25T09:24:15,123+01:00
3031
2016-05-25T09-01:00
3132
2016-05-25T09:24-01:00
3233
2016-05-25T09:24:15-01:00
34+
2016-05-25T09:24:15-01:15
3335
2016-05-25T09:24:15.123-01:00
3436
2016-05-25T09:24:15,123-01:00
3537
2016-05-25T09+06:00
@@ -73,8 +75,10 @@ export const VALID_TEST_CASES = `
7375
// Issue #1
7476
2016-05-25T09:24:15+06
7577
2016-05-25T09:24:15+0600
78+
2016-05-25T09:24:15+0615
7679
2016-05-25T09:24:15-06
7780
2016-05-25T09:24:15-0600
81+
2016-05-25T09:24:15-0615
7882
7983
// 6 digit years
8084
+002000-01-01

0 commit comments

Comments
 (0)