Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallable constructors for less panics (#815) #996

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
8b3732f
Fallable constructors for less panics (#815)
Zomtir Mar 22, 2023
ee9871d
reconstruct_from_timestamp
Zomtir Mar 22, 2023
e29524f
ParsingNotEnough seems better for partial fields
Zomtir Mar 23, 2023
d1bd74e
Finished regular tests, doctests missing
Zomtir Mar 23, 2023
63c3494
Fixed all tests
Zomtir Mar 23, 2023
d27efa6
Readded lost locales
Zomtir Mar 23, 2023
5b1b711
arbitiary
Zomtir Mar 23, 2023
6eb7743
cargo fmt
Zomtir Mar 23, 2023
5a8eff8
Fixed some warnings
Zomtir Mar 27, 2023
6191156
restore some tests
Zomtir Apr 1, 2023
225b3e4
cosmetic fix
Zomtir Apr 1, 2023
228a689
moving forward
Zomtir Apr 2, 2023
db74841
time to be or not to be
Zomtir Apr 3, 2023
6655ba3
UTC/Local date stuff
Zomtir Apr 6, 2023
890e4c9
Test fixes
Zomtir Apr 6, 2023
34f05c1
Missed some utc/local date offset
Zomtir Apr 6, 2023
92a4308
Fix more tests
Zomtir Apr 6, 2023
0d0d5ba
Test fixing
Zomtir Apr 6, 2023
ec96378
More test fixes
Zomtir Apr 6, 2023
7a39b6e
Rounding Error
Zomtir Apr 6, 2023
7f8f39b
Move test_duration_round_error
Zomtir Apr 6, 2023
af68091
Test fixing...
Zomtir Apr 6, 2023
a3a8e45
Test fixing...2
Zomtir Apr 6, 2023
251f7b9
some ymd
Zomtir Apr 6, 2023
7652f24
final ymd
Zomtir Apr 6, 2023
de821dc
doctest
Zomtir Apr 6, 2023
a817932
doctests
Zomtir Apr 6, 2023
0432bd1
Doctests pass again
Zomtir Apr 6, 2023
5e51295
and_hms_opt for backwards compablity
Zomtir Apr 6, 2023
07df76e
cosmetic changes
Zomtir Apr 6, 2023
3695075
Merge branch 'main' into fallible-constructors
Zomtir Apr 6, 2023
33c0647
Turn result to option
Zomtir Apr 7, 2023
3c319ca
Fix clippy
Zomtir Apr 7, 2023
a52b57d
all features
Zomtir Apr 7, 2023
de66bf2
feature check
Zomtir Apr 7, 2023
d7f0374
serde error handling
Zomtir Apr 7, 2023
246e332
wasm
Zomtir Apr 7, 2023
eda476a
remove vscode config
Zomtir Apr 7, 2023
816df27
ymd gone
Zomtir Apr 7, 2023
4d4197e
serde error
Zomtir Apr 7, 2023
b78a655
From<serde_json::Error>
Zomtir Apr 7, 2023
ca5276c
test returns
Zomtir Apr 7, 2023
b2f508f
windows stuff
Zomtir Apr 7, 2023
573535d
cargo fmt
Zomtir Apr 7, 2023
4fb5696
more windows
Zomtir Apr 7, 2023
7386f59
cargo fmt
Zomtir Apr 7, 2023
d41abc1
more windows
Zomtir Apr 7, 2023
64bbb78
Removed SystemError
Zomtir Apr 9, 2023
79f21ca
cargo fmt...
Zomtir Apr 9, 2023
a46d79a
IO direct
Zomtir Apr 9, 2023
ce5c11a
io error test
Zomtir Apr 9, 2023
c7aa463
cargo fmt
Zomtir Apr 9, 2023
0e341c0
serde_json only as test
Zomtir Apr 9, 2023
9e317ff
serde_json non-dev
Zomtir Apr 9, 2023
74c975f
serde_json dependencies
Zomtir Apr 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ default = ["clock", "std", "wasmbind"]
alloc = []
libc = []
std = []
serde = ["dep:serde", "dep:serde_json"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be causing the MSRV failure (one of the two CI failures) due to:

Note: The dep: syntax is only available starting with Rust 1.60. Previous versions can only use the implicit feature name.

There are suggestions that we will probably go higher than the current 1.48 (see: #995), but it may not go as high as 1.60 (put another way, we probably can't justify moving to 1.60 just to get this dep:{crate} syntax)

clock = ["std", "windows-sys", "iana-time-zone"]
wasmbind = ["wasm-bindgen", "js-sys"]
unstable-locales = ["pure-rust-locales", "alloc"]
Expand All @@ -28,6 +29,7 @@ __doctest = []

[dependencies]
serde = { version = "1.0.99", default-features = false, optional = true }
serde_json = { version = "1", optional = true}
pure-rust-locales = { version = "0.5.2", optional = true }
criterion = { version = "0.4.0", optional = true }
rkyv = {version = "0.7", optional = true}
Expand All @@ -44,7 +46,6 @@ windows-sys = { version = "0.48.0", features = ["Win32_System_Time", "Win32_Foun
iana-time-zone = { version = "0.1.45", optional = true, features = ["fallback"] }

[dev-dependencies]
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 }
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ Consider using `NaiveDateTime` with the implicit TAI (International Atomic Time)
if you want.

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.
Any operation that can be ambiguous will return `Err(chrono::Error)` 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`.
and consequently `NaiveDate::from_ymd(2014, 1, 30)?.with_month(2)` returns `Err(chrono::Error)`.

Non ISO week handling is not yet supported.
For now you can use the [chrono_ext](https://crates.io/crates/chrono_ext)
Expand Down
28 changes: 9 additions & 19 deletions benches/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,18 @@ fn bench_datetime_from_str(c: &mut Criterion) {
}

fn bench_datetime_to_rfc2822(c: &mut Criterion) {
let pst = FixedOffset::east_opt(8 * 60 * 60).unwrap();
let dt = pst
.from_local_datetime(
&NaiveDate::from_ymd_opt(2018, 1, 11)
.unwrap()
.and_hms_nano_opt(10, 5, 13, 84_660_000)
.unwrap(),
)
.unwrap();
let pst = FixedOffset::east(8 * 60 * 60).unwrap();
let dt = pst.from_local_datetime(
&NaiveDate::from_ymd(2018, 1, 11)?.and_hms_nano(10, 5, 13, 84_660_000)?,
);
c.bench_function("bench_datetime_to_rfc2822", |b| b.iter(|| black_box(dt).to_rfc2822()));
}

fn bench_datetime_to_rfc3339(c: &mut Criterion) {
let pst = FixedOffset::east_opt(8 * 60 * 60).unwrap();
let dt = pst
.from_local_datetime(
&NaiveDate::from_ymd_opt(2018, 1, 11)
.unwrap()
.and_hms_nano_opt(10, 5, 13, 84_660_000)
.unwrap(),
)
.unwrap();
let pst = FixedOffset::east(8 * 60 * 60).unwrap();
let dt = pst.from_local_datetime(
&NaiveDate::from_ymd(2018, 1, 11)?.and_hms_nano(10, 5, 13, 84_660_000)?,
);
c.bench_function("bench_datetime_to_rfc3339", |b| b.iter(|| black_box(dt).to_rfc3339()));
}

Expand Down Expand Up @@ -112,7 +102,7 @@ fn num_days_from_ce_alt<Date: Datelike>(date: &Date) -> i32 {
fn bench_num_days_from_ce(c: &mut Criterion) {
let mut group = c.benchmark_group("num_days_from_ce");
for year in &[1, 500, 2000, 2019] {
let d = NaiveDate::from_ymd_opt(*year, 1, 1).unwrap();
let d = NaiveDate::from_ymd(*year, 1, 1).unwrap();
group.bench_with_input(BenchmarkId::new("new", year), &d, |b, y| {
b.iter(|| num_days_from_ce_alt(y))
});
Expand Down
5 changes: 3 additions & 2 deletions ci/core-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use chrono::{TimeZone, Utc};

pub fn create_time() {
let _ = Utc.with_ymd_and_hms(2019, 1, 1, 0, 0, 0).unwrap();
pub fn create_time() -> Result<(), chrono::Error> {
let _ = Utc.with_ymd_and_hms(2019, 1, 1, 0, 0, 0)?.single()?;
Ok(())
}