Commit graph

410 commits

Author SHA1 Message Date
Andrew Gallant
d6bae333b0
0.2.12 2025-05-03 09:21:58 -04:00
Andrew Gallant
016d0b1254 fmt/rfc2822: fix panic in handling of whitespace
Skipping whitespace happens immediately before `input[0]`. But skipping
the whitespace could lead to `input` being empty.

We handle the empty case and add a regression test.

Fixes #359
2025-05-03 09:22:45 -04:00
Andrew Gallant
3efed44871 fmt/temporal: ensure that 1970-06-01T00-00:45:00[Africa/Monrovia] does not parse successfully
Previously we were allowing this through since we didn't distinguish
between `-00:45` and `-00:45:00` when checking offset equality. In the
former case, we round the actual offset (which is `-00:44:30` in this
case), and if it matches the provided offset, we allow it. But in the
latter case, we *should* respect the precision specified in the string
and perform exact equality.

We fix this by just querying the parsed structure to see if a second
component was actually parsed or not. If it was, we do exact equality.

(For context, this is only an issue because Temporal, and also Jiff,
generally only support time zone offsets up to minute precision when
formatting. This reflects what RFC 3339 and RFC 9557 support. However,
we still support *parsing* offsets with sub-minute precision. To make
everything consistent and round-trip, we permit rounding as a means to
test offset equality when a time zone offset has sub-minute precision
but a parsed offset does not.)

Fixes #357
2025-05-02 15:01:22 -04:00
Andrew Gallant
b0512f4ef4
jiff-icu: compatibility fixes
I guess we can't just drop the `std` feature quite yet, since Jiff only
implements `std::error::Error` and not `core::error::Error`. Sigh.
2025-05-01 15:56:34 -04:00
Andrew Gallant
11b286deed
jiff-icu-0.2.0-beta.2 2025-05-01 15:38:38 -04:00
Andrew Gallant
0d1cf196a0
0.2.11 2025-05-01 15:36:48 -04:00
Andrew Gallant
407180a402
changelog: 0.2.11 2025-05-01 15:36:23 -04:00
Stepan Koltsov
2dc5b00d2e
doc: fix typo in "formatting"
PR #354
2025-05-01 08:26:20 -04:00
Andrew Gallant
3acc4f9b60 display: clarify default precision in Display impls
Previously, the documentation for `Display` trait implementations on
datetime types discussed precision, but omitted the default behavior.
This PR documents the default behavior and makes the docs for
`Timestamp`, `Zoned`, `civil::DateTime` and `civil::Time` a bit more
consistent.

Fixes #328
2025-04-30 20:57:41 -04:00
Arie Bovenberg
c9701c3c94 fmt/rfc2822: fix handling whitespace at comma and time separators
RFC2822 allows some unusual whitespace configurations
which weren't covered previously. In particular, these two cases
are now handled properly according to spec:

(1) Whitespace is allowed, but may also be completely omitted, on both
    sides of the `,` following the weekday;
(2) Whitespace is allowed around the time separators (`:`).

Fixes #339
2025-04-30 20:38:21 -04:00
Andrew Gallant
d395262c24
fmt/strtime: remove breadcrumbs comment
This was meant to be removed before merging. Oh well.
2025-04-30 20:24:13 -04:00
Andrew Gallant
2f6602eedb fmt/strtime: add "lenient" mode for strtime formatting APIs
This is another (IMO) cursed API meant to provide some measure of
compatibility with GNU date: a mode that specifically ignores errors
when formatting datetimes using `jiff::fmt::strtime`.

For example, neither `%0` nor `%+` are valid conversion specifiers
supported by Jiff. By default, using those will result in an error. But
with the new lenient mode (which you need to opt into), no error will
occur and instead `%0` and `%+` just get written literally as-is in the
returned string.

This applies to other kinds of errors. For example, if you use `%z` with
a `BrokenDownTime` that doesn't contain an offset, then that would
normally result in an error. But in lenient mode, it just results in
`%z` being written literally.

The docs for this mode contain a strongly worded warning to avoid
enabling this. It's makes for a terrible user experience because it
squashes failures without so much as a peep. The *only* reason anyone
should enable it is for when strict compatibility with other software
is necessary.

Closes #350
2025-04-30 20:21:40 -04:00
Andrew Gallant
9f3d5ebd2f fmt/strtime: add support for %::z and %:::z
These are also motivated by their presence in GNU date. They are
basically just different ways of printing offsets from UTC.

We do some light refactoring to DRY up the code a bit, and to make it a
little nicer to handle a variable number (up to a fixed size limit) of
`:` characters preceding a directive.

This is honestly just a giant clusterfuck (who thinks having `%z`,
`%:z`, `%::z` and `%:::z` is a nice user experience!?!?), but so is
`strptime`/`strftime` I guess. Oh well.

Closes #342
2025-04-30 17:33:44 -04:00
Andrew Gallant
8860d97b0b fmt/strtime: use Temporal offset parser in strptime
I originally didn't do this because I perceived the offset parsing in
`strptime` to be "simple," and I didn't want to complicate the Temporal
offset parser. But now that we seek to support `%::z` and `%:::z` in
`strptime`, it makes sense to DRY things up a bit.
2025-04-30 17:33:44 -04:00
Andrew Gallant
0957978bae fmt/strtime: add more %z and %:z tests
We're going to be gutting the offset parsing, so let's add some tests
for it to make sure we don't break anything.
2025-04-30 17:33:44 -04:00
Andrew Gallant
2087383c2c fmt/strtime: touchups for %N
I had forgotten to update the docs. And I added another test.

Ref #344
2025-04-30 17:33:44 -04:00
Andrew Gallant
6f77691dee fmt: remove old commented out code 2025-04-30 07:49:29 -04:00
Andrew Gallant
06c9d1e3fb fmt/strtime: add support for the %q
This is also found in GNU date. It simply prints the quarter of the
year.

We don't bother with parsing. It can't be used to construct a date. The
only thing we could support is actually parsing a new dedicated quarter
field. It's not really clear if that's worth it. If someone has a use
case for it, I'd be open to adding it. (Since `BrokenDownTime` is
already enormous.)

Closes #341
2025-04-30 07:49:29 -04:00
Andrew Gallant
b2d224838e fmt/strtime: add support for %N
This conversion specifier is supported by GNU date.

Thankfully this was pretty easy to do, as it's just an alias for `%f`,
which Jiff already supports.

Closes #344
2025-04-30 07:49:29 -04:00
Andrew Gallant
d798ec7f44 tz: make bundled database return TimeZone::UTC when appropriate
Previously, this was not being special cased, which in turn read `UTC`
like any other time zone. But really, we should be returning
`TimeZone::UTC` when and if we know that the time zone is actually
`UTC`.

Fixes #346
2025-04-29 17:20:00 -04:00
Andrew Gallant
f21740ee5f fmt/strtime: optimize strftime
This is mostly just using `#[inline]` in variouos spots and
specializing common code paths.

The most interesting change is that a `BrokenDownTime` now
contains a `Option<TimeZone>` instead of a time zone
abbreviation. It turns out that getting the time zone
abbreviation for a fixed offset time zone does some work
up-front to format the string. By just storing the time
zone, we can defer that work until we know we actually
need it.
2025-04-28 12:12:44 -04:00
Andrew Gallant
836bc15e37 bench: add strftime benchmark
This actually never got any optimization attention, and
it looks like its perf matters to coreutils. So let's
take a look at it!

Ref https://github.com/uutils/coreutils/issues/7852
2025-04-28 12:12:44 -04:00
Andrew Gallant
9de018ce74 strtime: add Custom trait for override strtime behavior
Specifically, this permits customizing the %c, %r, %X and %x
conversion specifiers. (Which are also newly added in this commit.)

We also include a default behavior for these specifiers
(meant to match Unicode's `und` locale) as well as an opt-in
POSIX behavior (meant to match POSIX's `C` locale).

Some minor refactoring is also included here. It was too annoying
to split into its own commit.
2025-04-28 12:12:44 -04:00
Andrew Gallant
ea763735a1 error: add a public method for constructing Error values
I've finally relented and exposes a very restricted way
to build an `Error` value.

I was motivated to do this because there are some traits
in Jiff that use `jiff::Error` in their return types. Without
a constructor like this, it isn't possible for implementors
of that trait to provide their own error values.
2025-04-28 12:12:44 -04:00
Andrew Gallant
9eeb9949b7 fmt: remove comment about incremental parsing
That API was added, so this is really no longer needed.
2025-04-28 12:12:44 -04:00
Andrew Gallant
febe58d91d jiff-icu: squash unused import warnings 2025-04-28 12:12:44 -04:00
Andrew Gallant
69dbc90c5f jiff-icu: add support for zoned datetimes 2025-04-28 12:12:44 -04:00
Andrew Gallant
11364d2a23 jiff-icu: migrate to icu 2.0.0
This basically does what is necessary to get everything compiled and
tests passing.

We'll add on time zone and offset stuff in a subsequent commit.

Note that we now depend on `icu_calendar` and `icu_time` directly, with
the latter being optional (but enabled by default). In particular, one
can do useful things with just conversions to dates with `icu_calendar`.
But I expect most folks will want both.
2025-04-28 12:12:44 -04:00
Joey de Waal
ef7ed1f85e
jiff-sqlx: remove dependency on sqlx-core
Specifically, the `sqlx-core`, `sqlx-sqlite`
and `sqlx-postgres` crates aren't actually
supposed to be depended on directly.
2025-04-23 08:49:39 -04:00
Andrew Gallant
75ed28ea23
0.2.10 2025-04-21 19:53:49 -04:00
Andrew Gallant
ad1353780c strtime: fix parsing for Tuesday
Unfortunately, I had a typo, which meant it recognized Tueday instead
Tuesday.

This was covered by tests, but I missed the typo in the asserted test
output too.

Fixes #333
2025-04-21 10:29:30 -04:00
Philippe Loctaux
13bd8ab8f0
doc: fix typo
PR #332
2025-04-21 09:28:17 -04:00
Andrew Gallant
e2f8b9a7c9
0.2.9 2025-04-19 15:02:40 -04:00
Andrew Gallant
5673c5b694
changelog: 0.2.9 2025-04-19 15:02:15 -04:00
Andrew Gallant
b0c08ed744 rangeint: implement Hash for ranged integers manually
Only the actual value matters. By deriving `Hash`, it was including the
tracked min/max values, which is of course incorrect.

Note that this was only an issue in debug mode. In release mode, the
min/max values aren't compiled in, and so the `Hash` impl was correct.

Fixes #330
2025-04-19 15:00:39 -04:00
Jan Procházka
d08fcb36ce
wasm: improve panic message when js feature isn't enabled
This should hopefully make the opt-in `js` feature more
discoverable when users hit panics.

Closes #296
2025-04-18 08:59:00 -04:00
Joseph Cooper
df373bdde2
doc: fix typo
Correct typo in comment about regression test for
`SignedDuration::try_from_secs_f32()`.

PR #327
2025-04-17 08:28:48 -04:00
Andrew Gallant
d27af19fe2
0.2.8 2025-04-13 17:59:11 -04:00
Andrew Gallant
d1921a8fb7
changelog: 0.2.8 2025-04-13 17:58:44 -04:00
Andrew Gallant
093d6b9475 signed_duration: add alternate Debug implementation
This adds an "alternate" Debug implementation for `SignedDuration`.
The alternate impl is a more "straight forward" representation of
a `SignedDuration`'s internals. That is, it just shows seconds and
nanoseconds (omitting zero components). I find this much easier to
read when reasoning about SignedDuration, since its internals and, to
an extent, its API, are defined in terms of its second and nanosecond
components.
2025-04-13 17:57:42 -04:00
Andrew Gallant
c939baaea6 signed_duration: fix panic in SignedDuration::try_from_secs_f64
This also resulted in a panic for an undocumented case, in debug mode, in
`SignedDuration::from_secs_f64`.

A similar fix has been applied to the `f32` case as well.

The problem was that if the fractional part of the floating point
duration rounded up to 1, then the nanosecond component would represent
a single full second. This case wasn't correctly accounted for.

Fixes #324
2025-04-13 17:57:42 -04:00
Andrew Gallant
3e32e71ac8
0.2.7 2025-04-13 14:08:10 -04:00
Andrew Gallant
01e241431c
changelog: 0.2.7 2025-04-13 14:07:41 -04:00
Andrew Gallant
06b94b52ae jiff-static: add perf-inline feature to jiff-static
In practice, we do this because otherwise
`cfg_attr(feature = "perf-inline")` will throw a warning otherwise. And
that happens because we use these annotations in code in Jiff that is
shared (via copying) with `jiff-static`. So instead of just removing the
annotations, we add `perf-inline` as a feature to `jiff-static`.

For `jiff-static`, we disable it by default, since we don't really care
about that level of perf when doing datetime calculations at compile
time.
2025-04-11 20:55:04 -04:00
Andrew Gallant
cd4b25e0fb
vim: remove most linked projects
It looks like this was actually the root cause of what was causing a
rustc stunlock. Apparently every save in my editor causes `cargo check`
to run on *all* of the linked projects? That seems nuts... Sigh.
2025-04-11 20:30:53 -04:00
Andrew Gallant
058c317405 jiff-cli: re-generate shared code in jiff-static
This apparently got out of date. And it was apparently not being
enforced in CI. And the destination directory used by `jiff-cli` was
outdated. So fix all of that here, including re-generation.
2025-04-11 15:58:33 -04:00
Andrew Gallant
32c4b9337c changelog: add recent changes 2025-04-11 15:58:33 -04:00
Andrew Gallant
5a6f268e82 cargo: add perf-inline crate feature
This is copied over from `regex`. Basically, when this is enabled (which
is the default), then a bunch of `inline(always)` annotations are
scattered in places (as motivated by micro-benchmarking). Otherwise,
these annotations are removed.
2025-04-11 15:58:33 -04:00
Andrew Gallant
692725befe rustc: remove some generics
This improves compile times slightly in some ad hoc experiments.

I thought this might help more than it ultimately did.
2025-04-11 15:58:33 -04:00
Joey de Waal
08903c55ec
tz: treat an empty TZ environment variable as TZ=UTC
Specifically, an environment variable that is *set* to
the empty string.

This seems like odd behavior to me, but it's apparently
what both GNU and BSD tooling do. And since Jiff's
support for `TZ` is really about conforming to existing
convention, we just do what everyone else does.

PR #319
2025-04-11 15:03:46 -04:00