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 8 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 `Utc.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
2 changes: 1 addition & 1 deletion ci/core-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
use chrono::{TimeZone, Utc};

pub fn create_time() {
let _ = Utc.with_ymd_and_hms(2019, 1, 1, 0, 0, 0).unwrap();
let _ = Utc.ymd(2019, 1, 1).and_hms(0, 0, 0);
}
Loading