Skip to content

feat(datetime): add format_distance_to_now function #6615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

fbritoferreira
Copy link

This PR introduces theformatDistanceToNow function to the @std/datetime package.
The function formats a given Date object as a human-readable relative time string, such as "3 minutes ago" or "1 hour ago".

@fbritoferreira fbritoferreira requested a review from kt3k as a code owner April 22, 2025 15:50
@CLAassistant
Copy link

CLAassistant commented Apr 22, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

codecov bot commented Apr 22, 2025

Codecov Report

Attention: Patch coverage is 72.00000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 94.52%. Comparing base (645875e) to head (867a117).

Files with missing lines Patch % Lines
datetime/format_distance_to_now.ts 72.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6615      +/-   ##
==========================================
- Coverage   94.54%   94.52%   -0.02%     
==========================================
  Files         580      581       +1     
  Lines       43772    43797      +25     
  Branches     6480     6496      +16     
==========================================
+ Hits        41384    41401      +17     
- Misses       2345     2353       +8     
  Partials       43       43              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@timreichen
Copy link
Contributor

While I think this is kinda neat in general I think it opens a big can of worms concerning localization.
Doesn't this kinda overlap with Intl.DurationFormat?

@iuioiua
Copy link
Contributor

iuioiua commented Apr 22, 2025

While I think this is kinda neat in general I think it opens a big can of worms concerning localization. Doesn't this kinda overlap with Intl.DurationFormat?

I agree. I instead suggest adding an example snippet to @std/datetime/difference's documentation that uses Intl.DurationFormat. E.g. denoland/saaskit#706 and jsr-io/jsr#974 (comment).

@iuioiua
Copy link
Contributor

iuioiua commented Apr 24, 2025

I suggest closing this PR in favour of my suggestion above.

@kt3k
Copy link
Member

kt3k commented Apr 24, 2025

I agree with @timreichen and @iuioiua . Intl.DurationFormat covers this, and we generally don't try to compete with web platform APIs.

@fbritoferreira Thanks for your suggestion anyways

Closing without merge

@kt3k kt3k closed this Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants