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

Section on modifiers and padding #10

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/api/format-description.md
Original file line number Diff line number Diff line change
@@ -15,16 +15,7 @@
# Format description

A format description is the manner in which the time crate knows how a value should be formatted and
parsed. However, a format description is not a single type; it is instead represented by two
internal traits (one for formatting and one for parsing) that are implemented by a number of types.
Currently, all types that implement one trait also implement the other, but this is not guaranteed.

The following types currently implement both the `Formattable` and `Parsable` traits:

- `FormatItem<'_>`
- `[FormatItem<'_>]`
- `T where <T as Deref>::Target: Formattable` (or `Parsable`)
- All [well known formats](./well-known-format-descriptions.md)
parsed.

While it is possible to construct a format description manually, this is generally not recommended,
as it is more tedious and less readable than the alternative. Unless you are doing this, you will
@@ -47,6 +38,27 @@ to have both consecutive literals and consecutive components. Components must be
between brackets with optional whitespace. Escaping behavior varies by version, and is described
below.

## Modifiers

Many of the components have optional modifiers to change how it is formatted or parsed.

The `padding` modifier, such as used on the `hour` and `month` components can be padded
with `space`, `zero` or `none`. In the case of `none` leading zeros are still accepted during
parsing.

## Traits

A format description is not a single type; it is instead represented by two
internal traits (one for formatting and one for parsing) that are implemented by a number of types.
Currently, all types that implement one trait also implement the other, but this is not guaranteed.

The following types currently implement both the `Formattable` and `Parsable` traits:

- `FormatItem<'_>`
- `[FormatItem<'_>]`
- `T where <T as Deref>::Target: Formattable` (or `Parsable`)
- All [well known formats](./well-known-format-descriptions.md)

## Versioning

There are multiple versions of the format description syntax in `time`. Similar to Rust editions,