Skip to main content

Crate time_compute

Crate time_compute 

Source
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 as Duration, its historical name in chrono), 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, Copy set of weekdays.
  • round: rounding/truncating a date-time by a TimeDelta span or by a number of subsecond digits (DurationRound, SubsecRound).
  • serde (crate feature serde) and rkyv (crate features rkyv/rkyv-16/rkyv-32/rkyv-64/rkyv-validation): optional (de)serialization support, disabled by default.
  • Locale (crate feature unstable-locales): locale-aware formatting via NaiveDate::format_localized/DateTime::format_localized (and the _with_items variants), matching chrono’s own unstable-locales feature name and “unstable” semantics 1:1. Falls back to English-only formatting when the feature is disabled.
  • Crate feature arbitrary: arbitrary::Arbitrary support (for fuzzing) on the same set of public types as chrono.
  • Crate feature defmt: defmt::Format support (compact Debug-like output for embedded/no_std targets) 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§

DateTime
A date and time of day, together with a time zone.
Days
An increment expressed in days, used with NaiveDate::checked_add_days and related methods.
FixedOffset
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 with NaiveDate::checked_add_months.
NaiveDate
A date in the proleptic Gregorian calendar (year, month, day), without a time of day or time zone.
NaiveDateTime
A date and time of day combined (proleptic Gregorian calendar), without an associated time zone.
NaiveTime
A time of day, with nanosecond precision and optional leap-second representation, but no associated date or time zone.
NaiveWeek
The week that a NaiveDate belongs to, anchored on a chosen starting weekday. Obtained via NaiveDate::week.
OutOfRange
Error returned when converting an out-of-range number to a Month.
OutOfRangeError
Error returned by TimeDelta::from_std/TimeDelta::to_std when the source value is out of range for the target type.
ParseMonthError
Error returned when a string does not match any month name.
ParseWeekdayError
Error returned when a string does not match any weekday name.
TimeDelta
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).
WeekdaySet
A set of Weekdays, packed into a single byte.

Enums§

JapaneseEra
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 the unstable-locales feature is enabled). Locales matching the locales in glibc.
MappedLocalTime
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, January to December.
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.
TimeZone
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 with chrono::Duration (the historical name of this type).
LocalResult
Historical name of MappedLocalTime. See that type for documentation.