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

api: add options for controlling precision #114

Merged
merged 1 commit into from
Aug 23, 2024
Merged

Conversation

BurntSushi
Copy link
Owner

This PR introduces new options for controlling the precision
of fractional seconds when printing Zoned, Timestamp,
civil::DateTime or civil::Time values. This is principally exposed
via jiff::fmt::temporal::DateTimePrinter::precision, but it's also
available via the standard library's formatting machinery. For example,
if zdt is a jiff::Zoned, then format!("{zdt:.6}") will format
it into a string with microsecond precision, even if its fractional
component is zero.

This is useful when one wants a datetime to use a "fixed width" format.
Or at least, as close to one as possible. For Zoned in particular, a
fixed width format is somewhat difficult to accomplish because of the
variable length IANA time zone identifier. But if the time zone
identifier is the same for all Zoned values in a particular context,
then setting the precision will provide fixed width. (Unless the years
are negative.)

Closes #92

This PR introduces new options for controlling the precision
of fractional seconds when printing `Zoned`, `Timestamp`,
`civil::DateTime` or `civil::Time` values. This is principally exposed
via `jiff::fmt::temporal::DateTimePrinter::precision`, but it's also
available via the standard library's formatting machinery. For example,
if `zdt` is a `jiff::Zoned`, then `format!("{zdt:.6}")` will format
it into a string with microsecond precision, even if its fractional
component is zero.

This is useful when one wants a datetime to use a "fixed width" format.
Or at least, as close to one as possible. For `Zoned` in particular, a
fixed width format is somewhat difficult to accomplish because of the
variable length IANA time zone identifier. But if the time zone
identifier is the same for all `Zoned` values in a particular context,
then setting the precision will provide fixed width. (Unless the years
are negative.)

Closes #92
@BurntSushi BurntSushi merged commit 1290ff3 into master Aug 23, 2024
17 checks passed
@BurntSushi BurntSushi deleted the ag/precision branch August 23, 2024 23:06
@BurntSushi
Copy link
Owner Author

This PR is on crates.io in jiff 0.1.9.

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.

Allow configure nanosecond's precision
1 participant