66 releases

0.4.38 Apr 15, 2024
0.4.37 Mar 27, 2024
0.4.34 Feb 11, 2024
0.4.31 Sep 15, 2023
0.1.3 Nov 28, 2014

#2 in Date and time

Download history 1981272/week @ 2024-07-29 1965178/week @ 2024-08-05 2013029/week @ 2024-08-12 2036424/week @ 2024-08-19 2050822/week @ 2024-08-26 1948786/week @ 2024-09-02 2016483/week @ 2024-09-09 1979503/week @ 2024-09-16 2103735/week @ 2024-09-23 2412405/week @ 2024-09-30 2766246/week @ 2024-10-07 2622974/week @ 2024-10-14 2249298/week @ 2024-10-21 2048794/week @ 2024-10-28 2101136/week @ 2024-11-04 1999767/week @ 2024-11-11

8,681,439 downloads per month
Used in 23,686 crates (12,448 directly)

MIT/Apache

1MB
19K SLoC

Chrono: Timezone-aware date and time handling

Chrono GitHub Actions Chrono on crates.io Chrono on docs.rs Chat codecov.io

Chrono aims to provide all functionality needed to do correct operations on dates and times in the proleptic Gregorian calendar:

  • The DateTime type is timezone-aware by default, with separate timezone-naive types.
  • Operations that may produce an invalid or ambiguous date and time return Option or MappedLocalTime.
  • Configurable parsing and formatting with an strftime inspired date and time formatting syntax.
  • The Local timezone works with the current timezone of the OS.
  • Types and operations are implemented to be reasonably efficient.

Timezone data is not shipped with chrono by default to limit binary sizes. Use the companion crate Chrono-TZ or tzfile for full timezone support.

Documentation

See docs.rs for the API reference.

Limitations

  • Only the proleptic Gregorian calendar (i.e. extended to support older dates) is supported.
  • Date types are limited to about +/- 262,000 years from the common epoch.
  • Time types are limited to nanosecond accuracy.
  • Leap seconds can be represented, but Chrono does not fully support them. See Leap Second Handling.

Crate features

Default features:

  • alloc: Enable features that depend on allocation (primarily string formatting).
  • std: Enables functionality that depends on the standard library. This is a superset of alloc and adds interoperation with standard library types and traits.
  • clock: Enables reading the local timezone (Local). This is a superset of now.
  • now: Enables reading the system time (now).
  • wasmbind: Interface with the JS Date API for the wasm32 target.

Optional features:

  • serde: Enable serialization/deserialization via serde.
  • rkyv: Deprecated, use the rkyv-* features.
  • rkyv-16: Enable serialization/deserialization via rkyv, using 16-bit integers for integral *size types.
  • rkyv-32: Enable serialization/deserialization via rkyv, using 32-bit integers for integral *size types.
  • rkyv-64: Enable serialization/deserialization via rkyv, using 64-bit integers for integral *size types.
  • rkyv-validation: Enable rkyv validation support using bytecheck.
  • arbitrary: Construct arbitrary instances of a type with the Arbitrary crate.
  • unstable-locales: Enable localization. This adds various methods with a _localized suffix. The implementation and API may change or even be removed in a patch release. Feedback welcome.
  • oldtime: This feature no longer has any effect; it used to offer compatibility with the time 0.1 crate.

Note: The rkyv{,-16,-32,-64} features are mutually exclusive.

Rust version requirements

The Minimum Supported Rust Version (MSRV) is currently Rust 1.61.0.

The MSRV is explicitly tested in CI. It may be bumped in minor releases, but this is not done lightly.

License

This project is licensed under either of

at your option.

Dependencies

~0.1–6MB
~21K SLoC