Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions spec/core/ZincReader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,45 @@ describe('ZincReader', function (): void {
HDateTime.make('2010-11-28T07:23:02.773-08:00 Los_Angeles')
)
})

it('parses a date time with timezone containing -', function (): void {
const parsedVal = makeReader(
'2010-11-28T07:23:02.773-04:00 Port-au-Prince'
).readValue()
const expectedVal = HDateTime.make(
'2010-11-28T07:23:02.773-04:00 Port-au-Prince'
)
expect(parsedVal).toEqual(expectedVal)
expect((parsedVal as HDateTime).timezone).toBe(
expectedVal.timezone
)
})

it('parses a date time with GMT-n timezone', function (): void {
const parsedVal = makeReader(
'2025-06-12T15:22:11.518+02:00 GMT-2'
).readValue()
const expectedVal = HDateTime.make(
'2025-06-12T15:22:11.518+02:00 GMT-2'
)
expect(parsedVal).toEqual(expectedVal)
expect((parsedVal as HDateTime).timezone).toBe(
expectedVal.timezone
)
})

it('parses a date time with GMT+n timezone', function (): void {
const parsedVal = makeReader(
'2025-06-12T11:23:32.488-02:00 GMT+2'
).readValue()
const expectedVal = HDateTime.make(
'2025-06-12T11:23:32.488-02:00 GMT+2'
)
expect(parsedVal).toEqual(expectedVal)
expect((parsedVal as HDateTime).timezone).toBe(
expectedVal.timezone
)
})
}) // date time

describe('null', function (): void {
Expand Down Expand Up @@ -1325,6 +1364,84 @@ describe('ZincReader', function (): void {
const value = ZincReader.readValue(zinc)
expect(value && value.equals(grid)).toBe(true)
})

it('parses a grid with a datetime and timezone containing -', function (): void {
const zinc =
'<<ver:"3.0"\n' +
'val\n' +
'2025-06-12T08:24:25.631-04:00 Port-au-Prince\n' +
'>>'

const grid = HGrid.make({
columns: [
{
name: 'val',
},
],
rows: [
HDict.make({
val: HDateTime.make(
'2025-06-12T08:24:25.631-04:00 Port-au-Prince'
),
}),
],
})

const value = makeReader(zinc).readValue()
expect(value && value.equals(grid)).toBe(true)
})

it('parses a grid with a datetime and GMT-n timezone val', function (): void {
const zinc =
'<<ver:"3.0"\n' +
'val\n' +
'2025-06-12T14:54:00.88+02:00 GMT-2\n' +
'>>'

const grid = HGrid.make({
columns: [
{
name: 'val',
},
],
rows: [
HDict.make({
val: HDateTime.make(
'2025-06-12T14:54:00.88+02:00 GMT-2'
),
}),
],
})

const value = makeReader(zinc).readValue()
expect(value && value.equals(grid)).toBe(true)
})

it('parses a grid with a datetime and GMT+n timezone val', function (): void {
const zinc =
'<<ver:"3.0"\n' +
'val\n' +
'2025-06-12T14:54:00.88-02:00 GMT+2\n' +
'>>'

const grid = HGrid.make({
columns: [
{
name: 'val',
},
],
rows: [
HDict.make({
val: HDateTime.make(
'2025-06-12T14:54:00.88-02:00 GMT+2'
),
}),
],
})

const value = makeReader(zinc).readValue()
expect(value && value.equals(grid)).toBe(true)
})
}) // grid
}) // #nextValue()

Expand Down
18 changes: 3 additions & 15 deletions src/core/ZincReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,21 +555,9 @@ export class ZincReader {
while (
this.scanner.isLetter() ||
this.scanner.isDigit() ||
this.scanner.is('_')
) {
dateTime += this.scanner.current
this.scanner.consume()

while (this.scanner.isDigit()) {
dateTime += this.scanner.current
this.scanner.consume()
}
}

// handle GMT+xx or GMT-xx
if (
(this.scanner.is('+') || this.scanner.is('-')) &&
dateTime.endsWith('GMT')
this.scanner.is('_') || // Tz containing "_" (ex.: Los_Angeles)
this.scanner.is('-') || // GMT-n or tz containing "-" (ex.: Port-au-Prince)
this.scanner.is('+') // GMT+n
) {
dateTime += this.scanner.current
this.scanner.consume()
Expand Down