Skip to content

Commit 92445cf

Browse files
fix(site): fix locale dates in timeline component (#9223)
1 parent 5c1ecfb commit 92445cf

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

site/src/components/Timeline/TimelineDateRow.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import { makeStyles } from "@mui/styles"
22
import TableCell from "@mui/material/TableCell"
33
import TableRow from "@mui/material/TableRow"
4-
import formatRelative from "date-fns/formatRelative"
54
import { FC } from "react"
5+
import { createDisplayDate } from "./utils"
66

77
export interface TimelineDateRow {
88
date: Date
99
}
1010

11-
// We only want the message related to the date since the time is displayed
12-
// inside of the build row
13-
export const createDisplayDate = (date: Date, base = new Date()): string =>
14-
formatRelative(date, base).split(" at ")[0]
15-
1611
export const TimelineDateRow: FC<TimelineDateRow> = ({ date }) => {
1712
const styles = useStyles()
1813

site/src/components/Timeline/Timeline.test.tsx renamed to site/src/components/Timeline/utils.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createDisplayDate } from "./TimelineDateRow"
1+
import { createDisplayDate } from "./utils"
22

33
describe("createDisplayDate", () => {
44
it("returns correctly for Saturdays", () => {

site/src/components/Timeline/utils.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-disable eslint-comments/disable-enable-pair -- Solve below */
2+
/* eslint-disable import/no-duplicates -- https://github.com/date-fns/date-fns/issues/1677 */
3+
import formatRelative from "date-fns/formatRelative"
4+
import subDays from "date-fns/subDays"
5+
6+
export const createDisplayDate = (
7+
date: Date,
8+
base: Date = new Date(),
9+
): string => {
10+
const lastWeek = subDays(base, 7)
11+
if (date >= lastWeek) {
12+
return formatRelative(date, base).split(" at ")[0]
13+
}
14+
return date.toLocaleDateString()
15+
}

0 commit comments

Comments
 (0)