Skip to content
Open
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
23 changes: 22 additions & 1 deletion packages/adapter-pg/src/__tests__/conversion.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'

import { mapArg } from '../conversion'
import { mapArg, normalize_timestamp, normalize_timestamptz } from '../conversion'

describe('mapArg', () => {
it('converts a date with a 4-digit year (value >= 1000-01-01) to the correct date', () => {
Expand Down Expand Up @@ -39,3 +39,24 @@ describe('mapArg', () => {
expect(result).toBe('0099-12-31 23:59:59.999')
})
})

describe('normalize_timestamp', () => {
it('leaves standard 4-digit years unaffected', () => {
expect(normalize_timestamp('2026-09-02 05:00:00')).toBe('2026-09-02T05:00:00+00:00')
})

it('prepends + to expanded years (>9999) to satisfy ISO 8601', () => {
expect(normalize_timestamp('202609-02-05 05:00:00')).toBe('+202609-02-05T05:00:00+00:00')
})
})

describe('normalize_timestamptz', () => {
it('leaves standard 4-digit years unaffected', () => {
// Note: Postgres timestamptz wire format includes the timezone offset
expect(normalize_timestamptz('2026-09-02 05:00:00+00')).toBe('2026-09-02T05:00:00+00:00')
})

it('prepends + to expanded years (>9999) to satisfy ISO 8601', () => {
expect(normalize_timestamptz('202609-02-05 05:00:00+00')).toBe('+202609-02-05T05:00:00+00:00')
})
})
10 changes: 6 additions & 4 deletions packages/adapter-pg/src/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,14 @@ function normalize_date(date: string): string {
* ex: 1996-12-19T16:39:57-08:00
*/

function normalize_timestamp(time: string): string {
return `${time.replace(' ', 'T')}+00:00`
export function normalize_timestamp(time: string): string {
const iso = `${time.replace(' ', 'T')}+00:00`
return /^\d{5,}/.test(iso) ? '+' + iso : iso
}

function normalize_timestamptz(time: string): string {
return time.replace(' ', 'T').replace(/[+-]\d{2}(:\d{2})?$/, '+00:00')
export function normalize_timestamptz(time: string): string {
const iso = time.replace(' ', 'T').replace(/[+-]\d{2}(:\d{2})?$/, '+00:00')
return /^\d{5,}/.test(iso) ? '+' + iso : iso
}

/*
Expand Down