Skip to content

Commit 1db4c5b

Browse files
authored
Merge pull request #9 from lucifurtun/master
fix: Make parser be aware of "Z" character as timezone offset
2 parents 3bfe24d + 099e3a9 commit 1db4c5b

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/parse-format/parse.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const match1to2 = /\d\d?/ // 0 - 99
88
const matchUpperAMPM = /[AP]M/
99
const matchLowerAMPM = /[ap]m/
1010
const matchSigned = /[+-]?\d+/ // -inf - inf
11-
const matchOffset = /[+-]\d\d:?\d\d/ // +00:00 -00:00 +0000 or -0000
11+
const matchOffset = /([+-]\d\d:?\d\d|Z)/ // +00:00 -00:00 +0000 -0000 or Z
1212
const matchAbbreviation = /[A-Z]{3,4}/ // CET
1313

1414
const parseTokenExpressions = {}
@@ -92,6 +92,10 @@ function addParseToken (tokens, property) {
9292
}
9393

9494
function offsetFromString (string) {
95+
if (string === 'Z') {
96+
return 0
97+
}
98+
9599
const parts = string.match(/([+-]|\d\d)/g)
96100
const minutes = +(parts[1] * 60) + +parts[2]
97101
return minutes === 0 ? 0 : parts[0] === '+' ? -minutes : minutes

test/parseZonedTime.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ it('format parser caching code works', () => {
7878
expect(year).toEqual(2018)
7979
})
8080

81+
it('recognizes ISO UTC timezone', () => {
82+
const time = parseZonedTime('Z', 'Z')
83+
const { zone } = time
84+
85+
expect(zone.offset).toEqual(0)
86+
})
87+
8188
it('leaves non-token parts of the format intact', () => {
8289
const time = parseZonedTime(' S:/-.() SS h ', ' [S]:/-.()[ SS h ]')
8390
expect(typeof time === 'object').toBeTruthy()

0 commit comments

Comments
 (0)