1
0
mirror of https://github.com/bspeice/dtparse synced 2024-11-12 17:08:09 -05:00

Fix deprecations

This commit is contained in:
Bradlee Speice 2023-03-25 02:29:55 +00:00
parent 3a9e2674a6
commit b925b968ca
5 changed files with 750 additions and 2494 deletions

View File

@ -317,7 +317,7 @@ TEST_PARSE_DEFAULT = '''
#[test]
fn test_parse_default{i}() {{
let info = ParserInfo::default();
let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0);
let default_rsdate = &NaiveDate::from_ymd_opt(2003, 9, 25).unwrap().and_hms_opt(0, 0, 0).unwrap();
let pdt = PyDateTime {{
year: {d.year}, month: {d.month}, day: {d.day},
hour: {d.hour}, minute: {d.minute}, second: {d.second},
@ -407,7 +407,7 @@ TEST_UNSPECIFIED_FALLBACK = '''
#[test]
fn test_unspecified_fallback{i}() {{
let info = ParserInfo::default();
let default_rsdate = &NaiveDate::from_ymd(2010, 1, 31).and_hms(0, 0, 0);
let default_rsdate = &NaiveDate::from_ymd_opt(2010, 1, 31).unwrap().and_hms_opt(0, 0, 0).unwrap();
let pdt = PyDateTime {{
year: {d.year}, month: {d.month}, day: {d.day},
hour: {d.hour}, minute: {d.minute}, second: {d.second},
@ -435,7 +435,7 @@ TEST_PARSE_DEFAULT_IGNORE = '''
#[ignore]
fn test_parse_default_ignore{i}() {{
let info = ParserInfo::default();
let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0);
let default_rsdate = &NaiveDate::from_ymd_opt(2003, 9, 25).unwrap().and_hms_opt(0, 0, 0).unwrap();
let pdt = PyDateTime {{
year: {d.year}, month: {d.month}, day: {d.day},
hour: {d.hour}, minute: {d.minute}, second: {d.second},

View File

@ -43,6 +43,6 @@ fn main() {
)
.unwrap()
.0,
NaiveDate::from_ymd(2015, 9, 10).and_hms(10, 20, 0)
NaiveDate::from_ymd_opt(2015, 9, 10).unwrap().and_hms_opt(10, 20, 0).unwrap()
);
}

View File

@ -77,6 +77,9 @@ extern crate chrono;
extern crate num_traits;
extern crate rust_decimal;
#[cfg(test)]
extern crate base64;
use chrono::Datelike;
use chrono::Duration;
use chrono::FixedOffset;
@ -712,7 +715,7 @@ impl Parser {
) -> ParseResult<(NaiveDateTime, Option<FixedOffset>, Option<Vec<String>>)> {
let default_date = default.unwrap_or(&Local::now().naive_local()).date();
let default_ts = NaiveDateTime::new(default_date, NaiveTime::from_hms(0, 0, 0));
let default_ts = NaiveDateTime::new(default_date, NaiveTime::from_hms_opt(0, 0, 0).unwrap());
let (res, tokens) =
self.parse_with_tokens(timestr, dayfirst, yearfirst, fuzzy, fuzzy_with_tokens)?;
@ -1004,7 +1007,7 @@ impl Parser {
tzinfos: &HashMap<String, i32>,
) -> ParseResult<Option<FixedOffset>> {
if let Some(offset) = res.tzoffset {
Ok(Some(FixedOffset::east(offset)))
Ok(FixedOffset::east_opt(offset))
} else if res.tzoffset == None
&& (res.tzname == Some(" ".to_owned())
|| res.tzname == Some(".".to_owned())
@ -1013,9 +1016,9 @@ impl Parser {
{
Ok(None)
} else if res.tzname.is_some() && tzinfos.contains_key(res.tzname.as_ref().unwrap()) {
Ok(Some(FixedOffset::east(
Ok(FixedOffset::east_opt(
*tzinfos.get(res.tzname.as_ref().unwrap()).unwrap(),
)))
))
} else if let Some(tzname) = res.tzname.as_ref() {
println!("tzname {} identified but not understood.", tzname);
Ok(None)

View File

@ -1,3 +1,5 @@
use base64::Engine;
use base64::engine::general_purpose::STANDARD;
use chrono::NaiveDate;
use std::collections::HashMap;
use std::str;
@ -19,7 +21,7 @@ fn test_fuzz() {
Err(ParseError::UnrecognizedFormat)
);
let default = NaiveDate::from_ymd(2016, 6, 29).and_hms(0, 0, 0);
let default = NaiveDate::from_ymd_opt(2016, 6, 29).unwrap().and_hms_opt(0, 0, 0).unwrap();
let p = Parser::default();
let res = p.parse(
"\x0D\x31",
@ -74,7 +76,7 @@ fn github_32() {
#[test]
fn github_34() {
let parse_vec = base64::decode("KTMuLjYpGDYvLjZTNiouNjYuHzZpLjY/NkwuNh42Ry42PzYnKTMuNk02NjY2NjA2NjY2NjY2NjYTNjY2Ni82NjY2NlAuNlAuNlNI").unwrap();
let parse_vec = STANDARD.decode("KTMuLjYpGDYvLjZTNiouNjYuHzZpLjY/NkwuNh42Ry42PzYnKTMuNk02NjY2NjA2NjY2NjY2NjYTNjY2Ni82NjY2NlAuNlAuNlNI").unwrap();
let parse_str = str::from_utf8(&parse_vec).unwrap();
let parse_result = parse(parse_str);
assert!(parse_result.is_err());
@ -82,7 +84,7 @@ fn github_34() {
#[test]
fn github_35() {
let parse_vec = base64::decode("KTY6LjYqNio6KjYn").unwrap();
let parse_vec = STANDARD.decode("KTY6LjYqNio6KjYn").unwrap();
let parse_str = str::from_utf8(&parse_vec).unwrap();
let parse_result = parse(parse_str);
assert!(parse_result.is_err());
@ -90,7 +92,7 @@ fn github_35() {
#[test]
fn github_36() {
let parse_vec = base64::decode("KTYuLg==").unwrap();
let parse_vec = STANDARD.decode("KTYuLg==").unwrap();
let parse_str = str::from_utf8(&parse_vec).unwrap();
let parse_result = parse(parse_str);
assert!(parse_result.is_err());

File diff suppressed because it is too large Load Diff