mirror of
https://github.com/bspeice/dtparse
synced 2024-12-22 04:18:09 -05:00
THE TEST CASES ARE PASSING!!!
This commit is contained in:
parent
55c164d4f9
commit
e4d9257305
15
src/lib.rs
15
src/lib.rs
@ -652,8 +652,7 @@ impl YMD {
|
|||||||
day = Some(self._ymd[1]);
|
day = Some(self._ymd[1]);
|
||||||
}
|
}
|
||||||
} else if len_ymd == 3 {
|
} else if len_ymd == 3 {
|
||||||
// UNWRAP: 3 elements guarantees all indices are Some
|
if self.mstridx == Some(0) {
|
||||||
if self.mstridx.unwrap() == 0 {
|
|
||||||
if self._ymd[1] > 31 {
|
if self._ymd[1] > 31 {
|
||||||
month = Some(self._ymd[0]);
|
month = Some(self._ymd[0]);
|
||||||
year = Some(self._ymd[1]);
|
year = Some(self._ymd[1]);
|
||||||
@ -663,7 +662,7 @@ impl YMD {
|
|||||||
day = Some(self._ymd[1]);
|
day = Some(self._ymd[1]);
|
||||||
year = Some(self._ymd[2]);
|
year = Some(self._ymd[2]);
|
||||||
}
|
}
|
||||||
} else if self.mstridx.unwrap() == 1 {
|
} else if self.mstridx == Some(1) {
|
||||||
if self._ymd[0] > 31 || (yearfirst && self._ymd[2] <= 31) {
|
if self._ymd[0] > 31 || (yearfirst && self._ymd[2] <= 31) {
|
||||||
year = Some(self._ymd[0]);
|
year = Some(self._ymd[0]);
|
||||||
month = Some(self._ymd[1]);
|
month = Some(self._ymd[1]);
|
||||||
@ -673,7 +672,7 @@ impl YMD {
|
|||||||
month = Some(self._ymd[1]);
|
month = Some(self._ymd[1]);
|
||||||
year = Some(self._ymd[2]);
|
year = Some(self._ymd[2]);
|
||||||
}
|
}
|
||||||
} else if self.mstridx.unwrap() == 2 {
|
} else if self.mstridx == Some(2) {
|
||||||
// It was in the original docs, so: WTF!?
|
// It was in the original docs, so: WTF!?
|
||||||
if self._ymd[1] > 31 {
|
if self._ymd[1] > 31 {
|
||||||
day = Some(self._ymd[0]);
|
day = Some(self._ymd[0]);
|
||||||
@ -766,7 +765,7 @@ impl Parser {
|
|||||||
|
|
||||||
if !ignoretz {
|
if !ignoretz {
|
||||||
let offset = self.build_tzaware(&naive, &res, default_ts);
|
let offset = self.build_tzaware(&naive, &res, default_ts);
|
||||||
Ok((naive, Some(offset.unwrap()), tokens))
|
Ok((naive, offset.unwrap(), tokens))
|
||||||
} else {
|
} else {
|
||||||
Ok((naive, None, tokens))
|
Ok((naive, None, tokens))
|
||||||
}
|
}
|
||||||
@ -995,10 +994,10 @@ impl Parser {
|
|||||||
dt: &NaiveDateTime,
|
dt: &NaiveDateTime,
|
||||||
res: &ParsingResult,
|
res: &ParsingResult,
|
||||||
default: NaiveDateTime,
|
default: NaiveDateTime,
|
||||||
) -> ParseResult<FixedOffset> {
|
) -> ParseResult<Option<FixedOffset>> {
|
||||||
|
|
||||||
if res.tzname.is_none() && res.tzoffset.is_none() {
|
if res.tzname.is_none() && res.tzoffset.is_none() {
|
||||||
Ok(FixedOffset::east(0))
|
Ok(None)
|
||||||
} else {
|
} else {
|
||||||
Err(ParseError::TimezoneUnsupported)
|
Err(ParseError::TimezoneUnsupported)
|
||||||
}
|
}
|
||||||
@ -1124,6 +1123,8 @@ impl Parser {
|
|||||||
let hour = value.to_i64().unwrap() as i32;
|
let hour = value.to_i64().unwrap() as i32;
|
||||||
let ampm = info.get_ampm(&tokens[idx + 2]).unwrap();
|
let ampm = info.get_ampm(&tokens[idx + 2]).unwrap();
|
||||||
res.hour = Some(self.adjust_ampm(hour, ampm));
|
res.hour = Some(self.adjust_ampm(hour, ampm));
|
||||||
|
} else {
|
||||||
|
ymd.append(value.floor().to_i64().unwrap() as i32, None);
|
||||||
}
|
}
|
||||||
} else if info.get_ampm(&tokens[idx + 1]).is_some()
|
} else if info.get_ampm(&tokens[idx + 1]).is_some()
|
||||||
&& (*ZERO <= value && value < *TWENTY_FOUR)
|
&& (*ZERO <= value && value < *TWENTY_FOUR)
|
||||||
|
@ -38,7 +38,7 @@ fn test_split() {
|
|||||||
macro_rules! test_parse_naive {
|
macro_rules! test_parse_naive {
|
||||||
($py: ident, $parser: ident, $s: expr) => {
|
($py: ident, $parser: ident, $s: expr) => {
|
||||||
let dt: PyObject = $parser.call_method1("parse", $s).unwrap().extract().unwrap();
|
let dt: PyObject = $parser.call_method1("parse", $s).unwrap().extract().unwrap();
|
||||||
let dt_s: String = dt.call_method0($py, "isoformat").unwrap().extract($py).unwrap();
|
let dt_s: String = dt.call_method1($py, "isoformat", " ").unwrap().extract($py).unwrap();
|
||||||
let s = format!("{}", dt_s);
|
let s = format!("{}", dt_s);
|
||||||
|
|
||||||
println!("{}", s);
|
println!("{}", s);
|
||||||
@ -61,5 +61,9 @@ fn test_parse() {
|
|||||||
let py = gil.python();
|
let py = gil.python();
|
||||||
let parser = py.import("dateutil.parser").unwrap();
|
let parser = py.import("dateutil.parser").unwrap();
|
||||||
|
|
||||||
|
test_parse_naive!(py, parser, "2018.5.15");
|
||||||
test_parse_naive!(py, parser, "May 5, 2018");
|
test_parse_naive!(py, parser, "May 5, 2018");
|
||||||
|
test_parse_naive!(py, parser, "Mar. 5, 2018");
|
||||||
|
test_parse_naive!(py, parser, "19990101T23");
|
||||||
|
test_parse_naive!(py, parser, "19990101T2359");
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user