Skip to main content

time_compute/
lib.rs

1//! `time_compute` — a date/time computation library, with no external
2//! dependency for its core (dates, times, durations). A few exceptions
3//! are allowed: time zone handling (see [`offset`]), which relies on the
4//! `tzdb`/`tz-rs` crates to read the IANA time zone database; and a
5//! handful of optional, disabled-by-default crate features --
6//! `serde`/`rkyv` (de)serialization (see the [`serde`] and [`rkyv`]
7//! modules), `unstable-locales` (locale-aware formatting, see
8//! [`Locale`]), `arbitrary` (fuzzing support), and `defmt` (compact
9//! embedded-friendly formatting) -- each matching chrono's own optional
10//! feature of the same name 1:1.
11//!
12//! Goal: offer an API as close as possible to `chrono`'s (same type names,
13//! same methods, same behaviour), so that a project using `chrono` can
14//! migrate by simply replacing `use chrono::...` with
15//! `use time_compute::...`. The source code itself is entirely original.
16//!
17//! # Current status
18//! - [`NaiveDate`]: a date without a time zone (proleptic Gregorian
19//!   calendar), with day/month arithmetic and ISO 8601 weeks.
20//! - [`NaiveTime`]: a time of day, with nanosecond precision and leap
21//!   second support.
22//! - [`NaiveDateTime`]: a date and time of day combined, without a time
23//!   zone.
24//! - [`TimeDelta`] (also available as [`Duration`], its historical name in
25//!   `chrono`), [`Days`], [`Months`]: durations and calendar increments.
26//! - [`Weekday`], [`Month`], [`Datelike`], [`Timelike`]: weekday, month,
27//!   and access to a date's or time's components.
28//! - [`Utc`], [`Local`], [`FixedOffset`], [`DateTime<Tz>`](DateTime),
29//!   [`TimeZone`], [`Offset`], [`MappedLocalTime`]: time zones and
30//!   timezone-aware date/times.
31//! - [`format`]: `strftime`-style formatting and parsing (`StrftimeItems`,
32//!   `Parsed`, RFC 2822/3339 helpers).
33//! - [`WeekdaySet`]: a compact, `Copy` set of weekdays.
34//! - [`round`]: rounding/truncating a date-time by a [`TimeDelta`] span or
35//!   by a number of subsecond digits ([`DurationRound`], [`SubsecRound`]).
36//! - [`serde`] (crate feature `serde`) and [`rkyv`] (crate features
37//!   `rkyv`/`rkyv-16`/`rkyv-32`/`rkyv-64`/`rkyv-validation`): optional
38//!   (de)serialization support, disabled by default.
39//! - [`Locale`] (crate feature `unstable-locales`): locale-aware formatting
40//!   via `NaiveDate::format_localized`/`DateTime::format_localized` (and
41//!   the `_with_items` variants), matching chrono's own
42//!   `unstable-locales` feature name and "unstable" semantics 1:1. Falls
43//!   back to English-only formatting when the feature is disabled.
44//! - Crate feature `arbitrary`: `arbitrary::Arbitrary` support (for
45//!   fuzzing) on the same set of public types as chrono.
46//! - Crate feature `defmt`: `defmt::Format` support (compact `Debug`-like
47//!   output for embedded/`no_std` targets) on the same set of public
48//!   types as chrono.
49
50#![forbid(unsafe_code)]
51
52mod buddhist_calendar;
53mod calendar;
54mod chinese_calendar;
55mod datetime;
56mod duration;
57pub mod format;
58mod japanese_era;
59mod matariki;
60mod month;
61pub mod naive;
62pub mod offset;
63pub mod round;
64mod traits;
65mod weekday;
66mod weekday_set;
67
68pub use datetime::DateTime;
69#[allow(deprecated)]
70#[doc(no_inline)]
71pub use datetime::{MAX_DATETIME, MIN_DATETIME};
72pub use duration::{Days, Duration, Months, OutOfRangeError, TimeDelta};
73pub use format::{ParseError, ParseResult, SecondsFormat};
74#[cfg(feature = "unstable-locales")]
75pub use format::Locale;
76// `JapaneseEra`: a `time_compute` extension -- not part of chrono, see
77// `japanese_era.rs`.
78pub use japanese_era::JapaneseEra;
79pub use month::{Month, OutOfRange, ParseMonthError};
80#[doc(inline)]
81pub use naive::{IsoWeek, NaiveDate, NaiveDateTime, NaiveTime, NaiveWeek};
82#[doc(inline)]
83pub use offset::{FixedOffset, Local, LocalResult, MappedLocalTime, Offset, TimeZone, Utc};
84pub use round::{DurationRound, RoundingError, SubsecRound};
85pub use traits::{Datelike, Timelike};
86pub use weekday::{ParseWeekdayError, Weekday};
87// `WeekdaySetIter` is intentionally not re-exported: real chrono keeps
88// `weekday_set` private and only exposes `WeekdaySet` itself, so the
89// iterator returned by `WeekdaySet::iter` is unnameable outside the crate
90// (callers just consume it via `for`/adapters). Matched here for parity.
91pub use weekday_set::WeekdaySet;
92
93/// Serialization/Deserialization with `serde`.
94///
95/// [`DateTime<Tz>`](DateTime) (de)serializes to/from an RFC 3339 string by
96/// default. This module provides alternatives for (de)serializing as a
97/// Unix timestamp instead (`ts_seconds`, `ts_milliseconds`,
98/// `ts_microseconds`, `ts_nanoseconds`, and their `_option` variants),
99/// intended for use with serde's `#[serde(with = "...")]` field attribute.
100///
101/// *Available on crate feature `serde` only.*
102#[cfg(feature = "serde")]
103pub mod serde {
104    pub use crate::datetime::serde::*;
105}
106
107/// Zero-copy (de)serialization with `rkyv`.
108///
109/// This module re-exports the `Archived*` versions of this crate's types.
110///
111/// *Available on crate features `rkyv`, `rkyv-16`, `rkyv-32`, or
112/// `rkyv-64` only.*
113#[cfg(any(feature = "rkyv", feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"))]
114pub mod rkyv {
115    pub use crate::datetime::ArchivedDateTime;
116    pub use crate::duration::ArchivedTimeDelta;
117    pub use crate::month::ArchivedMonth;
118    pub use crate::naive::date::{ArchivedIsoWeek, ArchivedNaiveDate};
119    pub use crate::naive::datetime::ArchivedNaiveDateTime;
120    pub use crate::naive::time::ArchivedNaiveTime;
121    pub use crate::offset::{ArchivedFixedOffset, ArchivedLocal, ArchivedUtc};
122    pub use crate::weekday::ArchivedWeekday;
123
124    /// Alias of [`ArchivedTimeDelta`].
125    pub type ArchivedDuration = ArchivedTimeDelta;
126}