Skip to content

Commit

Permalink
fix dayjs rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
sspenst committed Mar 19, 2024
1 parent 7df38c2 commit 1184ba9
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion components/formatted/formattedDate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,29 @@ import relativeTime from 'dayjs/plugin/relativeTime';
import React from 'react';
import StyledTooltip from '../page/styledTooltip';

dayjs.extend(relativeTime);
// https://day.js.org/docs/en/customization/relative-time
dayjs.extend(
relativeTime,
{
rounding: Math.floor,
thresholds: [
{ l: 's', r: 59, d: 'second' },
{ l: 'm', r: 1 },
{ l: 'mm', r: 59, d: 'minute' },
{ l: 'h', r: 1 },
{ l: 'hh', r: 23, d: 'hour' },
{ l: 'd', r: 1 },
{ l: 'dd', r: 27, d: 'day' },
// NB: weeks are not well-supported by dayjs
// { l: 'w', r: 1 },
// { l: 'ww', r: 4, d: 'week' },
{ l: 'M', r: 1 },
{ l: 'MM', r: 11, d: 'month' },
{ l: 'y', r: 1 },
{ l: 'yy', d: 'year' },
],
}
);

interface FormattedDateProps {
className?: string;
Expand Down

0 comments on commit 1184ba9

Please sign in to comment.