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

implement a few deprecations and expand the strtime conversion specifiers #208

Merged
merged 6 commits into from
Jan 21, 2025

Conversation

BurntSushi
Copy link
Owner

In brief, we:

  • Deprecate intz methods in favor of in_tz.
  • Deprecate the Eq and PartialEq trait implementations on Span in
    favor of calling span.fieldwise() to get a SpanFieldwise that implements
    Eq and PartialEq.
  • Deprecate any silent assumtions in the Span APIs that days are always 24
    hours. Instead, callers must either provide a relative reference time or
    provide the new special SpanRelativeTo::days_are_24_hours() marker.
  • Deprecate %V in favor of %Q for IANA time zone identifiers in strftime
    and strptime APIs.
  • Add a whole bunch of conversion specifiers to bring Jiff's strftime and
    strptime in near-parity with GNU's implementation. We leave out locale
    specific specifiers (because Jiff doesn't do locale, use icu for that)
    and %V for ISO 8601 week numbers. We'll add %V for this in jiff 0.2
    since it's a breaking change. (Hence the aforementioned deprecation.)

See the commit messages and their linked issues for more details.

In most cases we just squash the warning instead of cfg'ing out the
code. It is just super painful to correctly annotate everything piece of
code otherwise.
This applies to `Zoned`, `Timestamp`, `civil::DateTime` and
`civil::Date`.

Ref #28
Pretty much what it says on the tin. The idea here is that two different
`Span` values in memory, which compare not equal, might still be the
same duration. Obviously I knew this when I added the trait impl
originally, and realized it could be a footgun, but I thought its
convenience outweighed the footgun. However, I think #32 pretty
convincingly argues that it's the wrong default.

If this ends up being the wrong decision, we can always add the trait
impl back. In particular, I am worried about this making `Span` a very
annoying-to-use type. Not implementing basic equality is just super
annoying because it's common to want it in tests and other various
things where the footgun isn't really relevant. But at least this way,
we can fix the mistake in the future.

Ref #32
This does make _some_ use cases a bit more annoying, but I think it
overall makes the API more consistent. Essentially, unless
`SpanRelativeTo::days_are_24_hours` are provided, then Jiff will always
consider days to be a variable unit like weeks, months and years.
Previously, this would only happen _some_ of the time.

For now, when that assumption is silently made, Jiff will emit a
deprecation warning. This will turn into a hard error in `jiff 0.2`.

Ref #48
And similarly, deprecate `%:V` in favor of `%:Q`.

This was regretably done to improve compatibility with other strtime
implementations. In particular, `%V` will, in `jiff 0.2`, correspond to
an ISO 8601 week number. This matches other `strftime` and `strptime`
implementations, such as GNU's.

Ref #147
This adds a whole bunch of conversion specifiers from reading
`man strftime` on my system (GNU libc).

I originally didn't add most of these because they bloat the size of
`BrokenDownTime` and many of them seem a little dubious. But a few folks
have filed issues about compatibility. Given the `strtime` API is
already a complete clusterfuck, it probably makes sense to just match
existing practice as much as we can.

One conversion specifier I intend to add but haven't yet is `%V` for the
ISO 8601 week number. It is conspicuously absent here since `%V` is
currently used for IANA time zone identifiers. That will change in
`jiff 0.2`, which will make room for `%V` to be the ISO 8601 week
number.

Ref #139, Ref #147
@BurntSushi BurntSushi merged commit 28fa7b4 into master Jan 21, 2025
20 checks passed
@BurntSushi BurntSushi deleted the ag/variety branch January 21, 2025 03:25
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.

1 participant