Module format
Formatting (and parsing) utilities for date and time.
This module provides the common types and routines to implement,
for example, DateTime::format or
DateTime::parse_from_str methods.
For most cases you should use these high-level interfaces.
Internally the formatting and parsing shares the same abstract formatting items,
which are just an Iterator of
the Item type.
They are generated from more readable format strings;
currently Chrono supports a built-in syntax closely resembling
C's strftime format. The available options can be found here.
Example
#
# Ok::
Modules
-
strftime
strftime/strptime-inspired date and time formatting syntax.
Structs
-
DelayedFormat
A temporary object which can be used as an argument to
format!or others. This is normally constructed viaformatmethods of each date and time type. - InternalFixed An opaque type representing fixed-format item types for internal uses only.
- InternalNumeric An opaque type representing numeric item types for internal uses only.
- OffsetFormat Type for specifying the format of UTC offsets.
-
ParseError
An error from the
parsefunction. - Parsed A type to hold parsed fields of date and time that can check all fields are consistent.
-
StrftimeItems
Parsing iterator for
strftime-like format strings.
Enums
- Colons The separator between hours and minutes in an offset.
- Fixed Fixed-format item types.
- Item A single formatting item. This is used for both formatting and parsing.
- Numeric Numeric item types. They have associated formatting width (FW) and parsing width (PW).
- OffsetPrecision The precision of an offset from UTC formatting item.
- Pad Padding characters for numeric items.
- ParseErrorKind The category of parse error
- SecondsFormat Specific formatting options for seconds. This may be extended in the future, so exhaustive matching in external code is not recommended.
Functions
-
format
Tries to format given arguments with given formatting items.
Internally used by
DelayedFormat. - format_item Formats single formatting item
-
parse
Tries to parse given string into
parsedwith given formatting items. ReturnsOkwhen the entire string has been parsed (otherwiseparsedshould not be used). There should be no trailing string after parsing; use a strayItem::Spaceto trim whitespaces. -
parse_and_remainder
Tries to parse given string into
parsedwith given formatting items. ReturnsOkwith a slice of the unparsed remainder.
Type Aliases
-
ParseResult
Same as
Result<T, ParseError>.