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

Allow configure nanosecond's precision #92

Closed
tisonkun opened this issue Aug 11, 2024 · 1 comment · Fixed by #114
Closed

Allow configure nanosecond's precision #92

tisonkun opened this issue Aug 11, 2024 · 1 comment · Fixed by #114
Labels
enhancement New feature or request

Comments

@tisonkun
Copy link

tisonkun commented Aug 11, 2024

Background - fast/logforth#40 (comment)

Currently, the default formatter can cause unaligned nanosecond:

2024-08-11T13:47:37.947497+00:00[UTC] ERROR simple_stdio: examples/simple_stdio.rs:32 Hello error!
2024-08-11T13:47:37.98353+00:00[UTC]  WARN simple_stdio: examples/simple_stdio.rs:33 Hello warn!
2024-08-11T13:47:37.983557+00:00[UTC]  INFO simple_stdio: examples/simple_stdio.rs:34 Hello info!
2024-08-11T13:47:37.983579+00:00[UTC] DEBUG simple_stdio: examples/simple_stdio.rs:35 Hello debug!
2024-08-11T13:47:37.983602+00:00[UTC] TRACE simple_stdio: examples/simple_stdio.rs:36 Hello trace!

@BurntSushi suggests we can make it configurable at both:

Record for any improvement chance.

@BurntSushi BurntSushi added the enhancement New feature or request label Aug 11, 2024
BurntSushi added a commit that referenced this issue Aug 23, 2024
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
@tisonkun
Copy link
Author

Used in fast/logforth#58.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants