mirror of
https://github.com/bspeice/dtparse
synced 2024-12-22 04:18:09 -05:00
Fix deprecations
This commit is contained in:
parent
3a9e2674a6
commit
b925b968ca
@ -317,7 +317,7 @@ TEST_PARSE_DEFAULT = '''
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_parse_default{i}() {{
|
fn test_parse_default{i}() {{
|
||||||
let info = ParserInfo::default();
|
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 {{
|
let pdt = PyDateTime {{
|
||||||
year: {d.year}, month: {d.month}, day: {d.day},
|
year: {d.year}, month: {d.month}, day: {d.day},
|
||||||
hour: {d.hour}, minute: {d.minute}, second: {d.second},
|
hour: {d.hour}, minute: {d.minute}, second: {d.second},
|
||||||
@ -407,7 +407,7 @@ TEST_UNSPECIFIED_FALLBACK = '''
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_unspecified_fallback{i}() {{
|
fn test_unspecified_fallback{i}() {{
|
||||||
let info = ParserInfo::default();
|
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 {{
|
let pdt = PyDateTime {{
|
||||||
year: {d.year}, month: {d.month}, day: {d.day},
|
year: {d.year}, month: {d.month}, day: {d.day},
|
||||||
hour: {d.hour}, minute: {d.minute}, second: {d.second},
|
hour: {d.hour}, minute: {d.minute}, second: {d.second},
|
||||||
@ -435,7 +435,7 @@ TEST_PARSE_DEFAULT_IGNORE = '''
|
|||||||
#[ignore]
|
#[ignore]
|
||||||
fn test_parse_default_ignore{i}() {{
|
fn test_parse_default_ignore{i}() {{
|
||||||
let info = ParserInfo::default();
|
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 {{
|
let pdt = PyDateTime {{
|
||||||
year: {d.year}, month: {d.month}, day: {d.day},
|
year: {d.year}, month: {d.month}, day: {d.day},
|
||||||
hour: {d.hour}, minute: {d.minute}, second: {d.second},
|
hour: {d.hour}, minute: {d.minute}, second: {d.second},
|
||||||
|
@ -43,6 +43,6 @@ fn main() {
|
|||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0,
|
.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()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
11
src/lib.rs
11
src/lib.rs
@ -77,6 +77,9 @@ extern crate chrono;
|
|||||||
extern crate num_traits;
|
extern crate num_traits;
|
||||||
extern crate rust_decimal;
|
extern crate rust_decimal;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
extern crate base64;
|
||||||
|
|
||||||
use chrono::Datelike;
|
use chrono::Datelike;
|
||||||
use chrono::Duration;
|
use chrono::Duration;
|
||||||
use chrono::FixedOffset;
|
use chrono::FixedOffset;
|
||||||
@ -712,7 +715,7 @@ impl Parser {
|
|||||||
) -> ParseResult<(NaiveDateTime, Option<FixedOffset>, Option<Vec<String>>)> {
|
) -> ParseResult<(NaiveDateTime, Option<FixedOffset>, Option<Vec<String>>)> {
|
||||||
let default_date = default.unwrap_or(&Local::now().naive_local()).date();
|
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) =
|
let (res, tokens) =
|
||||||
self.parse_with_tokens(timestr, dayfirst, yearfirst, fuzzy, fuzzy_with_tokens)?;
|
self.parse_with_tokens(timestr, dayfirst, yearfirst, fuzzy, fuzzy_with_tokens)?;
|
||||||
@ -1004,7 +1007,7 @@ impl Parser {
|
|||||||
tzinfos: &HashMap<String, i32>,
|
tzinfos: &HashMap<String, i32>,
|
||||||
) -> ParseResult<Option<FixedOffset>> {
|
) -> ParseResult<Option<FixedOffset>> {
|
||||||
if let Some(offset) = res.tzoffset {
|
if let Some(offset) = res.tzoffset {
|
||||||
Ok(Some(FixedOffset::east(offset)))
|
Ok(FixedOffset::east_opt(offset))
|
||||||
} else if res.tzoffset == None
|
} else if res.tzoffset == None
|
||||||
&& (res.tzname == Some(" ".to_owned())
|
&& (res.tzname == Some(" ".to_owned())
|
||||||
|| res.tzname == Some(".".to_owned())
|
|| res.tzname == Some(".".to_owned())
|
||||||
@ -1013,9 +1016,9 @@ impl Parser {
|
|||||||
{
|
{
|
||||||
Ok(None)
|
Ok(None)
|
||||||
} else if res.tzname.is_some() && tzinfos.contains_key(res.tzname.as_ref().unwrap()) {
|
} 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(),
|
*tzinfos.get(res.tzname.as_ref().unwrap()).unwrap(),
|
||||||
)))
|
))
|
||||||
} else if let Some(tzname) = res.tzname.as_ref() {
|
} else if let Some(tzname) = res.tzname.as_ref() {
|
||||||
println!("tzname {} identified but not understood.", tzname);
|
println!("tzname {} identified but not understood.", tzname);
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use base64::Engine;
|
||||||
|
use base64::engine::general_purpose::STANDARD;
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::str;
|
use std::str;
|
||||||
@ -19,7 +21,7 @@ fn test_fuzz() {
|
|||||||
Err(ParseError::UnrecognizedFormat)
|
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 p = Parser::default();
|
||||||
let res = p.parse(
|
let res = p.parse(
|
||||||
"\x0D\x31",
|
"\x0D\x31",
|
||||||
@ -74,7 +76,7 @@ fn github_32() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn github_34() {
|
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_str = str::from_utf8(&parse_vec).unwrap();
|
||||||
let parse_result = parse(parse_str);
|
let parse_result = parse(parse_str);
|
||||||
assert!(parse_result.is_err());
|
assert!(parse_result.is_err());
|
||||||
@ -82,7 +84,7 @@ fn github_34() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn github_35() {
|
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_str = str::from_utf8(&parse_vec).unwrap();
|
||||||
let parse_result = parse(parse_str);
|
let parse_result = parse(parse_str);
|
||||||
assert!(parse_result.is_err());
|
assert!(parse_result.is_err());
|
||||||
@ -90,7 +92,7 @@ fn github_35() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn github_36() {
|
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_str = str::from_utf8(&parse_vec).unwrap();
|
||||||
let parse_result = parse(parse_str);
|
let parse_result = parse(parse_str);
|
||||||
assert!(parse_result.is_err());
|
assert!(parse_result.is_err());
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user