Skip to content

buffa-types: add jiff feature (Timestamp/Duration conversions)#264

Open
macalinao wants to merge 3 commits into
anthropics:mainfrom
macalinao:jiff
Open

buffa-types: add jiff feature (Timestamp/Duration conversions)#264
macalinao wants to merge 3 commits into
anthropics:mainfrom
macalinao:jiff

Conversation

@macalinao

Copy link
Copy Markdown
Contributor

Summary

Adds a jiff Cargo feature to buffa-types providing conversions between the protobuf well-known types and jiff, mirroring the existing chrono feature:

  • Timestampjiff::Timestamp — reuses the shared TimestampError (InvalidNanos + Overflow). jiff::Timestamp reports sub-second nanos sign-consistently (negative pre-epoch), so the From impl re-normalizes to proto's always-non-negative nanos convention by borrowing a second.
  • Durationjiff::SignedDurationSignedDuration is the faithful analog of proto Duration (sign-consistent seconds + sub-second nanos; jiff::Span is deliberately not a target since its calendar units have no fixed length). Introduces a narrow DurationJiffError with only InvalidNanos: a validated proto Duration can never overflow SignedDuration.

Details

  • no_std-compatible: jiff is pulled with default-features = false + alloc; buffa-types' std feature layers jiff/std on top via jiff?/std.
  • Wired into buffa-test so the conversions are exercised by cargo test --workspace in CI (parity with chrono).
  • jiff 0.2 declares MSRV 1.70, within buffa's 1.75 pin (so msrv-check stays green).
  • Thorough unit + doc tests: pre-epoch borrow, exact-second pre-epoch, nanos boundaries, both jiff::Timestamp extremes, both SignedDuration extremes, i32::MIN nanos, bidirectional sign-mismatch rejection.

Checks

  • cargo test -p buffa-types --features jiff
  • cargo clippy -p buffa-types --features jiff ✅ (clean)
  • cargo check -p buffa-types --no-default-features --features jiff ✅ (no_std)
  • cargo fmt --check
  • Changelog fragment added under .changes/unreleased/.

Reviewed pre-submission by the repo's rust-code-reviewer (no Critical/High/Medium correctness findings) and rust-api-ergonomics-reviewer (the flagged missing "proto JSON spec range" doc warning on the infallible From impls has been added for chrono parity).

Add a `jiff` Cargo feature to buffa-types providing conversions between
the protobuf well-known types and the jiff crate, mirroring the existing
`chrono` feature:

- Timestamp <-> jiff::Timestamp (reuses TimestampError; jiff's
  sign-consistent subsec nanos are re-normalized to proto's non-negative
  nanos convention by borrowing a second pre-epoch).
- Duration <-> jiff::SignedDuration (new DurationJiffError with only
  InvalidNanos: SignedDuration's range is wide enough that a validated
  proto Duration never overflows it).

no_std-compatible (jiff pulled with default-features=false + alloc); the
std feature layers jiff/std on top. Wired into buffa-test for CI coverage.
jiff 0.2 MSRV is 1.70, within buffa's 1.75 pin.
@github-actions

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

- Drop inline comments that restate the doc/code; keep the load-bearing
  underflow- and overflow-safety rationale.
- Add a no_std jiff check to the check-nostd task (parity with chrono).
@macalinao macalinao marked this pull request as ready for review June 29, 2026 08:46
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