Repository navigation
Conversation
…apSoftware#3562) When items reached 360 days (12 * 30), diffInMonths was 12, bypassing the months branch into diffInYears = floor(days / 365), which was 0 until day 365. This produced '0y ago' for items 360-364 days old. Clamp diffInYears to at least 1 when reaching the years branch so near-year items render as '1y ago'. Also accept an optional now Date parameter to enable deterministic unit testing. Closes CapSoftware#3562
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3562
Linear: CAP-952
Comments, share headers, and timeline branch cards that are 360–364 days old were displaying "0y ago".
Root Cause
formatTimeAgoinapps/web/app/s/[videoId]/_components/tabs/Activity/utils.tstransitioned from months to years oncediffInMonths < 12was false. At 360 days (12 * 30),diffInMonthsreached 12, so it dropped intodiffInYears = Math.floor(diffInDays / 365). For days 360 through 364,floor(days / 365)evaluated to0, producing"0y ago".Changes
diffInYears = Math.max(1, Math.floor(diffInDays / 365))so that reaching the years branch guarantees at least"1y ago".now: Date = new Date()parameter toformatTimeAgofor clean, deterministic unit testing without timers/mocks.apps/web/__tests__/unit/activity-time-ago.test.tsasserting 359d (11mo ago), 360–364d (1y ago), 365d (1y ago), and multi-year durations.Test plan
bun test apps/web/__tests__/unit/activity-time-ago.test.ts(3 pass, 13 assertions)bun test apps/web/__tests__/unit/video-thumbnail-duration.test.ts(4 pass, 17 assertions)bun test apps/mobile/src/utils/format.test.ts(4 pass, 19 assertions)

Confidence Score: 5/5
The PR appears safe to merge.Summary
Fixes
formatTimeAgoso items aged 360–364 days show “1y ago” instead of “0y ago.”Reviews (1) · Last reviewed commit: "fix(web): prevent comments showing 0y ag..." · Reviewed by Greptile