Expand description
time_compute — a date/time computation library, with no external
dependency for its core (dates, times, durations). A few exceptions
are allowed: time zone handling (see offset), which relies on the
tzdb/tz-rs crates to read the IANA time zone database; and a
handful of optional, disabled-by-default crate features –
serde/rkyv (de)serialization (see the serde and rkyv
modules), unstable-locales (locale-aware formatting, see
Locale), arbitrary (fuzzing support), and defmt (compact
embedded-friendly formatting) – each matching chrono’s own optional
feature of the same name 1:1.
Goal: offer an API as close as possible to chrono’s (same type names,
same methods, same behaviour), so that a project using chrono can
migrate by simply replacing use chrono::... with
use time_compute::.... The source code itself is entirely original.
§Current status
NaiveDate: a date without a time zone (proleptic Gregorian calendar), with day/month arithmetic and ISO 8601 weeks.NaiveTime: a time of day, with nanosecond precision and leap second support.NaiveDateTime: a date and time of day combined, without a time zone.TimeDelta(also available asDuration, its historical name inchrono),Days,Months: durations and calendar increments.Weekday,Month,Datelike,Timelike: weekday, month, and access to a date’s or time’s components.Utc,Local,FixedOffset,DateTime<Tz>,TimeZone,Offset,MappedLocalTime: time zones and timezone-aware date/times.- [
format]:strftime-style formatting and parsing (StrftimeItems,Parsed, RFC 2822/3339 helpers). WeekdaySet: a compact,Copyset of weekdays.round: rounding/truncating a date-time by aTimeDeltaspan or by a number of subsecond digits (DurationRound,SubsecRound).serde(crate featureserde) andrkyv(crate featuresrkyv/rkyv-16/rkyv-32/rkyv-64/rkyv-validation): optional (de)serialization support, disabled by default.Locale(crate featureunstable-locales): locale-aware formatting viaNaiveDate::format_localized/DateTime::format_localized(and the_with_itemsvariants), matching chrono’s ownunstable-localesfeature name and “unstable” semantics 1:1. Falls back to English-only formatting when the feature is disabled.- Crate feature
arbitrary:arbitrary::Arbitrarysupport (for fuzzing) on the same set of public types as chrono. - Crate feature
defmt:defmt::Formatsupport (compactDebug-like output for embedded/no_stdtargets) on the same set of public types as chrono.
Re-exports§
pub use datetime::MAX_DATETIME;Deprecated pub use datetime::MIN_DATETIME;Deprecated pub use format::ParseError;pub use format::ParseResult;pub use format::SecondsFormat;pub use round::DurationRound;pub use round::RoundingError;pub use round::SubsecRound;
Modules§
- format
- Formatting (and parsing) utilities for date and time.
- naive
- “Naive” date/time types, i.e. without an associated time zone.
- offset
- Time zones: computing the offset between a local time and UTC.
- rkyv
- Zero-copy (de)serialization with
rkyv. - round
- Rounding and truncating dates/times by a fixed span (subsecond digits or
an arbitrary
TimeDelta). - serde
- Serialization/Deserialization with
serde.
Structs§
- Date
Time - A date and time of day, together with a time zone.
- Days
- An increment expressed in days, used with
NaiveDate::checked_add_daysand related methods. - Fixed
Offset - A time zone with a fixed offset from UTC, from UTC-23:59:59 to UTC+23:59:59.
- IsoWeek
- A week in the ISO 8601 calendar (ISO year + week number).
- Local
- The system’s local time zone.
- Months
- An increment expressed in months (calendar arithmetic, distinct from
TimeDelta), used withNaiveDate::checked_add_months. - Naive
Date - A date in the proleptic Gregorian calendar (year, month, day), without a time of day or time zone.
- Naive
Date Time - A date and time of day combined (proleptic Gregorian calendar), without an associated time zone.
- Naive
Time - A time of day, with nanosecond precision and optional leap-second representation, but no associated date or time zone.
- Naive
Week - The week that a
NaiveDatebelongs to, anchored on a chosen starting weekday. Obtained viaNaiveDate::week. - OutOf
Range - Error returned when converting an out-of-range number to a
Month. - OutOf
Range Error - Error returned by
TimeDelta::from_std/TimeDelta::to_stdwhen the source value is out of range for the target type. - Parse
Month Error - Error returned when a string does not match any month name.
- Parse
Weekday Error - Error returned when a string does not match any weekday name.
- Time
Delta - A signed span of time, with nanosecond precision.
- Utc
- The UTC time zone. The most efficient time zone when the local time is
not needed. Also used as its own
Offset(a dummy, zero-sized one). - Weekday
Set - A set of
Weekdays, packed into a single byte.
Enums§
- Japanese
Era - A modern Japanese era (“nengo”, 元号), one per imperial reign since the “one reign, one era name” system was formalized in 1868 (law-codified in 1979).
- Locale
- Re-exported at the crate root as
time_compute::Locale(only when theunstable-localesfeature is enabled). Locales matching the locales inglibc. - Mapped
Local Time - The result of mapping a local time to a concrete instant in a given time zone: a single unambiguous result, an ambiguous result (the local time falls in a “fold”, e.g. when clocks are turned back for DST), or no result at all (the local time falls in a “gap”, e.g. when clocks are turned forward).
- Month
- The month of the year,
JanuarytoDecember. - Weekday
- A day of the week, from Monday to Sunday (ISO 8601 convention: the week starts on Monday).
Traits§
- Datelike
- Read access to the components of a date.
- Offset
- The offset from a local time to UTC, associated with a given
TimeZone. - Time
Zone - A time zone: computes the offset(s) between UTC and local time.
- Timelike
- Read access to the components of a time of day.
Type Aliases§
- Duration
- Alias of
TimeDelta, kept for compatibility withchrono::Duration(the historical name of this type). - Local
Result - Historical name of
MappedLocalTime. See that type for documentation.