Commit graph

79 commits

Author SHA1 Message Date
Andrew Gallant
269aee43ef
shared: attempt a faster date <-> rate die algorithm
This comes from:
https://www.benjoffe.com/fast-date-64

More specifically, the code is here:
7fcf82b07d/algorithms/benjoffe_fast64.hpp

But the benchmarks don't show an improvement:

```
$ critcmp base x01
group                                                   base                                   x01
-----                                                   ----                                   ---
civil_datetime/to_timestamp_static/bundled/jiff         1.00     10.5±0.09ns        ? ?/sec    1.03     10.9±0.07ns        ? ?/sec
civil_datetime/to_timestamp_static/zoneinfo/jiff        1.00     10.4±0.09ns        ? ?/sec    1.03     10.8±0.07ns        ? ?/sec
timestamp/to_civil_datetime_offset_conversion/jiff      1.00      4.4±0.05ns        ? ?/sec    1.03      4.6±0.03ns        ? ?/sec
```

I ran the benchmarks like this:

```
cd bench
```

Before the change:

```
cargo bench --'(civil_datetime/to_timestamp_static|timestamp/to_civil_datetime_offset_conversion).*jiff' --save-baseline base
```

And then after the change:

```
cargo bench --'(civil_datetime/to_timestamp_static|timestamp/to_civil_datetime_offset_conversion).*jiff' --save-baseline x01
```

Then I used [`critcmp`] to compare them:

```
critcmp base x01
```

It's very possible I didn't port it correctly. I haven't scrutinized the
codegen. It's also possible that there is an improvement, but that it's
hard to write a benchmark using Jiff APIs to observe it.

(Note that I left out the ARM-specific bits. I'm testing this on x86-64.
I wanted to test there first before digging into the platform specific
optimizations.)

[`critcmp`]: https://github.com/BurntSushi/critcmp
2025-11-26 14:31:58 -05:00
Andrew Gallant
6bab68dc24
jiff-icu-0.2.2
Some checks are pending
ci / time-zone-init (windows-latest) (push) Waiting to run
ci / test-default (beta, ubuntu-latest, beta) (push) Waiting to run
ci / test-default (macos, macos-latest, stable) (push) Waiting to run
ci / test-default (nightly, ubuntu-latest, nightly) (push) Waiting to run
ci / test-default (stable, ubuntu-latest, stable) (push) Waiting to run
ci / test-all (macos, macos-latest, nightly) (push) Waiting to run
ci / test-all (nightly, ubuntu-latest, nightly) (push) Waiting to run
ci / test-only-bundle (macos, macos-latest, nightly) (push) Waiting to run
ci / test-only-bundle (nightly, ubuntu-latest, nightly) (push) Waiting to run
ci / test-core (macos, macos-latest, nightly) (push) Waiting to run
ci / test-core (nightly, ubuntu-latest, nightly) (push) Waiting to run
ci / test-various-feature-combos (macos, macos-latest, nightly) (push) Waiting to run
ci / test-various-feature-combos (nightly, ubuntu-latest, nightly) (push) Waiting to run
ci / test-release (push) Waiting to run
ci / test-doc (push) Waiting to run
ci / test-bench (push) Waiting to run
ci / cross (aarch64-linux-android) (push) Waiting to run
ci / cross (aarch64-unknown-linux-gnu) (push) Waiting to run
ci / cross (i686-unknown-linux-gnu) (push) Waiting to run
ci / cross (powerpc-unknown-linux-gnu) (push) Waiting to run
ci / cross (powerpc64-unknown-linux-gnu) (push) Waiting to run
ci / cross (s390x-unknown-linux-gnu) (push) Waiting to run
ci / cross (x86_64-linux-android) (push) Waiting to run
ci / riscv32imc-unknown-none-elf (push) Waiting to run
ci / wasm32-wasip1 (push) Waiting to run
ci / wasm32-unknown-emscripten (push) Waiting to run
ci / wasm32-unknown-uknown (push) Waiting to run
ci / docsrs (push) Waiting to run
ci / rustfmt (push) Waiting to run
ci / generated (push) Waiting to run
2025-11-07 08:22:47 -05:00
Andrew Gallant
422353bb0c jiff-icu: add TryFrom impls for icu_time::zone::models::AtTime
It looks like `icu_time::zone::models::Full` has been deprecated. So we
need some `allow(deprecated)` to squash the warnings. And we implement a
`TryFrom` for `ZonedDateTime<Iso, TimeZoneInfo<AtTime>>` as its
replacement.

Previously, I think this would have lost some information, but it sounds
like icu4x can now figure out the right DST status without being told.

Ref https://github.com/unicode-org/icu4x/pull/6754
Ref https://github.com/unicode-org/icu4x/pull/6755
2025-11-07 08:22:32 -05:00
Andrew Gallant
ba1de61e1b
jiff-icu-0.2.1 2025-11-07 07:54:58 -05:00
Andrew Gallant
2ef6045d57
0.2.16 2025-11-07 07:53:58 -05:00
jesse
64940a824b
doc: typo fixing
Some checks are pending
ci / test-core (nightly, ubuntu-latest, nightly) (push) Waiting to run
ci / test-various-feature-combos (macos, macos-latest, nightly) (push) Waiting to run
ci / test-various-feature-combos (nightly, ubuntu-latest, nightly) (push) Waiting to run
ci / test-release (push) Waiting to run
ci / test-doc (push) Waiting to run
ci / test-bench (push) Waiting to run
ci / test-miri (push) Waiting to run
ci / win-msvc (push) Waiting to run
ci / win-gnu (push) Waiting to run
ci / msrv (push) Waiting to run
ci / examples (push) Waiting to run
ci / integrations (push) Waiting to run
ci / time-zone-init (macos-latest) (push) Waiting to run
ci / time-zone-init (ubuntu-24.04-arm) (push) Waiting to run
ci / time-zone-init (ubuntu-latest) (push) Waiting to run
ci / cross (aarch64-unknown-linux-gnu) (push) Waiting to run
ci / cross (i686-unknown-linux-gnu) (push) Waiting to run
ci / time-zone-init (windows-latest) (push) Waiting to run
ci / cross (aarch64-linux-android) (push) Waiting to run
ci / cross (powerpc-unknown-linux-gnu) (push) Waiting to run
ci / cross (powerpc64-unknown-linux-gnu) (push) Waiting to run
ci / cross (s390x-unknown-linux-gnu) (push) Waiting to run
ci / cross (x86_64-linux-android) (push) Waiting to run
ci / riscv32imc-unknown-none-elf (push) Waiting to run
ci / wasm32-wasip1 (push) Waiting to run
ci / wasm32-unknown-emscripten (push) Waiting to run
ci / wasm32-unknown-uknown (push) Waiting to run
ci / docsrs (push) Waiting to run
ci / rustfmt (push) Waiting to run
ci / generated (push) Waiting to run
Mostly found via `typos-cli` and `codespell`.

PR #443
2025-11-06 16:11:16 -05:00
Andrew Gallant
8383ebf05f
shared: remove commented out code 2025-10-23 13:12:20 -04:00
Andrew Gallant
292f18640d posix: fix handling of "permanent DST" POSIX time zone strings
See the comment in the code for explanation, but basically, this comes
from S 3.3.1 of RFC 9636:

> 3.3.1.  All-Year Daylight Saving Time
>
> DST is considered to be in effect all year if its UT offset is less
> than (i.e., west of) that of standard time, and it starts January 1
> at 00:00 and ends December 31 at 24:00 minus the difference between
> standard and daylight saving time, leaving no room for standard time
> in the calendar.  [POSIX] implies but does not explicitly state this,
> so it is spelled out here for clarity.
>
> Example: XXX3EDT4,0/0,J365/23

> This represents a time zone that is perpetually 4 hours west of UT
> and is abbreviated "EDT".  The "XXX" is ignored.

These odd time zones can occur when compiling TZif files using `zic`
with rearguard semantics. In particular, this applies for times at or
after 2087 in `Africa/Casablanca`. Rearguard semantics are used by
Jiff's `jiff-tzdb` crate, but aren't always otherwise used in standard
`/usr/share/zoneinfo` installations. As a result, this bug's effects
cannot always be consistently observed.

Fixes #386
2025-10-23 08:57:53 -04:00
Andrew Gallant
06564abdf4 dev: improve Debug experience for PosixTimeZone
This commit adds a few targeted `Debug` constraints so that
we can use `dbg!` a bit more freely.
2025-10-23 08:57:53 -04:00
Andrew Gallant
860b58a3c4 fmt/strtime: make lenient formatting more lenient
Previously, it was possible for lenient formatting to still error when
the formatting string contained invalid UTF-8. This commit alleviates
that error condition by writing a replacement character instead. This
required tweaking our UTF-8 decoding routines so that we could implement
the "substitution by maximal subparts" strategy for lossy decoding.

This now means that lenient formatting can only fail when writing to the
underlying writer fails.
2025-10-17 14:54:03 -04:00
Andrew Gallant
0099c91ec4 doc: switch from doc_auto_cfg to doc_cfg
In https://github.com/rust-lang/rust/pull/138907, the `doc_auto_cfg`
feature was subsumed by `doc_cfg`. This does overall looks like we're on
a path toward stabilization, which is great.

One problem here though is that a bunch of crates use the `cfg`
`docsrs` to enable `doc_auto_cfg`. So if we enable it, then it causes
those crates to emit hard errors. This is overall very annoying, and
I don't know how to unfuck things. So I changed the `cfg` knob to
`docsrs_jiff` which, doesn't quite provide a guarantee, but gets us
closer to being masters of our own destiny.

See also a similar change made to `regex`:
https://github.com/rust-lang/regex/pull/1305
2025-10-13 12:50:49 -04:00
Andrew Gallant
5dcabd788d tz: fix panicking bug in TZif parser
Some checks are pending
ci / test-only-bundle (macos, macos-latest, nightly) (push) Waiting to run
ci / test-only-bundle (nightly, ubuntu-latest, nightly) (push) Waiting to run
ci / test-core (macos, macos-latest, nightly) (push) Waiting to run
ci / test-core (nightly, ubuntu-latest, nightly) (push) Waiting to run
ci / test-various-feature-combos (macos, macos-latest, nightly) (push) Waiting to run
ci / win-msvc (push) Waiting to run
ci / win-gnu (push) Waiting to run
ci / msrv (push) Waiting to run
ci / examples (push) Waiting to run
ci / integrations (push) Waiting to run
ci / time-zone-init (macos-latest) (push) Waiting to run
ci / time-zone-init (ubuntu-24.04-arm) (push) Waiting to run
ci / time-zone-init (ubuntu-latest) (push) Waiting to run
ci / test-default (nightly, ubuntu-latest, nightly) (push) Waiting to run
ci / test-default (stable, ubuntu-latest, stable) (push) Waiting to run
ci / test-all (macos, macos-latest, nightly) (push) Waiting to run
ci / test-all (nightly, ubuntu-latest, nightly) (push) Waiting to run
ci / cross (aarch64-linux-android) (push) Waiting to run
ci / cross (aarch64-unknown-linux-gnu) (push) Waiting to run
ci / cross (i686-unknown-linux-gnu) (push) Waiting to run
ci / cross (powerpc-unknown-linux-gnu) (push) Waiting to run
ci / cross (powerpc64-unknown-linux-gnu) (push) Waiting to run
ci / cross (s390x-unknown-linux-gnu) (push) Waiting to run
ci / cross (x86_64-linux-android) (push) Waiting to run
ci / riscv32imc-unknown-none-elf (push) Waiting to run
ci / wasm32-wasip1 (push) Waiting to run
ci / wasm32-unknown-emscripten (push) Waiting to run
ci / wasm32-unknown-uknown (push) Waiting to run
ci / rustfmt (push) Waiting to run
ci / generated (push) Waiting to run
This can only happen when malformed TZif data is given. Generally
speaking, Jiff treats TZif data as untrusted and promises not to panic
when given malformed data. So this is something that ought to be fixed.
However, it's rare to use untrusted TZif data in practice.

In this specific case, we were assuming that the time zone designation
list was always terminated by NUL.

Fixes #423
2025-10-08 12:18:36 -04:00
Andrew Gallant
962edee175 shared: fix some panics in POSIX time zone parsing caught by a fuzzer
The first one here was pretty embarrassing: the parser panicked on the
empty string.

The others were a bit subtler and had to do with incorrect construction
of error messages. Arguably, more tests for the error cases here ought
to be added.

Fixes #407
2025-09-25 20:56:19 -04:00
Andrew Gallant
8842b0fcf7
0.2.15 2025-06-13 14:21:41 -04:00
Andrew Gallant
8105228403
0.2.14 2025-05-20 15:55:34 -04:00
Andrew Gallant
4e4939d199
jiff-icu: bump ICU4X to 2.0.0 2025-05-08 16:52:55 -04:00
Andrew Gallant
e729efaea3 jiff-icu: upgrade to ICU4X 2.0.0
This mostly just involved doing some renames.
2025-05-08 16:52:13 -04:00
Andrew Gallant
5d60f33c58
0.2.13 2025-05-05 22:06:38 -04:00
Andrew Gallant
d6bae333b0
0.2.12 2025-05-03 09:21:58 -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
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
e2f8b9a7c9
0.2.9 2025-04-19 15:02:40 -04:00
Andrew Gallant
d27af19fe2
0.2.8 2025-04-13 17:59:11 -04:00
Andrew Gallant
3e32e71ac8
0.2.7 2025-04-13 14:08:10 -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
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
0541c1979c cargo: restore sanity to iterative development
I'm not sure when or how exactly it happened, but in the last weeks,
I've noticed that `rustc` gets effectively stun-locked whenever I make a
change to a source file in Jiff. A quick examination of what the fuck my
computer is doing seems to reveal that it's spending oodles of time
compiling diesel over and over.

I have no idea why this is happening and I don't really care to spend
the time unraveling the mysteries of diesel.

So I took a hammer to the problem. I have effectively shunted all
examples and all "integration" crates out of Jiff's core workspace and
into their own little bloated fiefdoms. To compensate for the fact that
`cargo test --all` no longer tests these things, I've added shell
scripts to run the requisite tests. And those shell scripts are now run
in CI.

I'm now back to a state where I can save a file in Jiff and I get
sub-second `cargo check` response times.
2025-04-10 20:54:30 -04:00
Andrew Gallant
0bdb3b0207
0.2.6 2025-04-07 17:21:51 -04:00
Andrew Gallant
8d9ff39020
0.2.5 2025-03-22 20:40:58 -04:00
Andrew Gallant
939549520e
jiff-tzdb-platform-0.1.3 2025-03-22 20:39:37 -04:00
Andrew Gallant
ebd7ee41f3
deps: bump to jiff-tzdb 0.1.4 2025-03-22 20:39:28 -04:00
Andrew Gallant
3ff4513edf
jiff-tzdb-0.1.4 2025-03-22 20:38:00 -04:00
Andrew Gallant
e616bf975b jiff-tzdb: update to tzdb 2025b
Note that this adds a new time zone with
identifier `America/Coyhaique`.

Ref: https://lists.iana.org/hyperkitty/list/tz-announce@iana.org/thread/6JVHNHLB6I2WAYTQ75L6KEPEQHFXAJK3/
2025-03-22 20:35:11 -04:00
Andrew Gallant
4404fb0f6b
0.2.4 2025-03-10 18:35:37 -04:00
Andrew Gallant
0a0b5a0bee
jiff-static: improve README
This was still the copy from `jiff-tzdb`. Update it to be about
`jiff-static`.
2025-03-10 07:54:20 -04:00
Andrew Gallant
fc9e02dfdf
0.2.3 2025-03-07 08:43:20 -05:00
Andrew Gallant
624ffc7cf8
0.2.2 2025-03-06 16:35:45 -05:00
Andrew Gallant
c7edc0a105
jiff-static: fix crate layout
I wasn't sure why `cargo package` wasn't picking up
`crates/jiff-static/shared`. So I switched to a traditional `src`
layout, which shouldn't be necessary. Indeed, that didn't fix things.
Turns out, I had a bunk `include` rule.

But I wanted to switch to the `src` scheme anyway, so leave that.
2025-03-06 16:34:30 -05:00
Andrew Gallant
08571714a9
jiff-tzdb-0.1.3 2025-03-06 16:28:38 -05:00
Andrew Gallant
300886fef3
jiff-diesel-0.1.3 2025-03-06 16:28:21 -05:00
Andrew Gallant
252a0806dc
jiff-sqlx-0.1.1 2025-03-06 16:28:08 -05:00
Andrew Gallant
9a23a442af jiff-static: update shared copy of code 2025-03-06 10:09:11 -05:00
Andrew Gallant
98164d6263 tz: pack TZif civil datetime into i64
This leads to amazing speed-ups for TZ lookups on civil datetimes:

    tz/posix_datetime_to_offset/jiff               1.00     32.6±0.70ns        ? ?/sec    1.01     32.9±0.28ns        ? ?/sec
    tz/posix_timestamp_to_offset/jiff              1.00     21.8±0.17ns        ? ?/sec    1.04     22.6±0.15ns        ? ?/sec
    tz/tzif_bundled_datetime_to_offset/jiff        2.57     23.4±0.19ns        ? ?/sec    1.00      9.1±0.06ns        ? ?/sec
    tz/tzif_bundled_timestamp_to_offset/jiff       1.00      6.0±0.05ns        ? ?/sec    1.04      6.2±0.05ns        ? ?/sec
    tz/tzif_future_datetime_to_offset/jiff         1.35     50.5±0.60ns        ? ?/sec    1.00     37.4±0.67ns        ? ?/sec
    tz/tzif_future_timestamp_to_offset/jiff        1.00     21.2±0.15ns        ? ?/sec    1.00     21.2±0.17ns        ? ?/sec
    tz/tzif_historical_datetime_to_offset/jiff     2.68     23.4±0.17ns        ? ?/sec    1.00      8.7±0.08ns        ? ?/sec
    tz/tzif_historical_timestamp_to_offset/jiff    1.00      6.0±0.05ns        ? ?/sec    1.00      6.0±0.05ns        ? ?/sec

It turns out that comparing civil datetimes is actually quite
expensive. Getting them down to a single integer comparison makes
the binary search much quicker.
2025-03-05 18:48:44 -05:00
Andrew Gallant
f6a5cc6a22 tz: refactor TZif representation to use column storage
This makes binary search for TZ lookups substantially faster.

This is yet another brutal refactor. Changing anything in POSIX time
zones or TZif handling is now a monster pain in the ass because all
of that code is shared in a very awkward way with `jiff-static`.

Ref #271
2025-03-05 18:48:44 -05:00