Skip to content

Commit

Permalink
Merge pull request #1116 from pitdicker/merge_0.4.x
Browse files Browse the repository at this point in the history
Merge 0.4.x, excluding #1113
  • Loading branch information
djc committed May 31, 2023
2 parents 2c60ec8 + 8164f9f commit 088b693
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 103 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ jobs:
- run: cargo fmt --check -- --color=always
- run: cargo fmt --check --manifest-path fuzz/Cargo.toml
- run: cargo clippy --color=always -- -D warnings
- run: cargo clippy --color=always --target x86_64-pc-windows-msvc -- -D warnings
- run: cargo clippy --manifest-path fuzz/Cargo.toml --color=always -- -D warnings
- run: |
cargo clippy --color=always --target x86_64-pc-windows-msvc \
-- -D warnings
- run: |
cargo clippy --manifest-path fuzz/Cargo.toml --color=always \
-- -D warnings
env:
RUSTFLAGS: "-Dwarnings"
cargo-deny:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1

check-doc:
runs-on: ubuntu-latest
Expand Down
36 changes: 29 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,18 @@ jobs:
with:
toolchain: 1.56.1
- uses: Swatinem/rust-cache@v2
# run --lib and --doc to avoid the long running integration tests which are run elsewhere
- run: cargo test --lib --features unstable-locales,wasmbind,clock,serde,windows-sys --color=always -- --color=always
- run: cargo test --doc --features unstable-locales,wasmbind,clock,serde,windows-sys --color=always -- --color=always
# run --lib and --doc to avoid the long running integration tests
# which are run elsewhere
- run: |
cargo test --lib \
--features \
unstable-locales,wasmbind,clock,serde,windows-sys \
--color=always -- --color=always
- run: |
cargo test --doc \
--features \
unstable-locales,wasmbind,clock,serde,windows-sys \
--color=always -- --color=always
rust_versions:
strategy:
Expand All @@ -63,7 +72,8 @@ jobs:
- uses: Swatinem/rust-cache@v2
- run: cargo check --benches
- run: cargo check --manifest-path fuzz/Cargo.toml --all-targets
# run --lib and --doc to avoid the long running integration tests which are run elsewhere
# run --lib and --doc to avoid the long running integration tests
# which are run elsewhere
- run: cargo test --lib --all-features --color=always -- --color=always
- run: cargo test --doc --all-features --color=always -- --color=always

Expand All @@ -77,7 +87,13 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2
- run: cargo hack check --feature-powerset --optional-deps serde,rkyv --skip default --skip __internal_bench --skip __doctest --skip iana-time-zone --skip pure-rust-locales
- run: |
cargo hack check --feature-powerset --optional-deps serde,rkyv \
--skip default --skip __internal_bench --skip __doctest \
--skip iana-time-zone --skip pure-rust-locales
# run using `bash` on all platforms for consistent
# line-continuation marks
shell: bash
- run: cargo test --lib --no-default-features
- run: cargo test --doc --no-default-features

Expand Down Expand Up @@ -119,9 +135,12 @@ jobs:
with:
node-version: "12"
- run: |
set -euxo pipefail
export RUST_BACKTRACE=1
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf \
| bash --noprofile --norc
wasm-pack --version
shell: bash
- run: cargo build --target ${{ matrix.target }} --color=always

features_check_wasm:
Expand All @@ -136,7 +155,10 @@ jobs:
targets: wasm32-unknown-unknown
- uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2
- run: cargo hack check --feature-powerset --optional-deps serde,rkyv --skip default --skip __internal_bench --skip __doctest --skip iana-time-zone --skip pure-rust-locales
- run: |
cargo hack check --feature-powerset --optional-deps serde,rkyv \
--skip default --skip __internal_bench --skip __doctest \
--skip iana-time-zone --skip pure-rust-locales
cross-targets:
strategy:
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ cff-version: 1.2.0
message: Please cite this crate using these information.

# Version information.
date-released: 2023-05-29
version: 0.4.25
date-released: 2023-05-31
version: 0.4.26

# Project information.
abstract: Date and time library for Rust
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ categories = ["date-and-time"]
readme = "README.md"
license = "MIT OR Apache-2.0"
exclude = ["/ci/*"]
edition = "2018"
edition = "2021"
rust-version = "1.56.0"

[lib]
Expand Down Expand Up @@ -51,7 +51,6 @@ android-tzdata = "0.1.1"
serde_json = { version = "1" }
serde_derive = { version = "1", default-features = false }
bincode = { version = "1.3.0" }
num-iter = { version = "0.1.35", default-features = false }
doc-comment = { version = "0.3" }

[target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dev-dependencies]
Expand Down
84 changes: 52 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[Chrono][docsrs]: Date and Time for Rust
[Chrono][docsrs]: Timezone-aware date and time handling
========================================

[![Chrono GitHub Actions][gh-image]][gh-checks]
Expand All @@ -15,45 +15,65 @@
[gitter-image]: https://badges.gitter.im/chrono-rs/chrono.svg
[gitter]: https://gitter.im/chrono-rs/chrono

It aims to be a feature-complete superset of
the [time](https://github.com/rust-lang-deprecated/time) library.
In particular,
Chrono aims to provide all functionality needed to do correct operations on dates and times in the
[proleptic Gregorian calendar](https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar):

* Chrono strictly adheres to ISO 8601.
* Chrono is timezone-aware by default, with separate timezone-naive types.
* Chrono is space-optimal and (while not being the primary goal) reasonably efficient.
* The [`DateTime`](https://docs.rs/chrono/latest/chrono/struct.DateTime.html) 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
[`LocalResult`](https://docs.rs/chrono/latest/chrono/offset/enum.LocalResult.html).
* Configurable parsing and formatting with an `strftime` inspired date and time formatting syntax.
* The [`Local`](https://docs.rs/chrono/latest/chrono/offset/struct.Local.html) timezone works with
the current timezone of the OS.
* Types and operations are implemented to be reasonably efficient.

There were several previous attempts to bring a good date and time library to Rust,
which Chrono builds upon and should acknowledge:
Timezone data is not shipped with chrono by default to limit binary sizes. Use the companion crate
[Chrono-TZ](https://crates.io/crates/chrono-tz) or [`tzfile`](https://crates.io/crates/tzfile) for
full timezone support.

* [Initial research on
the wiki](https://github.com/rust-lang/rust-wiki-backup/blob/master/Lib-datetime.md)
* Dietrich Epp's [datetime-rs](https://github.com/depp/datetime-rs)
* Luis de Bethencourt's [rust-datetime](https://github.com/luisbg/rust-datetime)
## Documentation

See [docs.rs](https://docs.rs/chrono/latest/chrono/) for the API reference.

## Limitations

Only proleptic Gregorian calendar (i.e. extended to support older dates) is supported.
Be very careful if you really have to deal with pre-20C dates, they can be in Julian or others.
* 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](https://docs.rs/chrono/latest/chrono/naive/struct.NaiveTime.html#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 system time (`now`) and local timezone (`Local`).
* `wasmbind`: Interface with the JS Date API for the `wasm32` target.

Optional features:

* `serde`: Enable serialization/deserialization via serde.
* `rkyv`: Enable serialization/deserialization via rkyv.
* `rustc-serialize`: Enable serialization/deserialization via rustc-serialize (deprecated).
* `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.

## Rust version requirements

The Minimum Supported Rust Version (MSRV) is currently **Rust 1.56.0**.

Date types are limited in about +/- 262,000 years from the common epoch.
Time types are limited in the nanosecond accuracy.
The MSRV is explicitly tested in CI. It may be bumped in minor releases, but this is not done
lightly.

[Leap seconds are supported in the representation but
Chrono doesn't try to make use of them](https://docs.rs/chrono/0.5/chrono/naive/struct.NaiveTime.html#leap-second-handling).
(The main reason is that leap seconds are not really predictable.)
Almost *every* operation over the possible leap seconds will ignore them.
Consider using `NaiveDateTime` with the implicit TAI (International Atomic Time) scale
if you want.
## License

Chrono inherently does not support an inaccurate or partial date and time representation.
Any operation that can be ambiguous will return `None` in such cases.
For example, "a month later" of 2014-01-30 is not well-defined
and consequently `Utc.ymd_opt(2014, 1, 30).unwrap().with_month(2)` returns `None`.
This project is licensed under either of

Non ISO week handling is not yet supported.
For now you can use the [chrono_ext](https://crates.io/crates/chrono_ext)
crate ([sources](https://github.com/bcourtine/chrono-ext/)).
* [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)
* [MIT License](https://opensource.org/licenses/MIT)

Advanced time zone handling is not yet supported.
For now you can try the [Chrono-tz](https://github.com/chronotope/chrono-tz/) crate instead.
at your option.
5 changes: 4 additions & 1 deletion src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ fn test_parse() {

// fixed: dot plus nanoseconds
check!("", [fix!(Nanosecond)]; ); // no field set, but not an error
check!(".", [fix!(Nanosecond)]; TOO_SHORT);
check!("4", [fix!(Nanosecond)]; TOO_LONG); // never consumes `4`
check!("4", [fix!(Nanosecond), num!(Second)]; second: 4);
check!(".0", [fix!(Nanosecond)]; nanosecond: 0);
Expand All @@ -888,13 +889,13 @@ fn test_parse() {
check!(".000000000547", [fix!(Nanosecond)]; nanosecond: 0);
check!(".0000000009999999999999999999999999", [fix!(Nanosecond)]; nanosecond: 0);
check!(".4🤠", [fix!(Nanosecond), lit!("🤠")]; nanosecond: 400_000_000);
check!(".", [fix!(Nanosecond)]; TOO_SHORT);
check!(".4x", [fix!(Nanosecond)]; TOO_LONG);
check!(". 4", [fix!(Nanosecond)]; INVALID);
check!(" .4", [fix!(Nanosecond)]; TOO_LONG); // no automatic trimming

// fixed: nanoseconds without the dot
check!("", [internal_fix!(Nanosecond3NoDot)]; TOO_SHORT);
check!(".", [internal_fix!(Nanosecond3NoDot)]; TOO_SHORT);
check!("0", [internal_fix!(Nanosecond3NoDot)]; TOO_SHORT);
check!("4", [internal_fix!(Nanosecond3NoDot)]; TOO_SHORT);
check!("42", [internal_fix!(Nanosecond3NoDot)]; TOO_SHORT);
Expand All @@ -910,6 +911,7 @@ fn test_parse() {
check!(".421", [internal_fix!(Nanosecond3NoDot)]; INVALID);

check!("", [internal_fix!(Nanosecond6NoDot)]; TOO_SHORT);
check!(".", [internal_fix!(Nanosecond6NoDot)]; TOO_SHORT);
check!("0", [internal_fix!(Nanosecond6NoDot)]; TOO_SHORT);
check!("1234", [internal_fix!(Nanosecond6NoDot)]; TOO_SHORT);
check!("12345", [internal_fix!(Nanosecond6NoDot)]; TOO_SHORT);
Expand All @@ -923,6 +925,7 @@ fn test_parse() {
check!(".42100", [internal_fix!(Nanosecond6NoDot)]; INVALID);

check!("", [internal_fix!(Nanosecond9NoDot)]; TOO_SHORT);
check!(".", [internal_fix!(Nanosecond9NoDot)]; TOO_SHORT);
check!("42195", [internal_fix!(Nanosecond9NoDot)]; TOO_SHORT);
check!("12345678", [internal_fix!(Nanosecond9NoDot)]; TOO_SHORT);
check!("421950803", [internal_fix!(Nanosecond9NoDot)]; nanosecond: 421_950_803);
Expand Down
2 changes: 0 additions & 2 deletions src/format/parsed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
//! A collection of parsed date and time items.
//! They can be constructed incrementally while being checked for consistency.

use core::convert::TryFrom;

use super::{ParseResult, IMPOSSIBLE, NOT_ENOUGH, OUT_OF_RANGE};
use crate::naive::{NaiveDate, NaiveDateTime, NaiveTime};
use crate::offset::{FixedOffset, LocalResult, Offset, TimeZone};
Expand Down
5 changes: 1 addition & 4 deletions src/month.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::{convert::TryFrom, fmt};
use core::fmt;

#[cfg(feature = "rkyv")]
use rkyv::{Archive, Deserialize, Serialize};
Expand All @@ -12,7 +12,6 @@ use crate::OutOfRange;
///
/// It is possible to convert from a date to a month independently
/// ```
/// # use std::convert::TryFrom;
/// use chrono::prelude::*;
/// let date = Utc.with_ymd_and_hms(2019, 10, 28, 9, 10, 11).unwrap();
/// // `2019-10-28T09:10:11Z`
Expand Down Expand Up @@ -311,8 +310,6 @@ mod month_serde {

#[cfg(test)]
mod tests {
use core::convert::TryFrom;

use super::Month;
use crate::{Datelike, OutOfRange, TimeZone, Utc};

Expand Down
10 changes: 2 additions & 8 deletions src/naive/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#[cfg(any(feature = "alloc", feature = "std", test))]
use core::borrow::Borrow;
use core::convert::TryFrom;
use core::ops::{Add, AddAssign, RangeInclusive, Sub, SubAssign};
use core::{fmt, str};

Expand Down Expand Up @@ -2250,10 +2249,7 @@ mod tests {
};
use crate::time_delta::TimeDelta;
use crate::{Datelike, Weekday};
use std::{
convert::{TryFrom, TryInto},
i32, u32,
};
use std::{i32, u32};

#[test]
fn diff_months() {
Expand Down Expand Up @@ -2342,9 +2338,7 @@ mod tests {

#[test]
fn test_readme_doomsday() {
use num_iter::range_inclusive;

for y in range_inclusive(NaiveDate::MIN.year(), NaiveDate::MAX.year()) {
for y in NaiveDate::MIN.year()..=NaiveDate::MAX.year() {
// even months
let d4 = NaiveDate::from_ymd_opt(y, 4, 4).unwrap();
let d6 = NaiveDate::from_ymd_opt(y, 6, 6).unwrap();
Expand Down
1 change: 0 additions & 1 deletion src/naive/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#[cfg(any(feature = "alloc", feature = "std", test))]
use core::borrow::Borrow;
use core::convert::TryFrom;
use core::fmt::Write;
use core::ops::{Add, AddAssign, Sub, SubAssign};
use core::{fmt, str};
Expand Down
Loading

0 comments on commit 088b693

Please sign in to comment.