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

fmt/strtime: support parsing and formatting fractional seconds #55

Merged
merged 1 commit into from
Jul 28, 2024

Conversation

BurntSushi
Copy link
Owner

This isn't supported in the analogous C APIs, but it turns out it was
supported in the chrono crate and was actually being used.

This adds two new directives, %f and %.f. The former always writes
out at least one digit (and parsing requires at least one digit) and
corresponds to the number of fractional nanoseconds. The latter includes
the leading . and is satisfied by the empty string. That is, if a .
isn't found when %.f is expected, then it is skipped entirely when
parsing. Similarly, when formatting, if there are no fractional seconds
(i.e., the subsecond component is 0), then no fractional component is
written either.

It is expected that most use cases will reach for just %.f, since it
will just do the "right" thing without thinking much about it. For
example, %H:%M:%S%.f will parse both 23:30:01 and 23:30:01.789.

Closes #54

This isn't supported in the analogous C APIs, but it turns out it was
supported in the `chrono` crate and was actually being used.

This adds two new directives, `%f` and `%.f`. The former always writes
out at least one digit (and parsing requires at least one digit) and
corresponds to the number of fractional nanoseconds. The latter includes
the leading `.` and is satisfied by the empty string. That is, if a `.`
isn't found when `%.f` is expected, then it is skipped entirely when
parsing. Similarly, when formatting, if there are no fractional seconds
(i.e., the subsecond component is `0`), then no fractional component is
written either.

It is expected that most use cases will reach for just `%.f`, since it
will just do the "right" thing without thinking much about it. For
example, `%H:%M:%S%.f` will parse both `23:30:01` and `23:30:01.789`.

Closes #54
@BurntSushi BurntSushi force-pushed the ag/strtime-fractional-second branch from 77dc509 to 10181ab Compare July 28, 2024 22:10
@BurntSushi BurntSushi merged commit 5be8343 into master Jul 28, 2024
14 checks passed
@BurntSushi BurntSushi deleted the ag/strtime-fractional-second branch July 28, 2024 22:10
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.

add support for fractional seconds to jiff::fmt::strtime
1 participant