diff --git a/src/components/ui/DateDiffLabel/index.stories.tsx b/src/components/ui/DateDiffLabel/index.stories.tsx index 46a3779..365c622 100644 --- a/src/components/ui/DateDiffLabel/index.stories.tsx +++ b/src/components/ui/DateDiffLabel/index.stories.tsx @@ -50,6 +50,14 @@ export const ThreeMonthAgo: Story = { args: { date: new Date(Date.now() - 1000 * 60 * 60 * 24 * 30 * 3) }, } +export const SixMonthAgo: Story = { + args: { date: new Date(Date.now() - 1000 * 60 * 60 * 24 * 30 * 6) }, +} + export const YearAgo: Story = { args: { date: new Date(Date.now() - 1000 * 60 * 60 * 24 * 365) }, +}; + +export const TwoYearAgo: Story = { + args: { date: new Date(Date.now() - 1000 * 60 * 60 * 24 * 365 * 2) }, }; \ No newline at end of file diff --git a/src/components/ui/DateDiffLabel/index.tsx b/src/components/ui/DateDiffLabel/index.tsx index 31204b3..877bc28 100644 --- a/src/components/ui/DateDiffLabel/index.tsx +++ b/src/components/ui/DateDiffLabel/index.tsx @@ -14,11 +14,8 @@ export const DateDiffLabel: FC = ({ date, now = new Date(), className, -}) => { - const nowDate = now ?? new Date(); - return ( +}) => ( - ); -}; \ No newline at end of file + ); \ No newline at end of file diff --git a/src/components/ui/DateDiffLabel/logic.ts b/src/components/ui/DateDiffLabel/logic.ts index e90664f..8a9ec88 100644 --- a/src/components/ui/DateDiffLabel/logic.ts +++ b/src/components/ui/DateDiffLabel/logic.ts @@ -15,35 +15,32 @@ export const DateToDiffLabel = ( Math.floor((now.getTime() - date.getTime()) / 1000) ); - if(diffInSeconds <= MONTH * 3) { - if (diffInSeconds < MINUTE) - return `${diffInSeconds}${ - DATE_DIFF_LABEL['second'] - }`; - if (diffInSeconds < HOUR) - return `${Math.floor(diffInSeconds / MINUTE)}${ - DATE_DIFF_LABEL['minute'] - }`; - if (diffInSeconds < DAY) - return `${Math.floor(diffInSeconds / HOUR)}${ - DATE_DIFF_LABEL['hour'] - }`; - if (diffInSeconds < WEEK) - return `${Math.floor(diffInSeconds / DAY)}${ - DATE_DIFF_LABEL['day'] - }`; - if (diffInSeconds < MONTH) - return `${Math.floor(diffInSeconds / WEEK)}${ - DATE_DIFF_LABEL['week'] - }`; + if (diffInSeconds < MINUTE) + return `${diffInSeconds}${ + DATE_DIFF_LABEL['second'] + }`; + if (diffInSeconds < HOUR) + return `${Math.floor(diffInSeconds / MINUTE)}${ + DATE_DIFF_LABEL['minute'] + }`; + if (diffInSeconds < DAY) + return `${Math.floor(diffInSeconds / HOUR)}${ + DATE_DIFF_LABEL['hour'] + }`; + if (diffInSeconds < WEEK) + return `${Math.floor(diffInSeconds / DAY)}${ + DATE_DIFF_LABEL['day'] + }`; + if (diffInSeconds < MONTH) + return `${Math.floor(diffInSeconds / WEEK)}${ + DATE_DIFF_LABEL['week'] + }`; + if (diffInSeconds <= MONTH * 3) return `${Math.floor(diffInSeconds / MONTH)}${ DATE_DIFF_LABEL['month'] }`; - } - - if(date.getFullYear() === now.getFullYear()) { - return `${date.getMonth()+1}/${date.getDate()}` - } else { - return `${date.getFullYear()}/${date.getMonth()+1}/${date.getDate()}` - } + if(date.getFullYear() === now.getFullYear()) + return `${date.getMonth()+1}/${date.getDate()}`; + + return `${date.getFullYear()}/${date.getMonth()+1}/${date.getDate()}`; }; \ No newline at end of file