-
-
Notifications
You must be signed in to change notification settings - Fork 281
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
Fix large-dates ambiguity by creating a repr:four modifier #709
Conversation
...what's up with the failing checks? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #709 +/- ##
=======================================
- Coverage 97.8% 97.7% -0.1%
=======================================
Files 81 83 +2
Lines 9378 8980 -398
=======================================
- Hits 9169 8773 -396
+ Misses 209 207 -2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reviewability, you may want to do the cargo fmt
changes first in their own separate commit, avoid polluting the Created tests by...
commit with non-test changes.
And there should probably be an accompanying merge request on https://github.com/time-rs/book to clarify how to resolve the large-dates ambiguity, update the [year] component diagaram, etc in https://time-rs.github.io/book/api/format-description.html#components |
Not sure about the formatting check; it appears that the |
@dennisorlando it looks like the CI is using rust nightly (at least for that step): fmt:
name: Formatting
runs-on: ubuntu-latest
if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork) || github.event_name == 'push'
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- name: Check formatting
run: cargo fmt --all -- --check
env:
RUSTFLAGS: --cfg bench |
Thanks! I rerun cargo fmt with an updated nightly installation and it worked. - name: Install toolchain
<...>
- name: Print version
run: cargo fmt --version
- name: Check formatting
run: cargo fmt --all -- --check
env:
RUSTFLAGS: --cfg bench |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, nice work! I have a few nits. More generally, I would prefer this be named repr:narrow
with the corresponding YearRepr::Narrow
variant. I feel this better captures the intent when combined with the large-dates
feature.
Finally, can you remove the formatting commit and rebase instead? It was something I hadn't kept up to date with on nightly, hence the issue.
tests/formatting.rs
Outdated
@@ -392,6 +392,7 @@ fn format_date() -> time::Result<()> { | |||
(fd!("[year sign:mandatory]"), "+2019"), | |||
(fd!("[year base:iso_week sign:mandatory]"), "+2020"), | |||
(fd!("[year repr:last_two]"), "19"), | |||
(fd!("[year repr:four]"), "2019"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that formatting can fail, it would be a good idea to add a test for that situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific section I can put such test in? I can't figure out where to put it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create a new method if one doesn't seem obvious. I want to say RFC 3339 is the only case where formatting can fail currently, so it's quite likely this is the case.
On it; |
"standard" works for me. |
After some more recent work, namely adding I don't believe it's documented how to add a new modifier, so let me know if you need any guidance. If you prefer, I can also tackle it myself. |
Hmm I have a hard time decoupling it from Maybe a |
With the addition or My thought was |
how should range:standard affect the different representations (e.g. when used with repr:century or repr:last_two)? |
For
Awesome! 🙂 |
This is linked to #683
This PR creates a new [year] modifier, i.e.
repr:four
, which represents a full year which is forced to be 4 digits long. This is different from the defaultrepr:full
, which has a variable amount of digits depending if thelarge-dates
feature is enabled, thus causing parsing ambiguities that might produce errors in crates who depend ohtime.rs
.Tests have still to be written for this PR, thus it's not ready to be merged, but I opened this pull request anyways so that someone else might write them.
Namings and comments might also need to be discussed.
(I'll make a rebase of the commits when this PR is ready to be merged)