Skip to content

Commit

Permalink
Additional section on modifiers and padding, move traits details afte…
Browse files Browse the repository at this point in the history
…r introduction for better flow (#10)
  • Loading branch information
softdevca authored Apr 2, 2024
1 parent 51ac452 commit 5ecface
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/api/format-description.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 5ecface

Please sign in to comment.