diff --git a/spec/core/ZincReader.spec.ts b/spec/core/ZincReader.spec.ts index a8b5fbd..dfa036f 100644 --- a/spec/core/ZincReader.spec.ts +++ b/spec/core/ZincReader.spec.ts @@ -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 { @@ -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 = + '<>' + + 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 = + '<>' + + 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 = + '<>' + + 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() diff --git a/src/core/ZincReader.ts b/src/core/ZincReader.ts index 9d31b9b..14bcbf4 100644 --- a/src/core/ZincReader.ts +++ b/src/core/ZincReader.ts @@ -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()