File tree 3 files changed +17
-7
lines changed
site/src/components/Timeline
3 files changed +17
-7
lines changed Original file line number Diff line number Diff line change 1
1
import { makeStyles } from "@mui/styles"
2
2
import TableCell from "@mui/material/TableCell"
3
3
import TableRow from "@mui/material/TableRow"
4
- import formatRelative from "date-fns/formatRelative"
5
4
import { FC } from "react"
5
+ import { createDisplayDate } from "./utils"
6
6
7
7
export interface TimelineDateRow {
8
8
date : Date
9
9
}
10
10
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
-
16
11
export const TimelineDateRow : FC < TimelineDateRow > = ( { date } ) => {
17
12
const styles = useStyles ( )
18
13
Original file line number Diff line number Diff line change 1
- import { createDisplayDate } from "./TimelineDateRow "
1
+ import { createDisplayDate } from "./utils "
2
2
3
3
describe ( "createDisplayDate" , ( ) => {
4
4
it ( "returns correctly for Saturdays" , ( ) => {
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments