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.)
This PR introduces new options for controlling the precision of fractional seconds when printing
Zoned
,Timestamp
,civil::DateTime
orcivil::Time
values. This is principally exposed viajiff::fmt::temporal::DateTimePrinter::precision
, but it's also available via the standard library's formatting machinery. For example, ifzdt
is ajiff::Zoned
, thenformat!("{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 allZoned
values in a particular context, then setting the precision will provide fixed width. (Unless the years are negative.)Closes #92