From 9acfc2f612274ab73ec1897e07a4a0c2bf81249e Mon Sep 17 00:00:00 2001 From: taichong Date: Wed, 17 Jul 2024 20:50:38 +0800 Subject: [PATCH] modify default NaiveDate value 1970-01-01 --- src/lib.rs | 6 ++++-- src/tests/fuzzing.rs | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fee9b0f..a0bcdb6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -710,8 +710,10 @@ impl Parser { ignoretz: bool, tzinfos: &HashMap, ) -> ParseResult<(NaiveDateTime, Option, Option>)> { - let default_date = default.unwrap_or(&Local::now().naive_local()).date(); - + // If default is none, 1970-01-01 00:00:00 as default value is better. + let default_date = default + .unwrap_or(&NaiveDate::default().and_hms_opt(0, 0, 0).unwrap()) + .date(); let default_ts = NaiveDateTime::new(default_date, NaiveTime::from_hms_opt(0, 0, 0).unwrap()); diff --git a/src/tests/fuzzing.rs b/src/tests/fuzzing.rs index 8cc3c05..e2bb399 100644 --- a/src/tests/fuzzing.rs +++ b/src/tests/fuzzing.rs @@ -160,4 +160,15 @@ fn github_46() { panic!(); } } + + parse_result = parse("2000"); + match parse_result { + Ok((dt, offset)) => { + assert_eq!(format!("{:?}", dt), "2000-01-01T00:00:00".to_string()); + assert!(offset.is_none()); + } + Err(_) => { + panic!(); + } + } }