Skip to content

fix: relativeDate shows "0 month ago" between 28 and 29 days - #77

Open
arpitjain099 wants to merge 1 commit into
usebruno:mainfrom
arpitjain099:fix/relative-date-month-boundary
Open

fix: relativeDate shows "0 month ago" between 28 and 29 days#77
arpitjain099 wants to merge 1 commit into
usebruno:mainfrom
arpitjain099:fix/relative-date-month-boundary

Conversation

@arpitjain099

Copy link
Copy Markdown

The notification timestamps use relativeDate, and there's a small gap in its cascade. The weeks branch checks weeksDifference < 4, which stops at 28 days, but the months branch reports Math.floor(daysDifference / 30), which is still 0 until day 30. So anything 28 or 29 days old renders as "0 month ago".

The fix changes that branch to daysDifference < 30 so those two days read "4 weeks ago", and the months branch only kicks in once a full month has actually passed. Behavior for every other range is unchanged.

I added a unit test in src/webview/utils/common/relativeDate.spec.ts covering the seconds/minutes/hours/days/weeks/months cases plus the 28 and 29 day boundary; npx vitest run passes (79 tests). Thanks for taking a look.

The weeks branch used weeksDifference < 4 (under 28 days), so 28 and 29
days elapsed fell through to the months branch where Math.floor(days / 30)
is still 0, rendering '0 month ago'. Switch that branch to daysDifference
< 30 so those days read '4 weeks ago' and the months branch is only used
once at least one full month has passed.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant