Skip to content

Commit 088b693

Browse files
authored
Merge pull request chronotope#1116 from pitdicker/merge_0.4.x
Merge 0.4.x, excluding chronotope#1113
2 parents 2c60ec8 + 8164f9f commit 088b693

15 files changed

+189
-103
lines changed

.github/workflows/lint.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@ jobs:
1818
- run: cargo fmt --check -- --color=always
1919
- run: cargo fmt --check --manifest-path fuzz/Cargo.toml
2020
- run: cargo clippy --color=always -- -D warnings
21-
- run: cargo clippy --color=always --target x86_64-pc-windows-msvc -- -D warnings
22-
- run: cargo clippy --manifest-path fuzz/Cargo.toml --color=always -- -D warnings
21+
- run: |
22+
cargo clippy --color=always --target x86_64-pc-windows-msvc \
23+
-- -D warnings
24+
- run: |
25+
cargo clippy --manifest-path fuzz/Cargo.toml --color=always \
26+
-- -D warnings
2327
env:
2428
RUSTFLAGS: "-Dwarnings"
2529
2630
cargo-deny:
2731
runs-on: ubuntu-latest
2832
steps:
29-
- uses: actions/checkout@v3
30-
- uses: EmbarkStudios/cargo-deny-action@v1
33+
- uses: actions/checkout@v3
34+
- uses: EmbarkStudios/cargo-deny-action@v1
3135

3236
check-doc:
3337
runs-on: ubuntu-latest

.github/workflows/test.yml

+29-7
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,18 @@ jobs:
4545
with:
4646
toolchain: 1.56.1
4747
- uses: Swatinem/rust-cache@v2
48-
# run --lib and --doc to avoid the long running integration tests which are run elsewhere
49-
- run: cargo test --lib --features unstable-locales,wasmbind,clock,serde,windows-sys --color=always -- --color=always
50-
- run: cargo test --doc --features unstable-locales,wasmbind,clock,serde,windows-sys --color=always -- --color=always
48+
# run --lib and --doc to avoid the long running integration tests
49+
# which are run elsewhere
50+
- run: |
51+
cargo test --lib \
52+
--features \
53+
unstable-locales,wasmbind,clock,serde,windows-sys \
54+
--color=always -- --color=always
55+
- run: |
56+
cargo test --doc \
57+
--features \
58+
unstable-locales,wasmbind,clock,serde,windows-sys \
59+
--color=always -- --color=always
5160
5261
rust_versions:
5362
strategy:
@@ -63,7 +72,8 @@ jobs:
6372
- uses: Swatinem/rust-cache@v2
6473
- run: cargo check --benches
6574
- run: cargo check --manifest-path fuzz/Cargo.toml --all-targets
66-
# run --lib and --doc to avoid the long running integration tests which are run elsewhere
75+
# run --lib and --doc to avoid the long running integration tests
76+
# which are run elsewhere
6777
- run: cargo test --lib --all-features --color=always -- --color=always
6878
- run: cargo test --doc --all-features --color=always -- --color=always
6979

@@ -77,7 +87,13 @@ jobs:
7787
- uses: dtolnay/rust-toolchain@stable
7888
- uses: taiki-e/install-action@cargo-hack
7989
- uses: Swatinem/rust-cache@v2
80-
- 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
90+
- run: |
91+
cargo hack check --feature-powerset --optional-deps serde,rkyv \
92+
--skip default --skip __internal_bench --skip __doctest \
93+
--skip iana-time-zone --skip pure-rust-locales
94+
# run using `bash` on all platforms for consistent
95+
# line-continuation marks
96+
shell: bash
8197
- run: cargo test --lib --no-default-features
8298
- run: cargo test --doc --no-default-features
8399

@@ -119,9 +135,12 @@ jobs:
119135
with:
120136
node-version: "12"
121137
- run: |
138+
set -euxo pipefail
122139
export RUST_BACKTRACE=1
123-
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
140+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf \
141+
| bash --noprofile --norc
124142
wasm-pack --version
143+
shell: bash
125144
- run: cargo build --target ${{ matrix.target }} --color=always
126145

127146
features_check_wasm:
@@ -136,7 +155,10 @@ jobs:
136155
targets: wasm32-unknown-unknown
137156
- uses: taiki-e/install-action@cargo-hack
138157
- uses: Swatinem/rust-cache@v2
139-
- 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
158+
- run: |
159+
cargo hack check --feature-powerset --optional-deps serde,rkyv \
160+
--skip default --skip __internal_bench --skip __doctest \
161+
--skip iana-time-zone --skip pure-rust-locales
140162
141163
cross-targets:
142164
strategy:

CITATION.cff

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ cff-version: 1.2.0
33
message: Please cite this crate using these information.
44

55
# Version information.
6-
date-released: 2023-05-29
7-
version: 0.4.25
6+
date-released: 2023-05-31
7+
version: 0.4.26
88

99
# Project information.
1010
abstract: Date and time library for Rust

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ categories = ["date-and-time"]
1010
readme = "README.md"
1111
license = "MIT OR Apache-2.0"
1212
exclude = ["/ci/*"]
13-
edition = "2018"
13+
edition = "2021"
1414
rust-version = "1.56.0"
1515

1616
[lib]
@@ -51,7 +51,6 @@ android-tzdata = "0.1.1"
5151
serde_json = { version = "1" }
5252
serde_derive = { version = "1", default-features = false }
5353
bincode = { version = "1.3.0" }
54-
num-iter = { version = "0.1.35", default-features = false }
5554
doc-comment = { version = "0.3" }
5655

5756
[target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dev-dependencies]

README.md

+52-32
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[Chrono][docsrs]: Date and Time for Rust
1+
[Chrono][docsrs]: Timezone-aware date and time handling
22
========================================
33

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

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

22-
* Chrono strictly adheres to ISO 8601.
23-
* Chrono is timezone-aware by default, with separate timezone-naive types.
24-
* Chrono is space-optimal and (while not being the primary goal) reasonably efficient.
21+
* The [`DateTime`](https://docs.rs/chrono/latest/chrono/struct.DateTime.html) type is timezone-aware
22+
by default, with separate timezone-naive types.
23+
* Operations that may produce an invalid or ambiguous date and time return `Option` or
24+
[`LocalResult`](https://docs.rs/chrono/latest/chrono/offset/enum.LocalResult.html).
25+
* Configurable parsing and formatting with an `strftime` inspired date and time formatting syntax.
26+
* The [`Local`](https://docs.rs/chrono/latest/chrono/offset/struct.Local.html) timezone works with
27+
the current timezone of the OS.
28+
* Types and operations are implemented to be reasonably efficient.
2529

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

29-
* [Initial research on
30-
the wiki](https://github.com/rust-lang/rust-wiki-backup/blob/master/Lib-datetime.md)
31-
* Dietrich Epp's [datetime-rs](https://github.com/depp/datetime-rs)
32-
* Luis de Bethencourt's [rust-datetime](https://github.com/luisbg/rust-datetime)
34+
## Documentation
35+
36+
See [docs.rs](https://docs.rs/chrono/latest/chrono/) for the API reference.
3337

3438
## Limitations
3539

36-
Only proleptic Gregorian calendar (i.e. extended to support older dates) is supported.
37-
Be very careful if you really have to deal with pre-20C dates, they can be in Julian or others.
40+
* Only the proleptic Gregorian calendar (i.e. extended to support older dates) is supported.
41+
* Date types are limited to about +/- 262,000 years from the common epoch.
42+
* Time types are limited to nanosecond accuracy.
43+
* Leap seconds can be represented, but Chrono does not fully support them.
44+
See [Leap Second Handling](https://docs.rs/chrono/latest/chrono/naive/struct.NaiveTime.html#leap-second-handling).
45+
46+
## Crate features
47+
48+
Default features:
49+
50+
* `alloc`: Enable features that depend on allocation (primarily string formatting)
51+
* `std`: Enables functionality that depends on the standard library. This is a superset of `alloc`
52+
and adds interoperation with standard library types and traits.
53+
* `clock`: Enables reading the system time (`now`) and local timezone (`Local`).
54+
* `wasmbind`: Interface with the JS Date API for the `wasm32` target.
55+
56+
Optional features:
57+
58+
* `serde`: Enable serialization/deserialization via serde.
59+
* `rkyv`: Enable serialization/deserialization via rkyv.
60+
* `rustc-serialize`: Enable serialization/deserialization via rustc-serialize (deprecated).
61+
* `arbitrary`: construct arbitrary instances of a type with the Arbitrary crate.
62+
* `unstable-locales`: Enable localization. This adds various methods with a `_localized` suffix.
63+
The implementation and API may change or even be removed in a patch release. Feedback welcome.
64+
65+
## Rust version requirements
66+
67+
The Minimum Supported Rust Version (MSRV) is currently **Rust 1.56.0**.
3868

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

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

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

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

58-
Advanced time zone handling is not yet supported.
59-
For now you can try the [Chrono-tz](https://github.com/chronotope/chrono-tz/) crate instead.
79+
at your option.

src/format/parse.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ fn test_parse() {
866866

867867
// fixed: dot plus nanoseconds
868868
check!("", [fix!(Nanosecond)]; ); // no field set, but not an error
869+
check!(".", [fix!(Nanosecond)]; TOO_SHORT);
869870
check!("4", [fix!(Nanosecond)]; TOO_LONG); // never consumes `4`
870871
check!("4", [fix!(Nanosecond), num!(Second)]; second: 4);
871872
check!(".0", [fix!(Nanosecond)]; nanosecond: 0);
@@ -888,13 +889,13 @@ fn test_parse() {
888889
check!(".000000000547", [fix!(Nanosecond)]; nanosecond: 0);
889890
check!(".0000000009999999999999999999999999", [fix!(Nanosecond)]; nanosecond: 0);
890891
check!(".4🤠", [fix!(Nanosecond), lit!("🤠")]; nanosecond: 400_000_000);
891-
check!(".", [fix!(Nanosecond)]; TOO_SHORT);
892892
check!(".4x", [fix!(Nanosecond)]; TOO_LONG);
893893
check!(". 4", [fix!(Nanosecond)]; INVALID);
894894
check!(" .4", [fix!(Nanosecond)]; TOO_LONG); // no automatic trimming
895895

896896
// fixed: nanoseconds without the dot
897897
check!("", [internal_fix!(Nanosecond3NoDot)]; TOO_SHORT);
898+
check!(".", [internal_fix!(Nanosecond3NoDot)]; TOO_SHORT);
898899
check!("0", [internal_fix!(Nanosecond3NoDot)]; TOO_SHORT);
899900
check!("4", [internal_fix!(Nanosecond3NoDot)]; TOO_SHORT);
900901
check!("42", [internal_fix!(Nanosecond3NoDot)]; TOO_SHORT);
@@ -910,6 +911,7 @@ fn test_parse() {
910911
check!(".421", [internal_fix!(Nanosecond3NoDot)]; INVALID);
911912

912913
check!("", [internal_fix!(Nanosecond6NoDot)]; TOO_SHORT);
914+
check!(".", [internal_fix!(Nanosecond6NoDot)]; TOO_SHORT);
913915
check!("0", [internal_fix!(Nanosecond6NoDot)]; TOO_SHORT);
914916
check!("1234", [internal_fix!(Nanosecond6NoDot)]; TOO_SHORT);
915917
check!("12345", [internal_fix!(Nanosecond6NoDot)]; TOO_SHORT);
@@ -923,6 +925,7 @@ fn test_parse() {
923925
check!(".42100", [internal_fix!(Nanosecond6NoDot)]; INVALID);
924926

925927
check!("", [internal_fix!(Nanosecond9NoDot)]; TOO_SHORT);
928+
check!(".", [internal_fix!(Nanosecond9NoDot)]; TOO_SHORT);
926929
check!("42195", [internal_fix!(Nanosecond9NoDot)]; TOO_SHORT);
927930
check!("12345678", [internal_fix!(Nanosecond9NoDot)]; TOO_SHORT);
928931
check!("421950803", [internal_fix!(Nanosecond9NoDot)]; nanosecond: 421_950_803);

src/format/parsed.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
//! A collection of parsed date and time items.
55
//! They can be constructed incrementally while being checked for consistency.
66
7-
use core::convert::TryFrom;
8-
97
use super::{ParseResult, IMPOSSIBLE, NOT_ENOUGH, OUT_OF_RANGE};
108
use crate::naive::{NaiveDate, NaiveDateTime, NaiveTime};
119
use crate::offset::{FixedOffset, LocalResult, Offset, TimeZone};

src/month.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use core::{convert::TryFrom, fmt};
1+
use core::fmt;
22

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

312311
#[cfg(test)]
313312
mod tests {
314-
use core::convert::TryFrom;
315-
316313
use super::Month;
317314
use crate::{Datelike, OutOfRange, TimeZone, Utc};
318315

src/naive/date.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
66
#[cfg(any(feature = "alloc", feature = "std", test))]
77
use core::borrow::Borrow;
8-
use core::convert::TryFrom;
98
use core::ops::{Add, AddAssign, RangeInclusive, Sub, SubAssign};
109
use core::{fmt, str};
1110

@@ -2250,10 +2249,7 @@ mod tests {
22502249
};
22512250
use crate::time_delta::TimeDelta;
22522251
use crate::{Datelike, Weekday};
2253-
use std::{
2254-
convert::{TryFrom, TryInto},
2255-
i32, u32,
2256-
};
2252+
use std::{i32, u32};
22572253

22582254
#[test]
22592255
fn diff_months() {
@@ -2342,9 +2338,7 @@ mod tests {
23422338

23432339
#[test]
23442340
fn test_readme_doomsday() {
2345-
use num_iter::range_inclusive;
2346-
2347-
for y in range_inclusive(NaiveDate::MIN.year(), NaiveDate::MAX.year()) {
2341+
for y in NaiveDate::MIN.year()..=NaiveDate::MAX.year() {
23482342
// even months
23492343
let d4 = NaiveDate::from_ymd_opt(y, 4, 4).unwrap();
23502344
let d6 = NaiveDate::from_ymd_opt(y, 6, 6).unwrap();

src/naive/datetime/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
66
#[cfg(any(feature = "alloc", feature = "std", test))]
77
use core::borrow::Borrow;
8-
use core::convert::TryFrom;
98
use core::fmt::Write;
109
use core::ops::{Add, AddAssign, Sub, SubAssign};
1110
use core::{fmt, str};

0 commit comments

Comments
 (0)