Skip to content
Merged
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
7 changes: 1 addition & 6 deletions site/src/components/Timeline/TimelineDateRow.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { makeStyles } from "@mui/styles"
import TableCell from "@mui/material/TableCell"
import TableRow from "@mui/material/TableRow"
import formatRelative from "date-fns/formatRelative"
import { FC } from "react"
import { createDisplayDate } from "./utils"

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, base = new Date()): string =>
formatRelative(date, base).split(" at ")[0]

export const TimelineDateRow: FC<TimelineDateRow> = ({ date }) => {
const styles = useStyles()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createDisplayDate } from "./TimelineDateRow"
import { createDisplayDate } from "./utils"

describe("createDisplayDate", () => {
it("returns correctly for Saturdays", () => {
Expand Down
15 changes: 15 additions & 0 deletions site/src/components/Timeline/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable eslint-comments/disable-enable-pair -- Solve below */
/* eslint-disable import/no-duplicates -- https://github.com/date-fns/date-fns/issues/1677 */
import formatRelative from "date-fns/formatRelative"
import subDays from "date-fns/subDays"

export const createDisplayDate = (
date: Date,
base: Date = new Date(),
): string => {
const lastWeek = subDays(base, 7)
if (date >= lastWeek) {
return formatRelative(date, base).split(" at ")[0]
}
return date.toLocaleDateString()
}