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

Make applyDuration reversible #298

Merged
merged 3 commits into from
Jan 13, 2025
Merged

Conversation

leduyquang753
Copy link
Contributor

@leduyquang753 leduyquang753 commented Dec 30, 2024

(This is part of a set of multiple pull requests looking to overhaul the calculation functions.)

When the duration to be applied is negative, this pull request makes the application order of the components reversed compared to when the duration is positive, so that adding a duration to a date then subtracting the same amount yields the same date.

Note: One test is failing on my end from the current upstream code:

relative-time > [tense=future] > micro formats years
AssertionError: expected '3y' to equal '2y'
+ expected - actual

- 3y
+ 2y

This is caused by the current implementation of roundToNearestUnit computing the future date to be in 2027, resulting in a 3-year difference as it only considers the year alone in this case. This will be fixed with a reimplementation of the function in one of my other pull requests.

@leduyquang753 leduyquang753 requested a review from a team as a code owner December 30, 2024 16:29
src/duration.ts Outdated Show resolved Hide resolved
@keithamus
Copy link
Member

It looks as though there's a test failure - that perhaps should be changed with this change?

@leduyquang753
Copy link
Contributor Author

leduyquang753 commented Jan 6, 2025

It looks as though there's a test failure - that perhaps should be changed with this change?

The failing test is not because of or affected by this change as stated in my original comment (it also appears that quite a few tests use new Date() which makes them sensitive to the time of the year).

In the test of the check you run:

 ❌ relative-time > [tense=past] > micro formats years
      AssertionError: expected '11y' to equal '10y'
      + expected - actual
      
      -11y
      +10y
      
      at n4.<anonymous> (test/relative-time.js:531:13)

it is 11y because the test uses new Date() and it is currently the beginning of the year, making the duration rounding code calculate the supposed old date as in 2014 rather than 2015.

Copy link
Member

@keithamus keithamus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking nice!

@github/primer-reviewers you should merge this one and make a patch release with this.

@camertron camertron merged commit 8490db2 into github:main Jan 13, 2025
1 check passed
DennisRasey pushed a commit to DennisRasey/forgejo that referenced this pull request Jan 17, 2025
…#6559)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@github/relative-time-element](https://github.com/github/relative-time-element) | dependencies | patch | [`4.4.4` -> `4.4.5`](https://renovatebot.com/diffs/npm/@github%2frelative-time-element/4.4.4/4.4.5) |

---

### Release Notes

<details>
<summary>github/relative-time-element (@&#8203;github/relative-time-element)</summary>

### [`v4.4.5`](https://github.com/github/relative-time-element/releases/tag/v4.4.5)

[Compare Source](github/relative-time-element@v4.4.4...v4.4.5)

#### What's Changed

-   fix: wrap Intl.<>() calls in try/catch by [@&#8203;francinelucca](https://github.com/francinelucca) in github/relative-time-element#297
-   get main branch green by [@&#8203;keithamus](https://github.com/keithamus) in github/relative-time-element#302
-   Make `applyDuration` reversible by [@&#8203;leduyquang753](https://github.com/leduyquang753) in github/relative-time-element#298
-   Use node v22 by [@&#8203;camertron](https://github.com/camertron) in github/relative-time-element#303

#### New Contributors

-   [@&#8203;francinelucca](https://github.com/francinelucca) made their first contribution in github/relative-time-element#297
-   [@&#8203;leduyquang753](https://github.com/leduyquang753) made their first contribution in github/relative-time-element#298
-   [@&#8203;camertron](https://github.com/camertron) made their first contribution in github/relative-time-element#303

**Full Changelog**: github/relative-time-element@v4.4.4...v4.4.5

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "* 0-3 * * *" (UTC), Automerge - "* 0-3 * * *" (UTC).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMDYuMCIsInVwZGF0ZWRJblZlciI6IjM5LjEwNi4wIiwidGFyZ2V0QnJhbmNoIjoiZm9yZ2VqbyIsImxhYmVscyI6WyJkZXBlbmRlbmN5LXVwZ3JhZGUiLCJ0ZXN0L25vdC1uZWVkZWQiXX0=-->

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6559
Reviewed-by: Otto <[email protected]>
Co-authored-by: Renovate Bot <[email protected]>
Co-committed-by: Renovate Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants