fixed bug; wrote tests (#5329)

This commit is contained in:
Kira Pilot
2022-12-06 16:58:32 -05:00
committed by GitHub
parent 1cfe5de1c5
commit 85945af55e
2 changed files with 14 additions and 4 deletions
@@ -0,0 +1,8 @@
import { createDisplayDate } from "./TimelineDateRow"
describe("createDisplayDate", () => {
it("returns correctly for Saturdays", () => {
const date = new Date("Sat Dec 03 2022 00:00:00 GMT-0500")
expect(createDisplayDate(date)).toEqual("last Saturday")
})
})
@@ -8,16 +8,18 @@ export interface TimelineDateRow {
date: Date
}
// We only want the message related to the date since the time is displayed
// inside of the build row
export const createDisplayDate = (date: Date): string =>
formatRelative(date, new Date()).split(" at ")[0]
export const TimelineDateRow: FC<TimelineDateRow> = ({ date }) => {
const styles = useStyles()
// We only want the message related to the date since the time is displayed
// inside of the build row
const displayDate = formatRelative(date, new Date()).split("at")[0]
return (
<TableRow className={styles.dateRow}>
<TableCell className={styles.dateCell} title={date.toLocaleDateString()}>
{displayDate}
{createDisplayDate(date)}
</TableCell>
</TableRow>
)