Skip to content

Commit 85945af

Browse files
authored
fixed bug; wrote tests (#5329)
1 parent 1cfe5de commit 85945af

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { createDisplayDate } from "./TimelineDateRow"
2+
3+
describe("createDisplayDate", () => {
4+
it("returns correctly for Saturdays", () => {
5+
const date = new Date("Sat Dec 03 2022 00:00:00 GMT-0500")
6+
expect(createDisplayDate(date)).toEqual("last Saturday")
7+
})
8+
})

site/src/components/Timeline/TimelineDateRow.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ 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): string =>
14+
formatRelative(date, new Date()).split(" at ")[0]
15+
1116
export const TimelineDateRow: FC<TimelineDateRow> = ({ date }) => {
1217
const styles = useStyles()
13-
// We only want the message related to the date since the time is displayed
14-
// inside of the build row
15-
const displayDate = formatRelative(date, new Date()).split("at")[0]
1618

1719
return (
1820
<TableRow className={styles.dateRow}>
1921
<TableCell className={styles.dateCell} title={date.toLocaleDateString()}>
20-
{displayDate}
22+
{createDisplayDate(date)}
2123
</TableCell>
2224
</TableRow>
2325
)

0 commit comments

Comments
 (0)