Skip to content
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

feat: multiple units support in toRelative #926

Merged
merged 2 commits into from
May 8, 2021

Conversation

andreialecu
Copy link
Contributor

This has been requested before in #579, see discussion there for more details.

My use case is that during the first minute, .toRelative() will print something like 1 second ago. I'd like to avoid updating it every second (for performance purposes), and instead I'd like it to print out 0 minutes ago. This way I can schedule updates once every minute instead of every second.

This PR adds a way to override which units are considered when formatting a relative date.

See the tests I added as well.

Fixes #579.

@andreialecu
Copy link
Contributor Author

One thing to note is that this also fixes an issue with rounding:

I added a test for it:

  expect(base.minus({ seconds: 1 }).toRelative({ base, unit: "minutes" })).toBe("0 minutes ago");

On master, that printed in 0 minutes which was wrong.

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.

Feature request: toRelative multiple units
2 participants