Skip to content

feat: add optional jiff as chrono replacement - #1120

Open
tziemek wants to merge 2 commits into
oxidecomputer:mainfrom
tziemek:feat/jiff-feature
Open

tziemek wants to merge 2 commits into
oxidecomputer:mainfrom
tziemek:feat/jiff-feature

Conversation

@tziemek

@tziemek tziemek commented Nov 24, 2026

Copy link
Copy Markdown

resolves #1111

date and date-time string formats are now mapped to a date library chosen by Cargo feature. chrono stays the default, so existing output is unchanged. jiff is available as an alternative, and it takes precedence when both are enabled. With neither feature, dates are plain Strings.

Changes:

  • typify-impl has chrono (default) and jiff marker features. typify emits the paths and never links either crate, so these only select which path is generated
  • typify, typify-macro, and cargo-typify forward the features.
  • Workspace entries for typify, typify-impl, and typify-macro now set default-features = false. Cargo doesn't allow a member to override default-features on an inherited dependency, so this is the only way to let each crate choose.

Remarks:

  • The jiff types omit JsonSchema. schemars 0.8, which typify uses, has no jiff impl.
  • A type that requires JsonSchema and holds a jiff date is refused when rendered, with an error naming ::jiff::Timestamp.
  • chrono golden files only run under chrono
  • workspace-inherited crates must now pick features!
  • jiffs Timestamp is not chronos DateTime, API differs

@tziemek
tziemek marked this pull request as ready for review November 24, 2026 10:24
@ahl

ahl commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

I haven't looked at this closely, but first:

  1. I'm not sure a feature flag makes sense here; did you consider a generation input setting?
  2. I didn't realize that jiff lacks a JsonSchema impl; that would be a good PR for jiff (since schemars is in one of its dormant periods)

@tziemek

tziemek commented Nov 26, 2026

Copy link
Copy Markdown
Author

I haven't looked at this closely, but first:

1. I'm not sure a feature flag makes sense here; did you consider a generation input setting?

Actually I haven't, feature flag was my initial gut feeling. But you may be right. As chrono is only a dev dependency it wouldn't pollute consumer code when the generated code doesn't need it. I'll change it to a generation input setting.

2. I didn't realize that jiff lacks a JsonSchema impl; that would be a good PR for jiff (since schemars is in one of its dormant periods)

schemars has an open PR GREsau/schemars#547 for adding jiff support, but this would only work if we update schemars to 1.x (as far as I can see), which has its own difficulties.

@ahl ahl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

took a quick pass

Comment on lines +869 to +870
(format, _) => {
self.convert_format(type_name, original_schema, metadata, format, validation)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems a bit odd. convert_format is convert_string minus date and date-time?

.into_iter()
.collect::<TypespaceTraitSet>(),
),
TypeEntry::new_native(date_path(format, library), date_traits(library)),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps date_path and date_traits and be in the same function that just returns the TypeEntry

Comment thread cargo-typify/src/lib.rs
value_parser = ["chrono", "jiff", "string"],
default_value = "chrono"
)]
date_library: String,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet this could be the enum rather than a string

Comment thread typify-impl/src/lib.rs
Comment on lines +129 to 133
/// The crates needed for native types: `uuid` and the date library
/// (`chrono` or `jiff`) for the string formats they map to, and each crate an `x-rust-type` extension
/// names, at the version [`TypeSpaceSettings::with_crate`] declared for
/// it. Recorded on the `TypespaceBuilder` so the finalized typespace
/// reports them with the crates of what typespace renders itself.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap

Comment thread typify-impl/src/lib.rs
Comment on lines +264 to +266
/// Plain `String`s. Length and pattern constraints still apply; the format
/// itself is not validated.
String,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain that the benefit is no dependency

@@ -0,0 +1,176 @@
#![deny(warnings)]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not make a new subdirectory; follow an existing pattern for this

Comment thread CHANGELOG.adoc
Comment on lines +22 to +25
* The `date` and `date-time` string formats can be represented by `chrono`
(the default), `jiff`, or plain `String`s, chosen per generation with
`DateLibrary` (`date_library` in the macro, `--date-library` in the CLI).
Types from `jiff` do not implement `JsonSchema`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The `date` and `date-time` string formats can be represented by `chrono`
(the default), `jiff`, or plain `String`s, chosen per generation with
`DateLibrary` (`date_library` in the macro, `--date-library` in the CLI).
Types from `jiff` do not implement `JsonSchema`.
* The `date` and `date-time` string formats can be represented using `chrono`
(the default) or `jiff`, or as `String`s, chosen via generation settings
`DateLibrary` (`date_library` in the macro, `--date-library` in the CLI).
NB: types from `jiff` do not implement `JsonSchema`.

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.

Replacement for chrono

2 participants