Skip to content

Commit 9d0d9a7

Browse files
committed
fix(ui): support both date formats in UI: custom and RFC3339 (#335)
1 parent 1953123 commit 9d0d9a7

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

Diff for: ui/packages/shared/types/api/entities/clone.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*--------------------------------------------------------------------------
66
*/
77

8-
import { parseISO9075Date } from '@postgres.ai/shared/utils/date'
8+
import { parseDate } from '@postgres.ai/shared/utils/date'
99
import {
1010
SnapshotDto,
1111
formatSnapshotDto,
@@ -35,7 +35,7 @@ export type CloneDto = {
3535
export const formatCloneDto = (dto: CloneDto) => ({
3636
...dto,
3737
createdAt: dto.createdAt,
38-
createdAtDate: parseISO9075Date(dto.createdAt),
38+
createdAtDate: parseDate(dto.createdAt),
3939
snapshot: dto.snapshot ? formatSnapshotDto(dto.snapshot) : null,
4040
})
4141

Diff for: ui/packages/shared/types/api/entities/snapshot.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parseISO9075Date } from '@postgres.ai/shared/utils/date'
1+
import { parseDate } from '@postgres.ai/shared/utils/date'
22

33
export type SnapshotDto = {
44
createdAt: string
@@ -11,8 +11,8 @@ export type SnapshotDto = {
1111

1212
export const formatSnapshotDto = (dto: SnapshotDto) => ({
1313
...dto,
14-
createdAtDate: parseISO9075Date(dto.createdAt),
15-
dataStateAtDate: parseISO9075Date(dto.dataStateAt)
14+
createdAtDate: parseDate(dto.createdAt),
15+
dataStateAtDate: parseDate(dto.dataStateAt)
1616
})
1717

1818
export type Snapshot = ReturnType<typeof formatSnapshotDto>

Diff for: ui/packages/shared/utils/date.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import {
2121
formatDistanceToNowStrict,
2222
} from 'date-fns'
2323

24-
export const parseISO9075Date = (dateStr: string) =>
25-
parse(dateStr.replace('UTC', 'Z'), 'yyyy-MM-dd HH:mm:ss X', new Date())
24+
// parseDate parses date of both format: '2006-01-02 15:04:05 UTC' and `2006-01-02T15:04:05Z` (RFC3339).
25+
export const parseDate = (dateStr: string) =>
26+
parse(dateStr.replace(' UTC', 'Z').replace('T', ' '), 'yyyy-MM-dd HH:mm:ssX', new Date())
2627

2728
// UTCf - UTC formatted, but not actually UTC.
2829
// date-fns using this approach because browser don't have an opportunity to switch single date

0 commit comments

Comments
 (0)