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

"X years ago" is not rounding correctly #270

Closed
antn opened this issue Jan 4, 2024 · 3 comments · Fixed by #271
Closed

"X years ago" is not rounding correctly #270

antn opened this issue Jan 4, 2024 · 3 comments · Fixed by #271
Labels

Comments

@antn
Copy link
Member

antn commented Jan 4, 2024

I noticed that something from Feb 2020 displayed as "5 years ago", when it is closer to 4 years if we are trying to round?

Image

@antn antn added the bug label Jan 4, 2024
@Gusted
Copy link

Gusted commented Jan 6, 2024

Some light investigation suggests that the problem is in roundToSingleUnit (months and days needs to be specified for it to reproduce) likely around this logic, there's no comment here so I'm not sure what this logic is supposed to do. Here's a concrete testcase that currently fails.

diff --git a/test/duration.ts b/test/duration.ts
index ef96d97..e6c6aaf 100644
--- a/test/duration.ts
+++ b/test/duration.ts
@@ -309,6 +309,7 @@ suite('duration', function () {
         },
       ],
       ['-P27D', '-P1M', {relativeTo: new Date('2023-02-28T00:00:00Z')}],
+      [{days: -15, months: -11}, '-P1Y', {relativeTo: new Date('2024-01-06T00:00:00')}],
     ])
     for (const [input, expected, opts] of roundTests) {
       test(`roundToSingleUnit(${input}) === ${expected}`, () => {

@martinburger
Copy link

martinburger commented Jan 6, 2024

I think I ran into a similar issue:

image

This screenshot has been taken from a Gitea instance. Gitea uses relative-time-element to display, well, relative dates.

keithamus added a commit that referenced this issue Jan 12, 2024
keithamus added a commit that referenced this issue Jan 12, 2024
keithamus added a commit that referenced this issue Jan 12, 2024
keithamus added a commit that referenced this issue Jan 12, 2024
keithamus added a commit that referenced this issue Jan 12, 2024
@santeriv
Copy link

Yeah seeing similar on 2024-01-15 (not yet 3 years, but it shows 4 years ) compared to real value 2021-02-02 .
image

Did not make a test case of this..

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 a pull request may close this issue.

4 participants