mirror of
https://github.com/bspeice/dtparse
synced 2024-12-22 04:18:09 -05:00
commit
e9c994a755
18
src/lib.rs
18
src/lib.rs
@ -84,10 +84,7 @@ use chrono::Local;
|
|||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use chrono::NaiveTime;
|
use chrono::NaiveTime;
|
||||||
use chrono::Offset;
|
|
||||||
use chrono::TimeZone;
|
|
||||||
use chrono::Timelike;
|
use chrono::Timelike;
|
||||||
use chrono_tz::Tz;
|
|
||||||
use num_traits::cast::ToPrimitive;
|
use num_traits::cast::ToPrimitive;
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use rust_decimal::Error as DecimalError;
|
use rust_decimal::Error as DecimalError;
|
||||||
@ -959,7 +956,7 @@ impl Parser {
|
|||||||
|
|
||||||
fn build_tzaware(
|
fn build_tzaware(
|
||||||
&self,
|
&self,
|
||||||
dt: &NaiveDateTime,
|
_dt: &NaiveDateTime,
|
||||||
res: &ParsingResult,
|
res: &ParsingResult,
|
||||||
tzinfos: &HashMap<String, i32>,
|
tzinfos: &HashMap<String, i32>,
|
||||||
) -> ParseResult<Option<FixedOffset>> {
|
) -> ParseResult<Option<FixedOffset>> {
|
||||||
@ -976,16 +973,9 @@ impl Parser {
|
|||||||
Ok(Some(FixedOffset::east(
|
Ok(Some(FixedOffset::east(
|
||||||
*tzinfos.get(res.tzname.as_ref().unwrap()).unwrap(),
|
*tzinfos.get(res.tzname.as_ref().unwrap()).unwrap(),
|
||||||
)))
|
)))
|
||||||
} else if res.tzname.is_some() {
|
} else if let Some(tzname) = res.tzname.as_ref() {
|
||||||
let tzname = res.tzname.as_ref().unwrap();
|
println!("tzname {} identified but not understood.", tzname);
|
||||||
let tz: Result<Tz, String> = tzname.parse();
|
Ok(None)
|
||||||
if tz.is_ok() {
|
|
||||||
let offset = tz.unwrap().offset_from_local_datetime(dt).unwrap().fix();
|
|
||||||
Ok(Some(offset))
|
|
||||||
} else {
|
|
||||||
println!("tzname {} identified but not understood ({}). Ignoring for the time being, but behavior is subject to change.", tzname, tz.unwrap_err());
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Err(ParseError::TimezoneUnsupported)
|
Err(ParseError::TimezoneUnsupported)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
mod fuzzing;
|
mod fuzzing;
|
||||||
mod pycompat_parser;
|
mod pycompat_parser;
|
||||||
mod pycompat_tokenizer;
|
mod pycompat_tokenizer;
|
||||||
mod tz;
|
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
use parse;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn est() {
|
|
||||||
// Issue originally reported in https://github.com/bspeice/dtparse/issues/18
|
|
||||||
let dt = parse("Fri, 21 Aug 2015 18:37:44 EST");
|
|
||||||
|
|
||||||
assert!(dt.is_ok());
|
|
||||||
assert!(dt.unwrap().1.is_some());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn cest() {
|
|
||||||
// Issue originally reported in https://github.com/bspeice/dtparse/issues/18
|
|
||||||
let dt = parse("Fri, 21 Aug 2015 18:37:44 CEST");
|
|
||||||
|
|
||||||
assert!(dt.is_ok());
|
|
||||||
// TODO: Fix
|
|
||||||
// assert!(dt.unwrap().1.is_some());
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user