Skip to content

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

Merged
BurntSushi merged 1 commit intomasterfrom
ag/strtime-fractional-second
Jul 28, 2024
Merged

fmt/strtime: support parsing and formatting fractional seconds#55
BurntSushi merged 1 commit intomasterfrom
ag/strtime-fractional-second

Conversation

@BurntSushi
Copy link
Copy Markdown
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
@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