From 142712900fb788fd2874dd2bf9ff0ea977a5288d Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Wed, 13 Nov 2019 23:12:47 -0500 Subject: [PATCH 1/4] Attempt to read timezones from chrono-tz --- Cargo.toml | 1 + src/lib.rs | 19 ++++++++++++++----- src/tests/mod.rs | 1 + src/tests/tz.rs | 20 ++++++++++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 src/tests/tz.rs diff --git a/Cargo.toml b/Cargo.toml index 5df44ac..7207e7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ name = "dtparse" [dependencies] chrono = "0.4" +chrono-tz = "0.5" lazy_static = "1.1" num-traits = "0.2" rust_decimal = "^0.10.1" diff --git a/src/lib.rs b/src/lib.rs index 2ebad81..0ba5381 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,6 +73,7 @@ extern crate lazy_static; extern crate chrono; +extern crate chrono_tz; extern crate num_traits; extern crate rust_decimal; @@ -83,7 +84,10 @@ use chrono::Local; use chrono::NaiveDate; use chrono::NaiveDateTime; use chrono::NaiveTime; +use chrono::Offset; use chrono::Timelike; +use chrono::TimeZone; +use chrono_tz::Tz; use num_traits::cast::ToPrimitive; use rust_decimal::Decimal; use rust_decimal::Error as DecimalError; @@ -948,11 +952,10 @@ impl Parser { fn build_tzaware( &self, - _dt: &NaiveDateTime, + dt: &NaiveDateTime, res: &ParsingResult, tzinfos: &HashMap, ) -> ParseResult> { - // TODO: Actual timezone support if let Some(offset) = res.tzoffset { Ok(Some(FixedOffset::east(offset))) } else if res.tzoffset == None @@ -965,9 +968,15 @@ impl Parser { *tzinfos.get(res.tzname.as_ref().unwrap()).unwrap(), ))) } else if res.tzname.is_some() { - // TODO: Dateutil issues a warning/deprecation notice here. Should we force the issue? - println!("tzname {} identified but not understood. Ignoring for the time being, but behavior is subject to change.", res.tzname.as_ref().unwrap()); - Ok(None) + let tzname = res.tzname.as_ref().unwrap(); + let tz: Result = tzname.parse(); + 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 { Err(ParseError::TimezoneUnsupported) } diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 1776124..9ea7f0f 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -1,3 +1,4 @@ mod fuzzing; mod pycompat_parser; mod pycompat_tokenizer; +mod tz; diff --git a/src/tests/tz.rs b/src/tests/tz.rs new file mode 100644 index 0000000..8e866f3 --- /dev/null +++ b/src/tests/tz.rs @@ -0,0 +1,20 @@ +use crate::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()); +} From 030ca4fcedcc4d7de34abab78cf19b637c1001b5 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Wed, 13 Nov 2019 23:18:37 -0500 Subject: [PATCH 2/4] Rustfmt --- examples/russian.rs | 17 +- src/lib.rs | 228 +-- src/tests/fuzzing.rs | 30 +- src/tests/pycompat_parser.rs | 3090 ++++++++++++++++++++++++------- src/tests/pycompat_tokenizer.rs | 251 ++- src/tokenize.rs | 26 +- src/weekday.rs | 22 +- 7 files changed, 2808 insertions(+), 856 deletions(-) diff --git a/examples/russian.rs b/examples/russian.rs index beb0bb3..ba81a49 100644 --- a/examples/russian.rs +++ b/examples/russian.rs @@ -8,7 +8,6 @@ use dtparse::ParserInfo; use std::collections::HashMap; fn main() { - // In this example, we'll just swap the default "months" parameter // with a version in Russian. Lovingly taken from: // https://github.com/dateutil/dateutil/blob/99f5770e7c63aa049b28abe465d7f1cc25b63fd2/dateutil/test/test_parser.py#L244 @@ -26,14 +25,24 @@ fn main() { vec!["сен", "Сентябрь"], vec!["окт", "Октябрь"], vec!["ноя", "Ноябрь"], - vec!["дек", "Декабрь"] + vec!["дек", "Декабрь"], ]); let p = Parser::new(info); assert_eq!( - p.parse("10 Сентябрь 2015 10:20", None, None, false, false, None, false, &HashMap::new()) - .unwrap().0, + p.parse( + "10 Сентябрь 2015 10:20", + None, + None, + false, + false, + None, + false, + &HashMap::new() + ) + .unwrap() + .0, NaiveDate::from_ymd(2015, 9, 10).and_hms(10, 20, 0) ); } diff --git a/src/lib.rs b/src/lib.rs index 0ba5381..04e84e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,23 +4,23 @@ //! # dtparse //! The fully-featured "even I couldn't understand that" time parser. //! Designed to take in strings and give back sensible dates and times. -//! +//! //! dtparse has its foundations in the [`dateutil`](dateutil) library for //! Python, which excels at taking "interesting" strings and trying to make //! sense of the dates and times they contain. A couple of quick examples //! from the test cases should give some context: -//! +//! //! ```rust,ignore (tests-dont-compile-on-old-rust) //! # extern crate chrono; //! # extern crate dtparse; //! use chrono::prelude::*; //! use dtparse::parse; -//! +//! //! assert_eq!( //! parse("2008.12.30"), //! Ok((NaiveDate::from_ymd(2008, 12, 30).and_hms(0, 0, 0), None)) //! ); -//! +//! //! // It can even handle timezones! //! assert_eq!( //! parse("January 4, 2024; 18:30:04 +02:00"), @@ -30,17 +30,17 @@ //! )) //! ); //! ``` -//! +//! //! And we can even handle fuzzy strings where dates/times aren't the //! only content if we dig into the implementation a bit! -//! +//! //! ```rust,ignore (tests-dont-compile-on-old-rust) //! # extern crate chrono; //! # extern crate dtparse; //! use chrono::prelude::*; //! use dtparse::Parser; //! # use std::collections::HashMap; -//! +//! //! let mut p = Parser::default(); //! assert_eq!( //! p.parse( @@ -58,7 +58,7 @@ //! )) //! ); //! ``` -//! +//! //! Further examples can be found in the `examples` directory on international usage. //! //! # Usage @@ -66,7 +66,7 @@ //! `dtparse` requires a minimum Rust version of 1.21 to build, but is tested on Windows, OSX, //! BSD, Linux, and WASM. The build is also compiled against the iOS and Android SDK's, but is not //! tested against them. -//! +//! //! [dateutil]: https://github.com/dateutil/dateutil #[macro_use] @@ -85,14 +85,14 @@ use chrono::NaiveDate; use chrono::NaiveDateTime; use chrono::NaiveTime; use chrono::Offset; -use chrono::Timelike; use chrono::TimeZone; +use chrono::Timelike; use chrono_tz::Tz; use num_traits::cast::ToPrimitive; use rust_decimal::Decimal; use rust_decimal::Error as DecimalError; -use std::collections::HashMap; use std::cmp::min; +use std::collections::HashMap; use std::num::ParseIntError; use std::str::FromStr; use std::vec::Vec; @@ -178,7 +178,7 @@ pub fn parse_info(vec: Vec>) -> HashMap { } /// Container for specific tokens to be recognized during parsing. -/// +/// /// - `jump`: Values that indicate the end of a token for parsing and can be ignored /// - `weekday`: Names of the days of the week /// - `months`: Names of the months @@ -191,7 +191,7 @@ pub fn parse_info(vec: Vec>) -> HashMap { /// - `yearfirst`: Upon encountering an ambiguous date, treat the first value as the year /// - `year`: The current year /// - `century`: The first year in the current century -/// +/// /// Please note that if both `dayfirst` and `yearfirst` are true, years take precedence /// and will be parsed as "YDM" #[derive(Debug, PartialEq)] @@ -232,12 +232,10 @@ impl Default for ParserInfo { let century = year / 100 * 100; ParserInfo { - jump: parse_info(vec![ - vec![ - " ", ".", ",", ";", "-", "/", "'", "at", "on", "and", "ad", "m", "t", "of", - "st", "nd", "rd", "th", - ], - ]), + jump: parse_info(vec![vec![ + " ", ".", ",", ";", "-", "/", "'", "at", "on", "and", "ad", "m", "t", "of", "st", + "nd", "rd", "th", + ]]), weekday: parse_info(vec![ vec!["Mon", "Monday"], vec!["Tue", "Tues", "Tuesday"], @@ -345,7 +343,8 @@ impl ParserInfo { if res.tzoffset == Some(0) && res.tzname.is_none() || res.tzname == Some("Z".to_owned()) { res.tzname = Some("UTC".to_owned()); res.tzoffset = Some(0); - } else if res.tzoffset != Some(0) && res.tzname.is_some() + } else if res.tzoffset != Some(0) + && res.tzname.is_some() && self.utczone_index(res.tzname.as_ref().unwrap()) { res.tzoffset = Some(0); @@ -362,16 +361,16 @@ fn days_in_month(year: i32, month: i32) -> Result { }; match month { - 2 => if leap_year { - Ok(29) - } else { - Ok(28) - }, + 2 => { + if leap_year { + Ok(29) + } else { + Ok(28) + } + } 1 | 3 | 5 | 7 | 8 | 10 | 12 => Ok(31), 4 | 6 | 9 | 11 => Ok(30), - _ => { - Err(ParseError::ImpossibleTimestamp("Invalid month")) - } + _ => Err(ParseError::ImpossibleTimestamp("Invalid month")), } } @@ -425,9 +424,7 @@ impl YMD { Some(YMDLabel::Month) => { return Err(ParseError::ImpossibleTimestamp("Invalid month")) } - Some(YMDLabel::Day) => { - return Err(ParseError::ImpossibleTimestamp("Invalid day")) - } + Some(YMDLabel::Day) => return Err(ParseError::ImpossibleTimestamp("Invalid day")), } } @@ -439,9 +436,7 @@ impl YMD { Some(YMDLabel::Month) => { return Err(ParseError::ImpossibleTimestamp("Invalid month")) } - Some(YMDLabel::Day) => { - return Err(ParseError::ImpossibleTimestamp("Invalid day")) - } + Some(YMDLabel::Day) => return Err(ParseError::ImpossibleTimestamp("Invalid day")), } } @@ -502,19 +497,15 @@ impl YMD { } if self._ymd.len() != strids.len() { - return Err(ParseError::YearMonthDayError("Tried to resolve year, month, and day without enough information")); + return Err(ParseError::YearMonthDayError( + "Tried to resolve year, month, and day without enough information", + )); } Ok(( - strids - .get(&YMDLabel::Year) - .map(|i| self._ymd[*i]), - strids - .get(&YMDLabel::Month) - .map(|i| self._ymd[*i]), - strids - .get(&YMDLabel::Day) - .map(|i| self._ymd[*i]), + strids.get(&YMDLabel::Year).map(|i| self._ymd[*i]), + strids.get(&YMDLabel::Month).map(|i| self._ymd[*i]), + strids.get(&YMDLabel::Day).map(|i| self._ymd[*i]), )) } @@ -527,28 +518,24 @@ impl YMD { let len_ymd = self._ymd.len(); let mut strids: HashMap = HashMap::new(); - self.ystridx - .map(|u| strids.insert(YMDLabel::Year, u)); - self.mstridx - .map(|u| strids.insert(YMDLabel::Month, u)); - self.dstridx - .map(|u| strids.insert(YMDLabel::Day, u)); + self.ystridx.map(|u| strids.insert(YMDLabel::Year, u)); + self.mstridx.map(|u| strids.insert(YMDLabel::Month, u)); + self.dstridx.map(|u| strids.insert(YMDLabel::Day, u)); // TODO: More Rustiomatic way of doing this? - if len_ymd == strids.len() && !strids.is_empty() - || (len_ymd == 3 && strids.len() == 2) - { + if len_ymd == strids.len() && !strids.is_empty() || (len_ymd == 3 && strids.len() == 2) { return self.resolve_from_stridxs(&mut strids); }; // Received year, month, day, and ??? if len_ymd > 3 { - return Err(ParseError::YearMonthDayError("Received extra tokens in resolving year, month, and day")); + return Err(ParseError::YearMonthDayError( + "Received extra tokens in resolving year, month, and day", + )); } match (len_ymd, self.mstridx) { - (1, Some(val)) | - (2, Some(val)) => { + (1, Some(val)) | (2, Some(val)) => { let other = if len_ymd == 1 { self._ymd[0] } else { @@ -558,7 +545,7 @@ impl YMD { return Ok((Some(other), Some(self._ymd[val]), None)); } return Ok((None, Some(self._ymd[val]), Some(other))); - }, + } (2, None) => { if self._ymd[0] > 31 { return Ok((Some(self._ymd[0]), Some(self._ymd[1]), None)); @@ -570,28 +557,29 @@ impl YMD { return Ok((None, Some(self._ymd[1]), Some(self._ymd[0]))); } return Ok((None, Some(self._ymd[0]), Some(self._ymd[1]))); - }, + } (3, Some(0)) => { if self._ymd[1] > 31 { return Ok((Some(self._ymd[1]), Some(self._ymd[0]), Some(self._ymd[2]))); } return Ok((Some(self._ymd[2]), Some(self._ymd[0]), Some(self._ymd[1]))); - }, + } (3, Some(1)) => { if self._ymd[0] > 31 || (yearfirst && self._ymd[2] <= 31) { return Ok((Some(self._ymd[0]), Some(self._ymd[1]), Some(self._ymd[2]))); } return Ok((Some(self._ymd[2]), Some(self._ymd[1]), Some(self._ymd[0]))); - }, + } (3, Some(2)) => { // It was in the original docs, so: WTF!? if self._ymd[1] > 31 { return Ok((Some(self._ymd[2]), Some(self._ymd[1]), Some(self._ymd[0]))); } return Ok((Some(self._ymd[0]), Some(self._ymd[2]), Some(self._ymd[1]))); - }, + } (3, None) => { - if self._ymd[0] > 31 || self.ystridx == Some(0) + if self._ymd[0] > 31 + || self.ystridx == Some(0) || (yearfirst && self._ymd[1] <= 12 && self._ymd[2] <= 31) { if dayfirst && self._ymd[2] <= 12 { @@ -602,8 +590,10 @@ impl YMD { return Ok((Some(self._ymd[2]), Some(self._ymd[1]), Some(self._ymd[0]))); } return Ok((Some(self._ymd[2]), Some(self._ymd[0]), Some(self._ymd[1]))); - }, - (_, _) => { return Ok((None, None, None)); }, + } + (_, _) => { + return Ok((None, None, None)); + } } } } @@ -635,7 +625,7 @@ pub struct Parser { impl Parser { /// Create a new `Parser` instance using the provided `ParserInfo`. - /// + /// /// This method allows you to set up a parser to handle different /// names for days of the week, months, etc., enabling customization /// for different languages or extra values. @@ -646,27 +636,27 @@ impl Parser { /// Main method to trigger parsing of a string using the previously-provided /// parser information. Returns a naive timestamp along with timezone and /// unused tokens if available. - /// + /// /// `dayfirst` and `yearfirst` force parser behavior in the event of ambiguous /// dates. Consider the following scenarios where we parse the string '01.02.03' - /// + /// /// - `dayfirst=Some(true)`, `yearfirst=None`: Results in `February 2, 2003` /// - `dayfirst=None`, `yearfirst=Some(true)`: Results in `February 3, 2001` /// - `dayfirst=Some(true)`, `yearfirst=Some(true)`: Results in `March 2, 2001` - /// + /// /// `fuzzy` enables fuzzy parsing mode, allowing the parser to skip tokens if /// they are unrecognized. However, the unused tokens will not be returned /// unless `fuzzy_with_tokens` is set as `true`. - /// + /// /// `default` is the timestamp used to infer missing values, and is midnight /// of the current day by default. For example, when parsing the text '2003', /// we will use the current month and day as a default value, leading to a /// result of 'March 3, 2003' if the function was run using a default of /// March 3rd. - /// + /// /// `ignoretz` forces the parser to ignore timezone information even if it /// is recognized in the time string - /// + /// /// `tzinfos` is a map of timezone names to the offset seconds. For example, /// the parser would ignore the 'EST' part of the string in '10 AM EST' /// unless you added a `tzinfos` map of `{"EST": "14400"}`. Please note that @@ -758,7 +748,9 @@ impl Parser { } i += 2; - } else if i + 4 < len_l && l[i + 1] == l[i + 3] && l[i + 3] == " " + } else if i + 4 < len_l + && l[i + 1] == l[i + 3] + && l[i + 3] == " " && self.info.pertain_index(&l[i + 2]) { // Jan of 01 @@ -796,7 +788,7 @@ impl Parser { } else { "+".to_owned() }; - l[i+1] = item; + l[i + 1] = item; res.tzoffset = None; @@ -832,8 +824,11 @@ impl Parser { Some(signal * (hour_offset.unwrap() * 3600 + min_offset.unwrap() * 60)); let tzname = res.tzname.clone(); - if i + 5 < len_l && self.info.jump_index(&l[i + 2]) && l[i + 3] == "(" - && l[i + 5] == ")" && 3 <= l[i + 4].len() + if i + 5 < len_l + && self.info.jump_index(&l[i + 2]) + && l[i + 3] == "(" + && l[i + 5] == ")" + && 3 <= l[i + 4].len() && self.could_be_tzname(res.hour, &tzname, None, &l[i + 4]) { // (GMT) @@ -879,7 +874,10 @@ impl Parser { .chars() .all(|c| 65u8 as char <= c && c <= 90u8 as char); - hour.is_some() && tzname.is_none() && tzoffset.is_none() && token.len() <= 5 + hour.is_some() + && tzname.is_none() + && tzoffset.is_none() + && token.len() <= 5 && all_ascii_upper } @@ -903,7 +901,11 @@ impl Parser { Ok(val_is_ampm) } - fn build_naive(&self, res: &ParsingResult, default: &NaiveDateTime) -> ParseResult { + fn build_naive( + &self, + res: &ParsingResult, + default: &NaiveDateTime, + ) -> ParseResult { let y = res.year.unwrap_or_else(|| default.year()); let m = res.month.unwrap_or_else(|| default.month() as i32) as u32; @@ -923,7 +925,10 @@ impl Parser { let d = NaiveDate::from_ymd( y, m, - min(res.day.unwrap_or(default.day() as i32) as u32, days_in_month(y, m as i32)?) + min( + res.day.unwrap_or(default.day() as i32) as u32, + days_in_month(y, m as i32)?, + ), ); let d = d + d_offset; @@ -931,21 +936,23 @@ impl Parser { let hour = res.hour.unwrap_or(default.hour() as i32) as u32; let minute = res.minute.unwrap_or(default.minute() as i32) as u32; let second = res.second.unwrap_or(default.second() as i32) as u32; - let microsecond = res.microsecond + let microsecond = res + .microsecond .unwrap_or(default.timestamp_subsec_micros() as i32) as u32; - let t = NaiveTime::from_hms_micro_opt(hour, minute, second, microsecond).ok_or_else(|| { - if hour >= 24 { - ParseError::ImpossibleTimestamp("Invalid hour") - } else if minute >= 60 { - ParseError::ImpossibleTimestamp("Invalid minute") - } else if second >= 60 { - ParseError::ImpossibleTimestamp("Invalid second") - } else if microsecond >= 2_000_000 { - ParseError::ImpossibleTimestamp("Invalid microsecond") - } else { - unreachable!(); - } - })?; + let t = + NaiveTime::from_hms_micro_opt(hour, minute, second, microsecond).ok_or_else(|| { + if hour >= 24 { + ParseError::ImpossibleTimestamp("Invalid hour") + } else if minute >= 60 { + ParseError::ImpossibleTimestamp("Invalid minute") + } else if second >= 60 { + ParseError::ImpossibleTimestamp("Invalid second") + } else if microsecond >= 2_000_000 { + ParseError::ImpossibleTimestamp("Invalid microsecond") + } else { + unreachable!(); + } + })?; Ok(NaiveDateTime::new(d, t)) } @@ -959,8 +966,10 @@ impl Parser { if let Some(offset) = res.tzoffset { Ok(Some(FixedOffset::east(offset))) } else if res.tzoffset == None - && (res.tzname == Some(" ".to_owned()) || res.tzname == Some(".".to_owned()) - || res.tzname == Some("-".to_owned()) || res.tzname == None) + && (res.tzname == Some(" ".to_owned()) + || res.tzname == Some(".".to_owned()) + || res.tzname == Some("-".to_owned()) + || res.tzname == None) { Ok(None) } else if res.tzname.is_some() && tzinfos.contains_key(res.tzname.as_ref().unwrap()) { @@ -1000,7 +1009,9 @@ impl Parser { // TODO: I miss the `x in y` syntax // TODO: Decompose this logic a bit - if ymd.len() == 3 && (len_li == 2 || len_li == 4) && res.hour.is_none() + if ymd.len() == 3 + && (len_li == 2 || len_li == 4) + && res.hour.is_none() && (idx + 1 >= len_l || (tokens[idx + 1] != ":" && info.hms_index(&tokens[idx + 1]).is_none())) { @@ -1031,7 +1042,11 @@ impl Parser { } else if vec![8, 12, 14].contains(&len_li) { // YYMMDD let s = &tokens[idx]; - ymd.append(s[..4].parse::().unwrap(), &s[..4], Some(YMDLabel::Year))?; + ymd.append( + s[..4].parse::().unwrap(), + &s[..4], + Some(YMDLabel::Year), + )?; ymd.append(s[4..6].parse::().unwrap(), &s[4..6], None)?; ymd.append(s[6..8].parse::().unwrap(), &s[6..8], None)?; @@ -1088,10 +1103,10 @@ impl Parser { if let Some(value) = info.month_index(&tokens[idx + 4]) { ymd.append(value as i32, &tokens[idx + 4], Some(YMDLabel::Month))?; } else if let Ok(val) = tokens[idx + 4].parse::() { - ymd.append(val, &tokens[idx + 4], None)?; - } else { - return Err(ParseError::UnrecognizedFormat); - } + ymd.append(val, &tokens[idx + 4], None)?; + } else { + return Err(ParseError::UnrecognizedFormat); + } idx += 2; } @@ -1169,7 +1184,7 @@ impl Parser { len_l - 2 } else if idx > 1 { idx - 2 - } else if len_l == 0{ + } else if len_l == 0 { panic!("Attempting to find_hms_index() wih no tokens."); } else { 0 @@ -1177,13 +1192,18 @@ impl Parser { if idx + 1 < len_l && info.hms_index(&tokens[idx + 1]).is_some() { hms_idx = Some(idx + 1) - } else if allow_jump && idx + 2 < len_l && tokens[idx + 1] == " " + } else if allow_jump + && idx + 2 < len_l + && tokens[idx + 1] == " " && info.hms_index(&tokens[idx + 2]).is_some() { hms_idx = Some(idx + 2) } else if idx > 0 && info.hms_index(&tokens[idx - 1]).is_some() { hms_idx = Some(idx - 1) - } else if len_l > 0 && idx > 0 && idx == len_l - 1 && tokens[idx - 1] == " " + } else if len_l > 0 + && idx > 0 + && idx == len_l - 1 + && tokens[idx - 1] == " " && info.hms_index(&tokens[idx_minus_two]).is_some() { hms_idx = Some(idx - 2) @@ -1288,7 +1308,7 @@ fn ljust(s: &str, chars: usize, replace: char) -> String { /// Main entry point for using `dtparse`. The parse function is responsible for /// taking in a string representing some time value, and turning it into /// a timestamp with optional timezone information if it can be identified. -/// +/// /// The default implementation assumes English values for names of months, /// days of the week, etc. It is equivalent to Python's `dateutil.parser.parse()` pub fn parse(timestr: &str) -> ParseResult<(NaiveDateTime, Option)> { diff --git a/src/tests/fuzzing.rs b/src/tests/fuzzing.rs index 426b8b7..d9ca04c 100644 --- a/src/tests/fuzzing.rs +++ b/src/tests/fuzzing.rs @@ -7,18 +7,36 @@ use Parser; #[test] fn test_fuzz() { - - assert_eq!(parse("\x2D\x38\x31\x39\x34\x38\x34"), Err(ParseError::ImpossibleTimestamp("Invalid month"))); + assert_eq!( + parse("\x2D\x38\x31\x39\x34\x38\x34"), + Err(ParseError::ImpossibleTimestamp("Invalid month")) + ); // Garbage in the third delimited field - assert_eq!(parse("2..\x00\x000d\x00+\x010d\x01\x00\x00\x00+"), - Err(ParseError::UnrecognizedFormat)); + assert_eq!( + parse("2..\x00\x000d\x00+\x010d\x01\x00\x00\x00+"), + Err(ParseError::UnrecognizedFormat) + ); // OverflowError: Python int too large to convert to C long // assert_eq!(parse("8888884444444888444444444881"), Err(ParseError::AmPmWithoutHour)); let default = NaiveDate::from_ymd(2016, 6, 29).and_hms(0, 0, 0); let p = Parser::default(); - let res = p.parse("\x0D\x31", None, None, false, false, Some(&default), false, &HashMap::new()).unwrap(); + let res = p + .parse( + "\x0D\x31", + None, + None, + false, + false, + Some(&default), + false, + &HashMap::new(), + ) + .unwrap(); assert_eq!(res.0, default); - assert_eq!(parse("\x2D\x2D\x32\x31\x38\x6D"), Err(ParseError::ImpossibleTimestamp("Invalid minute"))); + assert_eq!( + parse("\x2D\x2D\x32\x31\x38\x6D"), + Err(ParseError::ImpossibleTimestamp("Invalid minute")) + ); } diff --git a/src/tests/pycompat_parser.rs b/src/tests/pycompat_parser.rs index 72885ab..6ad4066 100644 --- a/src/tests/pycompat_parser.rs +++ b/src/tests/pycompat_parser.rs @@ -1,4 +1,3 @@ - //! This code has been generated by running the `build_pycompat.py` script //! in the repository root. Please do not edit it, as your edits will be destroyed //! upon re-running code generation. @@ -11,9 +10,9 @@ use chrono::NaiveDateTime; use chrono::Timelike; use std::collections::HashMap; +use parse; use Parser; use ParserInfo; -use parse; struct PyDateTime { year: i32, @@ -23,7 +22,7 @@ struct PyDateTime { minute: u32, second: u32, micros: u32, - tzo: Option + tzo: Option, } fn parse_and_assert( @@ -38,41 +37,80 @@ fn parse_and_assert( ignoretz: bool, tzinfos: &HashMap, ) { - let parser = Parser::new(info); - let rs_parsed = parser.parse( - s, - dayfirst, - yearfirst, - fuzzy, - fuzzy_with_tokens, - default, - ignoretz, - tzinfos).expect(&format!("Unable to parse date in Rust '{}'", s)); + let rs_parsed = parser + .parse( + s, + dayfirst, + yearfirst, + fuzzy, + fuzzy_with_tokens, + default, + ignoretz, + tzinfos, + ) + .expect(&format!("Unable to parse date in Rust '{}'", s)); assert_eq!(pdt.year, rs_parsed.0.year(), "Year mismatch for '{}'", s); assert_eq!(pdt.month, rs_parsed.0.month(), "Month mismatch for '{}'", s); assert_eq!(pdt.day, rs_parsed.0.day(), "Day mismatch for '{}'", s); assert_eq!(pdt.hour, rs_parsed.0.hour(), "Hour mismatch for '{}'", s); - assert_eq!(pdt.minute, rs_parsed.0.minute(), "Minute mismatch f'or' {}", s); - assert_eq!(pdt.second, rs_parsed.0.second(), "Second mismatch for '{}'", s); - assert_eq!(pdt.micros, rs_parsed.0.timestamp_subsec_micros(), "Microsecond mismatch for '{}'", s); - assert_eq!(pdt.tzo, rs_parsed.1.map(|u| u.local_minus_utc()), "Timezone Offset mismatch for '{}'", s); + assert_eq!( + pdt.minute, + rs_parsed.0.minute(), + "Minute mismatch f'or' {}", + s + ); + assert_eq!( + pdt.second, + rs_parsed.0.second(), + "Second mismatch for '{}'", + s + ); + assert_eq!( + pdt.micros, + rs_parsed.0.timestamp_subsec_micros(), + "Microsecond mismatch for '{}'", + s + ); + assert_eq!( + pdt.tzo, + rs_parsed.1.map(|u| u.local_minus_utc()), + "Timezone Offset mismatch for '{}'", + s + ); } -fn parse_and_assert_simple( - pdt: PyDateTime, - s: &str, -) { +fn parse_and_assert_simple(pdt: PyDateTime, s: &str) { let rs_parsed = parse(s).expect(&format!("Unable to parse date in Rust '{}'", s)); assert_eq!(pdt.year, rs_parsed.0.year(), "Year mismatch for '{}'", s); assert_eq!(pdt.month, rs_parsed.0.month(), "Month mismatch for '{}'", s); assert_eq!(pdt.day, rs_parsed.0.day(), "Day mismatch for '{}'", s); assert_eq!(pdt.hour, rs_parsed.0.hour(), "Hour mismatch for '{}'", s); - assert_eq!(pdt.minute, rs_parsed.0.minute(), "Minute mismatch for '{}'", s); - assert_eq!(pdt.second, rs_parsed.0.second(), "Second mismatch for '{}'", s); - assert_eq!(pdt.micros, rs_parsed.0.timestamp_subsec_micros(), "Microsecond mismatch for '{}'", s); - assert_eq!(pdt.tzo, rs_parsed.1.map(|u| u.local_minus_utc()), "Timezone Offset mismatch for '{}'", s); + assert_eq!( + pdt.minute, + rs_parsed.0.minute(), + "Minute mismatch for '{}'", + s + ); + assert_eq!( + pdt.second, + rs_parsed.0.second(), + "Second mismatch for '{}'", + s + ); + assert_eq!( + pdt.micros, + rs_parsed.0.timestamp_subsec_micros(), + "Microsecond mismatch for '{}'", + s + ); + assert_eq!( + pdt.tzo, + rs_parsed.1.map(|u| u.local_minus_utc()), + "Timezone Offset mismatch for '{}'", + s + ); } fn parse_fuzzy_and_assert( @@ -88,35 +126,57 @@ fn parse_fuzzy_and_assert( ignoretz: bool, tzinfos: &HashMap, ) { - let parser = Parser::new(info); - let rs_parsed = parser.parse( - s, - dayfirst, - yearfirst, - fuzzy, - fuzzy_with_tokens, - default, - ignoretz, - tzinfos).expect(&format!("Unable to parse date in Rust '{}'", s)); + let rs_parsed = parser + .parse( + s, + dayfirst, + yearfirst, + fuzzy, + fuzzy_with_tokens, + default, + ignoretz, + tzinfos, + ) + .expect(&format!("Unable to parse date in Rust '{}'", s)); assert_eq!(pdt.year, rs_parsed.0.year(), "Year mismatch for '{}'", s); assert_eq!(pdt.month, rs_parsed.0.month(), "Month mismatch for '{}'", s); assert_eq!(pdt.day, rs_parsed.0.day(), "Day mismatch for '{}'", s); assert_eq!(pdt.hour, rs_parsed.0.hour(), "Hour mismatch for '{}'", s); - assert_eq!(pdt.minute, rs_parsed.0.minute(), "Minute mismatch f'or' {}", s); - assert_eq!(pdt.second, rs_parsed.0.second(), "Second mismatch for '{}'", s); - assert_eq!(pdt.micros, rs_parsed.0.timestamp_subsec_micros(), "Microsecond mismatch for '{}'", s); - assert_eq!(pdt.tzo, rs_parsed.1.map(|u| u.local_minus_utc()), "Timezone Offset mismatch for '{}'", s); + assert_eq!( + pdt.minute, + rs_parsed.0.minute(), + "Minute mismatch f'or' {}", + s + ); + assert_eq!( + pdt.second, + rs_parsed.0.second(), + "Second mismatch for '{}'", + s + ); + assert_eq!( + pdt.micros, + rs_parsed.0.timestamp_subsec_micros(), + "Microsecond mismatch for '{}'", + s + ); + assert_eq!( + pdt.tzo, + rs_parsed.1.map(|u| u.local_minus_utc()), + "Timezone Offset mismatch for '{}'", + s + ); assert_eq!(ptokens, rs_parsed.2, "Tokens mismatch for '{}'", s); } macro_rules! rs_tzinfo_map { - () => ({ + () => {{ let mut h = HashMap::new(); h.insert("BRST".to_owned(), -10800); h - }); + }}; } #[test] @@ -124,12 +184,27 @@ fn test_parse_default0() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 28, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 28, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Thu Sep 25 10:36:28", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Thu Sep 25 10:36:28", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -137,12 +212,27 @@ fn test_parse_default1() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 28, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 28, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Sep 10:36:28", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Sep 10:36:28", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -150,12 +240,27 @@ fn test_parse_default2() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 28, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 28, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10:36:28", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10:36:28", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -163,12 +268,27 @@ fn test_parse_default3() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10:36", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10:36", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -176,12 +296,27 @@ fn test_parse_default4() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Sep 2003", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Sep 2003", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -189,12 +324,27 @@ fn test_parse_default5() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Sep", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Sep", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -202,12 +352,27 @@ fn test_parse_default6() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "2003", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "2003", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -215,12 +380,27 @@ fn test_parse_default7() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 28, - micros: 500000, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 28, + micros: 500000, + tzo: None, }; - parse_and_assert(pdt, info, "10h36m28.5s", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10h36m28.5s", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -228,12 +408,27 @@ fn test_parse_default8() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 28, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 28, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10h36m28s", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10h36m28s", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -241,12 +436,27 @@ fn test_parse_default9() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10h36m", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10h36m", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -254,12 +464,27 @@ fn test_parse_default10() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10h", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10h", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -267,12 +492,27 @@ fn test_parse_default11() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10 h 36", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10 h 36", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -280,12 +520,27 @@ fn test_parse_default12() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 30, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 30, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10 h 36.5", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10 h 36.5", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -293,12 +548,27 @@ fn test_parse_default13() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 36, second: 5, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 36, + second: 5, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "36 m 5", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "36 m 5", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -306,12 +576,27 @@ fn test_parse_default14() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 36, second: 5, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 36, + second: 5, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "36 m 5 s", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "36 m 5 s", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -319,12 +604,27 @@ fn test_parse_default15() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 36, second: 5, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 36, + second: 5, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "36 m 05", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "36 m 05", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -332,12 +632,27 @@ fn test_parse_default16() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 36, second: 5, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 36, + second: 5, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "36 m 05 s", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "36 m 05 s", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -345,12 +660,27 @@ fn test_parse_default17() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10h am", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10h am", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -358,12 +688,27 @@ fn test_parse_default18() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 22, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 22, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10h pm", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10h pm", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -371,12 +716,27 @@ fn test_parse_default19() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10am", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10am", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -384,12 +744,27 @@ fn test_parse_default20() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 22, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 22, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10pm", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10pm", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -397,12 +772,27 @@ fn test_parse_default21() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10:00 am", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10:00 am", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -410,12 +800,27 @@ fn test_parse_default22() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 22, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 22, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10:00 pm", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10:00 pm", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -423,12 +828,27 @@ fn test_parse_default23() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10:00am", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10:00am", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -436,12 +856,27 @@ fn test_parse_default24() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 22, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 22, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10:00pm", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10:00pm", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -449,12 +884,27 @@ fn test_parse_default25() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10:00a.m", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10:00a.m", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -462,12 +912,27 @@ fn test_parse_default26() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 22, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 22, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10:00p.m", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10:00p.m", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -475,12 +940,27 @@ fn test_parse_default27() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10:00a.m.", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10:00a.m.", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -488,12 +968,27 @@ fn test_parse_default28() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 22, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 22, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10:00p.m.", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10:00p.m.", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -501,12 +996,27 @@ fn test_parse_default29() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 10, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 10, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "October", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "October", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -514,12 +1024,27 @@ fn test_parse_default30() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2000, month: 12, day: 31, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None + year: 2000, + month: 12, + day: 31, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "31-Dec-00", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "31-Dec-00", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -527,12 +1052,27 @@ fn test_parse_default31() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 1, second: 2, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 1, + second: 2, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "0:01:02", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "0:01:02", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -540,12 +1080,27 @@ fn test_parse_default32() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 1, second: 2, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 1, + second: 2, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "12h 01m02s am", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "12h 01m02s am", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -553,12 +1108,27 @@ fn test_parse_default33() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 12, minute: 8, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 12, + minute: 8, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "12:08 PM", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "12:08 PM", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -566,12 +1136,27 @@ fn test_parse_default34() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 1, minute: 2, second: 3, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 1, + minute: 2, + second: 3, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "01h02m03", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "01h02m03", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -579,12 +1164,27 @@ fn test_parse_default35() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 1, minute: 2, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 1, + minute: 2, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "01h02", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "01h02", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -592,12 +1192,27 @@ fn test_parse_default36() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 1, minute: 0, second: 2, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 1, + minute: 0, + second: 2, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "01h02s", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "01h02s", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -605,12 +1220,27 @@ fn test_parse_default37() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 1, second: 2, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 1, + second: 2, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "01m02", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "01m02", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -618,12 +1248,27 @@ fn test_parse_default38() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 2, minute: 1, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 2, + minute: 1, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "01m02h", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "01m02h", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -631,12 +1276,27 @@ fn test_parse_default39() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2004, month: 4, day: 10, - hour: 11, minute: 30, second: 0, - micros: 0, tzo: None + year: 2004, + month: 4, + day: 10, + hour: 11, + minute: 30, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "2004 10 Apr 11h30m", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "2004 10 Apr 11h30m", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -644,12 +1304,27 @@ fn test_parse_default40() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 3, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 3, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Sep 03", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Sep 03", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -657,12 +1332,27 @@ fn test_parse_default41() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Sep of 03", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Sep of 03", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -670,12 +1360,27 @@ fn test_parse_default42() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2017, month: 11, day: 25, - hour: 2, minute: 17, second: 0, - micros: 0, tzo: None + year: 2017, + month: 11, + day: 25, + hour: 2, + minute: 17, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "02:17NOV2017", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "02:17NOV2017", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -683,12 +1388,27 @@ fn test_parse_default43() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 28, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 28, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Thu Sep 10:36:28", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Thu Sep 10:36:28", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -696,12 +1416,27 @@ fn test_parse_default44() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 28, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 28, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Thu 10:36:28", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Thu 10:36:28", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -709,12 +1444,27 @@ fn test_parse_default45() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 10, day: 1, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 10, + day: 1, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Wed", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Wed", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -722,20 +1472,40 @@ fn test_parse_default46() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2003, 9, 25).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2003, month: 10, day: 1, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 10, + day: 1, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Wednesday", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Wednesday", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] fn test_parse_simple0() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 28, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 28, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "Thu Sep 25 10:36:28 2003"); } @@ -743,9 +1513,14 @@ fn test_parse_simple0() { #[test] fn test_parse_simple1() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "Thu Sep 25 2003"); } @@ -753,9 +1528,14 @@ fn test_parse_simple1() { #[test] fn test_parse_simple2() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 49, second: 41, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 49, + second: 41, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "2003-09-25T10:49:41"); } @@ -763,9 +1543,14 @@ fn test_parse_simple2() { #[test] fn test_parse_simple3() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 49, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 49, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "2003-09-25T10:49"); } @@ -773,9 +1558,14 @@ fn test_parse_simple3() { #[test] fn test_parse_simple4() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "2003-09-25T10"); } @@ -783,9 +1573,14 @@ fn test_parse_simple4() { #[test] fn test_parse_simple5() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "2003-09-25"); } @@ -793,9 +1588,14 @@ fn test_parse_simple5() { #[test] fn test_parse_simple6() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 49, second: 41, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 49, + second: 41, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "20030925T104941"); } @@ -803,9 +1603,14 @@ fn test_parse_simple6() { #[test] fn test_parse_simple7() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 49, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 49, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "20030925T1049"); } @@ -813,9 +1618,14 @@ fn test_parse_simple7() { #[test] fn test_parse_simple8() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "20030925T10"); } @@ -823,9 +1633,14 @@ fn test_parse_simple8() { #[test] fn test_parse_simple9() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "20030925"); } @@ -833,9 +1648,14 @@ fn test_parse_simple9() { #[test] fn test_parse_simple10() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 49, second: 41, - micros: 502000, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 49, + second: 41, + micros: 502000, + tzo: None, }; parse_and_assert_simple(pdt, "2003-09-25 10:49:41,502"); } @@ -843,9 +1663,14 @@ fn test_parse_simple10() { #[test] fn test_parse_simple11() { let pdt = PyDateTime { - year: 1997, month: 9, day: 2, - hour: 9, minute: 8, second: 0, - micros: 0, tzo: None, + year: 1997, + month: 9, + day: 2, + hour: 9, + minute: 8, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "199709020908"); } @@ -853,9 +1678,14 @@ fn test_parse_simple11() { #[test] fn test_parse_simple12() { let pdt = PyDateTime { - year: 1997, month: 9, day: 2, - hour: 9, minute: 8, second: 7, - micros: 0, tzo: None, + year: 1997, + month: 9, + day: 2, + hour: 9, + minute: 8, + second: 7, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "19970902090807"); } @@ -863,9 +1693,14 @@ fn test_parse_simple12() { #[test] fn test_parse_simple13() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "2003-09-25"); } @@ -873,9 +1708,14 @@ fn test_parse_simple13() { #[test] fn test_parse_simple14() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "09-25-2003"); } @@ -883,9 +1723,14 @@ fn test_parse_simple14() { #[test] fn test_parse_simple15() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "25-09-2003"); } @@ -893,9 +1738,14 @@ fn test_parse_simple15() { #[test] fn test_parse_simple16() { let pdt = PyDateTime { - year: 2003, month: 10, day: 9, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 10, + day: 9, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "10-09-2003"); } @@ -903,9 +1753,14 @@ fn test_parse_simple16() { #[test] fn test_parse_simple17() { let pdt = PyDateTime { - year: 2003, month: 10, day: 9, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 10, + day: 9, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "10-09-03"); } @@ -913,9 +1768,14 @@ fn test_parse_simple17() { #[test] fn test_parse_simple18() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "2003.09.25"); } @@ -923,9 +1783,14 @@ fn test_parse_simple18() { #[test] fn test_parse_simple19() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "09.25.2003"); } @@ -933,9 +1798,14 @@ fn test_parse_simple19() { #[test] fn test_parse_simple20() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "25.09.2003"); } @@ -943,9 +1813,14 @@ fn test_parse_simple20() { #[test] fn test_parse_simple21() { let pdt = PyDateTime { - year: 2003, month: 10, day: 9, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 10, + day: 9, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "10.09.2003"); } @@ -953,9 +1828,14 @@ fn test_parse_simple21() { #[test] fn test_parse_simple22() { let pdt = PyDateTime { - year: 2003, month: 10, day: 9, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 10, + day: 9, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "10.09.03"); } @@ -963,9 +1843,14 @@ fn test_parse_simple22() { #[test] fn test_parse_simple23() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "2003/09/25"); } @@ -973,9 +1858,14 @@ fn test_parse_simple23() { #[test] fn test_parse_simple24() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "09/25/2003"); } @@ -983,9 +1873,14 @@ fn test_parse_simple24() { #[test] fn test_parse_simple25() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "25/09/2003"); } @@ -993,9 +1888,14 @@ fn test_parse_simple25() { #[test] fn test_parse_simple26() { let pdt = PyDateTime { - year: 2003, month: 10, day: 9, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 10, + day: 9, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "10/09/2003"); } @@ -1003,9 +1903,14 @@ fn test_parse_simple26() { #[test] fn test_parse_simple27() { let pdt = PyDateTime { - year: 2003, month: 10, day: 9, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 10, + day: 9, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "10/09/03"); } @@ -1013,9 +1918,14 @@ fn test_parse_simple27() { #[test] fn test_parse_simple28() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "2003 09 25"); } @@ -1023,9 +1933,14 @@ fn test_parse_simple28() { #[test] fn test_parse_simple29() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "09 25 2003"); } @@ -1033,9 +1948,14 @@ fn test_parse_simple29() { #[test] fn test_parse_simple30() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "25 09 2003"); } @@ -1043,9 +1963,14 @@ fn test_parse_simple30() { #[test] fn test_parse_simple31() { let pdt = PyDateTime { - year: 2003, month: 10, day: 9, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 10, + day: 9, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "10 09 2003"); } @@ -1053,9 +1978,14 @@ fn test_parse_simple31() { #[test] fn test_parse_simple32() { let pdt = PyDateTime { - year: 2003, month: 10, day: 9, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 10, + day: 9, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "10 09 03"); } @@ -1063,9 +1993,14 @@ fn test_parse_simple32() { #[test] fn test_parse_simple33() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "25 09 03"); } @@ -1073,9 +2008,14 @@ fn test_parse_simple33() { #[test] fn test_parse_simple34() { let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "03 25 Sep"); } @@ -1083,9 +2023,14 @@ fn test_parse_simple34() { #[test] fn test_parse_simple35() { let pdt = PyDateTime { - year: 2025, month: 9, day: 3, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2025, + month: 9, + day: 3, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "25 03 Sep"); } @@ -1093,9 +2038,14 @@ fn test_parse_simple35() { #[test] fn test_parse_simple36() { let pdt = PyDateTime { - year: 1976, month: 7, day: 4, - hour: 0, minute: 1, second: 2, - micros: 0, tzo: None, + year: 1976, + month: 7, + day: 4, + hour: 0, + minute: 1, + second: 2, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, " July 4 , 1976 12:01:02 am "); } @@ -1103,9 +2053,14 @@ fn test_parse_simple36() { #[test] fn test_parse_simple37() { let pdt = PyDateTime { - year: 1996, month: 7, day: 10, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 1996, + month: 7, + day: 10, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "Wed, July 10, '96"); } @@ -1113,9 +2068,14 @@ fn test_parse_simple37() { #[test] fn test_parse_simple38() { let pdt = PyDateTime { - year: 1996, month: 7, day: 10, - hour: 12, minute: 8, second: 0, - micros: 0, tzo: None, + year: 1996, + month: 7, + day: 10, + hour: 12, + minute: 8, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "1996.July.10 AD 12:08 PM"); } @@ -1123,9 +2083,14 @@ fn test_parse_simple38() { #[test] fn test_parse_simple39() { let pdt = PyDateTime { - year: 1976, month: 7, day: 4, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 1976, + month: 7, + day: 4, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "July 4, 1976"); } @@ -1133,9 +2098,14 @@ fn test_parse_simple39() { #[test] fn test_parse_simple40() { let pdt = PyDateTime { - year: 1976, month: 7, day: 4, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 1976, + month: 7, + day: 4, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "7 4 1976"); } @@ -1143,9 +2113,14 @@ fn test_parse_simple40() { #[test] fn test_parse_simple41() { let pdt = PyDateTime { - year: 1976, month: 7, day: 4, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 1976, + month: 7, + day: 4, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "4 jul 1976"); } @@ -1153,9 +2128,14 @@ fn test_parse_simple41() { #[test] fn test_parse_simple42() { let pdt = PyDateTime { - year: 1976, month: 7, day: 4, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 1976, + month: 7, + day: 4, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "7-4-76"); } @@ -1163,9 +2143,14 @@ fn test_parse_simple42() { #[test] fn test_parse_simple43() { let pdt = PyDateTime { - year: 1976, month: 7, day: 4, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 1976, + month: 7, + day: 4, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "19760704"); } @@ -1173,9 +2158,14 @@ fn test_parse_simple43() { #[test] fn test_parse_simple44() { let pdt = PyDateTime { - year: 1976, month: 7, day: 4, - hour: 0, minute: 1, second: 2, - micros: 0, tzo: None, + year: 1976, + month: 7, + day: 4, + hour: 0, + minute: 1, + second: 2, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "0:01:02 on July 4, 1976"); } @@ -1183,9 +2173,14 @@ fn test_parse_simple44() { #[test] fn test_parse_simple45() { let pdt = PyDateTime { - year: 1976, month: 7, day: 4, - hour: 0, minute: 1, second: 2, - micros: 0, tzo: None, + year: 1976, + month: 7, + day: 4, + hour: 0, + minute: 1, + second: 2, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "0:01:02 on July 4, 1976"); } @@ -1193,9 +2188,14 @@ fn test_parse_simple45() { #[test] fn test_parse_simple46() { let pdt = PyDateTime { - year: 1976, month: 7, day: 4, - hour: 0, minute: 1, second: 2, - micros: 0, tzo: None, + year: 1976, + month: 7, + day: 4, + hour: 0, + minute: 1, + second: 2, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "July 4, 1976 12:01:02 am"); } @@ -1203,9 +2203,14 @@ fn test_parse_simple46() { #[test] fn test_parse_simple47() { let pdt = PyDateTime { - year: 1995, month: 1, day: 2, - hour: 4, minute: 24, second: 27, - micros: 0, tzo: None, + year: 1995, + month: 1, + day: 2, + hour: 4, + minute: 24, + second: 27, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "Mon Jan 2 04:24:27 1995"); } @@ -1213,9 +2218,14 @@ fn test_parse_simple47() { #[test] fn test_parse_simple48() { let pdt = PyDateTime { - year: 1995, month: 4, day: 4, - hour: 0, minute: 22, second: 0, - micros: 0, tzo: None, + year: 1995, + month: 4, + day: 4, + hour: 0, + minute: 22, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "04.04.95 00:22"); } @@ -1223,9 +2233,14 @@ fn test_parse_simple48() { #[test] fn test_parse_simple49() { let pdt = PyDateTime { - year: 1999, month: 1, day: 1, - hour: 11, minute: 23, second: 34, - micros: 578000, tzo: None, + year: 1999, + month: 1, + day: 1, + hour: 11, + minute: 23, + second: 34, + micros: 578000, + tzo: None, }; parse_and_assert_simple(pdt, "Jan 1 1999 11:23:34.578"); } @@ -1233,9 +2248,14 @@ fn test_parse_simple49() { #[test] fn test_parse_simple50() { let pdt = PyDateTime { - year: 1995, month: 4, day: 4, - hour: 12, minute: 22, second: 12, - micros: 0, tzo: None, + year: 1995, + month: 4, + day: 4, + hour: 12, + minute: 22, + second: 12, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "950404 122212"); } @@ -1243,9 +2263,14 @@ fn test_parse_simple50() { #[test] fn test_parse_simple51() { let pdt = PyDateTime { - year: 2001, month: 5, day: 3, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2001, + month: 5, + day: 3, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "3rd of May 2001"); } @@ -1253,9 +2278,14 @@ fn test_parse_simple51() { #[test] fn test_parse_simple52() { let pdt = PyDateTime { - year: 2001, month: 3, day: 5, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2001, + month: 3, + day: 5, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "5th of March 2001"); } @@ -1263,9 +2293,14 @@ fn test_parse_simple52() { #[test] fn test_parse_simple53() { let pdt = PyDateTime { - year: 2003, month: 5, day: 1, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 5, + day: 1, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "1st of May 2003"); } @@ -1273,9 +2308,14 @@ fn test_parse_simple53() { #[test] fn test_parse_simple54() { let pdt = PyDateTime { - year: 99, month: 1, day: 1, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 99, + month: 1, + day: 1, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "0099-01-01T00:00:00"); } @@ -1283,9 +2323,14 @@ fn test_parse_simple54() { #[test] fn test_parse_simple55() { let pdt = PyDateTime { - year: 31, month: 1, day: 1, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 31, + month: 1, + day: 1, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "0031-01-01T00:00:00"); } @@ -1293,9 +2338,14 @@ fn test_parse_simple55() { #[test] fn test_parse_simple56() { let pdt = PyDateTime { - year: 2008, month: 2, day: 27, - hour: 21, minute: 26, second: 1, - micros: 123456, tzo: None, + year: 2008, + month: 2, + day: 27, + hour: 21, + minute: 26, + second: 1, + micros: 123456, + tzo: None, }; parse_and_assert_simple(pdt, "20080227T21:26:01.123456789"); } @@ -1303,9 +2353,14 @@ fn test_parse_simple56() { #[test] fn test_parse_simple57() { let pdt = PyDateTime { - year: 2017, month: 11, day: 13, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2017, + month: 11, + day: 13, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "13NOV2017"); } @@ -1313,9 +2368,14 @@ fn test_parse_simple57() { #[test] fn test_parse_simple58() { let pdt = PyDateTime { - year: 3, month: 3, day: 4, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 3, + month: 3, + day: 4, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "0003-03-04"); } @@ -1323,9 +2383,14 @@ fn test_parse_simple58() { #[test] fn test_parse_simple59() { let pdt = PyDateTime { - year: 31, month: 12, day: 30, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 31, + month: 12, + day: 30, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "December.0031.30"); } @@ -1333,9 +2398,14 @@ fn test_parse_simple59() { #[test] fn test_parse_simple60() { let pdt = PyDateTime { - year: 2007, month: 9, day: 1, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2007, + month: 9, + day: 1, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "090107"); } @@ -1343,9 +2413,14 @@ fn test_parse_simple60() { #[test] fn test_parse_simple61() { let pdt = PyDateTime { - year: 2015, month: 5, day: 15, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2015, + month: 5, + day: 15, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; parse_and_assert_simple(pdt, "2015-15-May"); } @@ -1354,288 +2429,648 @@ fn test_parse_simple61() { fn test_parse_tzinfo0() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 28, - micros: 0, tzo: Some(-10800), + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 28, + micros: 0, + tzo: Some(-10800), }; - parse_and_assert(pdt, info, "Thu Sep 25 10:36:28 BRST 2003", None, None, false, false, - None, false, &rs_tzinfo_map!()); + parse_and_assert( + pdt, + info, + "Thu Sep 25 10:36:28 BRST 2003", + None, + None, + false, + false, + None, + false, + &rs_tzinfo_map!(), + ); } #[test] fn test_parse_tzinfo1() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 28, - micros: 0, tzo: Some(-10800), + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 28, + micros: 0, + tzo: Some(-10800), }; - parse_and_assert(pdt, info, "2003 10:36:28 BRST 25 Sep Thu", None, None, false, false, - None, false, &rs_tzinfo_map!()); + parse_and_assert( + pdt, + info, + "2003 10:36:28 BRST 25 Sep Thu", + None, + None, + false, + false, + None, + false, + &rs_tzinfo_map!(), + ); } #[test] fn test_parse_offset0() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 49, second: 41, - micros: 0, tzo: Some(-10800), + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 49, + second: 41, + micros: 0, + tzo: Some(-10800), }; - parse_and_assert(pdt, info, "Thu, 25 Sep 2003 10:49:41 -0300", None, None, false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Thu, 25 Sep 2003 10:49:41 -0300", + None, + None, + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_offset1() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 49, second: 41, - micros: 500000, tzo: Some(-10800), + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 49, + second: 41, + micros: 500000, + tzo: Some(-10800), }; - parse_and_assert(pdt, info, "2003-09-25T10:49:41.5-03:00", None, None, false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "2003-09-25T10:49:41.5-03:00", + None, + None, + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_offset2() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 49, second: 41, - micros: 0, tzo: Some(-10800), + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 49, + second: 41, + micros: 0, + tzo: Some(-10800), }; - parse_and_assert(pdt, info, "2003-09-25T10:49:41-03:00", None, None, false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "2003-09-25T10:49:41-03:00", + None, + None, + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_offset3() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 49, second: 41, - micros: 500000, tzo: Some(-10800), + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 49, + second: 41, + micros: 500000, + tzo: Some(-10800), }; - parse_and_assert(pdt, info, "20030925T104941.5-0300", None, None, false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "20030925T104941.5-0300", + None, + None, + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_offset4() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 49, second: 41, - micros: 0, tzo: Some(-10800), + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 49, + second: 41, + micros: 0, + tzo: Some(-10800), }; - parse_and_assert(pdt, info, "20030925T104941-0300", None, None, false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "20030925T104941-0300", + None, + None, + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_offset5() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2018, month: 8, day: 10, - hour: 10, minute: 0, second: 0, - micros: 0, tzo: Some(-10800), + year: 2018, + month: 8, + day: 10, + hour: 10, + minute: 0, + second: 0, + micros: 0, + tzo: Some(-10800), }; - parse_and_assert(pdt, info, "2018-08-10 10:00:00 UTC+3", None, None, false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "2018-08-10 10:00:00 UTC+3", + None, + None, + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_offset6() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2018, month: 8, day: 10, - hour: 15, minute: 36, second: 47, - micros: 0, tzo: Some(14400), + year: 2018, + month: 8, + day: 10, + hour: 15, + minute: 36, + second: 47, + micros: 0, + tzo: Some(14400), }; - parse_and_assert(pdt, info, "2018-08-10 03:36:47 PM GMT-4", None, None, false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "2018-08-10 03:36:47 PM GMT-4", + None, + None, + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_offset7() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2018, month: 8, day: 10, - hour: 4, minute: 15, second: 0, - micros: 0, tzo: Some(7200), + year: 2018, + month: 8, + day: 10, + hour: 4, + minute: 15, + second: 0, + micros: 0, + tzo: Some(7200), }; - parse_and_assert(pdt, info, "2018-08-10 04:15:00 AM Z-02:00", None, None, false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "2018-08-10 04:15:00 AM Z-02:00", + None, + None, + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_dayfirst0() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 9, day: 10, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 10, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10-09-2003", Some(true), None, false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10-09-2003", + Some(true), + None, + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_dayfirst1() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 9, day: 10, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 10, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10.09.2003", Some(true), None, false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10.09.2003", + Some(true), + None, + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_dayfirst2() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 9, day: 10, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 10, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10/09/2003", Some(true), None, false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10/09/2003", + Some(true), + None, + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_dayfirst3() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 9, day: 10, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2003, + month: 9, + day: 10, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10 09 2003", Some(true), None, false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10 09 2003", + Some(true), + None, + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_dayfirst4() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2007, month: 1, day: 9, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2007, + month: 1, + day: 9, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "090107", Some(true), None, false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "090107", + Some(true), + None, + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_dayfirst5() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2015, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2015, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "2015 09 25", Some(true), None, false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "2015 09 25", + Some(true), + None, + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_yearfirst0() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2010, month: 9, day: 3, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2010, + month: 9, + day: 3, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10-09-03", None, Some(true), false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10-09-03", + None, + Some(true), + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_yearfirst1() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2010, month: 9, day: 3, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2010, + month: 9, + day: 3, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10.09.03", None, Some(true), false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10.09.03", + None, + Some(true), + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_yearfirst2() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2010, month: 9, day: 3, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2010, + month: 9, + day: 3, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10/09/03", None, Some(true), false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10/09/03", + None, + Some(true), + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_yearfirst3() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2010, month: 9, day: 3, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2010, + month: 9, + day: 3, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "10 09 03", None, Some(true), false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "10 09 03", + None, + Some(true), + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_yearfirst4() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2009, month: 1, day: 7, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2009, + month: 1, + day: 7, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "090107", None, Some(true), false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "090107", + None, + Some(true), + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_yearfirst5() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2015, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2015, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "2015 09 25", None, Some(true), false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "2015 09 25", + None, + Some(true), + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_dfyf0() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2009, month: 7, day: 1, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2009, + month: 7, + day: 1, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "090107", Some(true), Some(true), false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "090107", + Some(true), + Some(true), + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_parse_dfyf1() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2015, month: 9, day: 25, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None, + year: 2015, + month: 9, + day: 25, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "2015 09 25", Some(true), Some(true), false, false, - None, false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "2015 09 25", + Some(true), + Some(true), + false, + false, + None, + false, + &HashMap::new(), + ); } #[test] @@ -1643,12 +3078,27 @@ fn test_unspecified_fallback0() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2010, 1, 31).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2009, month: 4, day: 30, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None + year: 2009, + month: 4, + day: 30, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "April 2009", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "April 2009", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -1656,12 +3106,27 @@ fn test_unspecified_fallback1() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2010, 1, 31).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2007, month: 2, day: 28, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None + year: 2007, + month: 2, + day: 28, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Feb 2007", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Feb 2007", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] @@ -1669,203 +3134,472 @@ fn test_unspecified_fallback2() { let info = ParserInfo::default(); let default_rsdate = &NaiveDate::from_ymd(2010, 1, 31).and_hms(0, 0, 0); let pdt = PyDateTime { - year: 2008, month: 2, day: 29, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None + year: 2008, + month: 2, + day: 29, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Feb 2008", None, None, false, false, - Some(default_rsdate), false, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Feb 2008", + None, + None, + false, + false, + Some(default_rsdate), + false, + &HashMap::new(), + ); } #[test] fn test_parse_ignoretz0() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 36, second: 28, - micros: 0, tzo: None + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 36, + second: 28, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Thu Sep 25 10:36:28 BRST 2003", None, None, false, false, - None, true, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Thu Sep 25 10:36:28 BRST 2003", + None, + None, + false, + false, + None, + true, + &HashMap::new(), + ); } #[test] fn test_parse_ignoretz1() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 1996, month: 7, day: 10, - hour: 15, minute: 8, second: 56, - micros: 0, tzo: None + year: 1996, + month: 7, + day: 10, + hour: 15, + minute: 8, + second: 56, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "1996.07.10 AD at 15:08:56 PDT", None, None, false, false, - None, true, &HashMap::new()); + parse_and_assert( + pdt, + info, + "1996.07.10 AD at 15:08:56 PDT", + None, + None, + false, + false, + None, + true, + &HashMap::new(), + ); } #[test] fn test_parse_ignoretz2() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 1952, month: 4, day: 12, - hour: 15, minute: 30, second: 42, - micros: 0, tzo: None + year: 1952, + month: 4, + day: 12, + hour: 15, + minute: 30, + second: 42, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Tuesday, April 12, 1952 AD 3:30:42pm PST", None, None, false, false, - None, true, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Tuesday, April 12, 1952 AD 3:30:42pm PST", + None, + None, + false, + false, + None, + true, + &HashMap::new(), + ); } #[test] fn test_parse_ignoretz3() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 1994, month: 11, day: 5, - hour: 8, minute: 15, second: 30, - micros: 0, tzo: None + year: 1994, + month: 11, + day: 5, + hour: 8, + minute: 15, + second: 30, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "November 5, 1994, 8:15:30 am EST", None, None, false, false, - None, true, &HashMap::new()); + parse_and_assert( + pdt, + info, + "November 5, 1994, 8:15:30 am EST", + None, + None, + false, + false, + None, + true, + &HashMap::new(), + ); } #[test] fn test_parse_ignoretz4() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 1994, month: 11, day: 5, - hour: 8, minute: 15, second: 30, - micros: 0, tzo: None + year: 1994, + month: 11, + day: 5, + hour: 8, + minute: 15, + second: 30, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "1994-11-05T08:15:30-05:00", None, None, false, false, - None, true, &HashMap::new()); + parse_and_assert( + pdt, + info, + "1994-11-05T08:15:30-05:00", + None, + None, + false, + false, + None, + true, + &HashMap::new(), + ); } #[test] fn test_parse_ignoretz5() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 1994, month: 11, day: 5, - hour: 8, minute: 15, second: 30, - micros: 0, tzo: None + year: 1994, + month: 11, + day: 5, + hour: 8, + minute: 15, + second: 30, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "1994-11-05T08:15:30Z", None, None, false, false, - None, true, &HashMap::new()); + parse_and_assert( + pdt, + info, + "1994-11-05T08:15:30Z", + None, + None, + false, + false, + None, + true, + &HashMap::new(), + ); } #[test] fn test_parse_ignoretz6() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 1976, month: 7, day: 4, - hour: 0, minute: 1, second: 2, - micros: 0, tzo: None + year: 1976, + month: 7, + day: 4, + hour: 0, + minute: 1, + second: 2, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "1976-07-04T00:01:02Z", None, None, false, false, - None, true, &HashMap::new()); + parse_and_assert( + pdt, + info, + "1976-07-04T00:01:02Z", + None, + None, + false, + false, + None, + true, + &HashMap::new(), + ); } #[test] fn test_parse_ignoretz7() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 1995, month: 4, day: 4, - hour: 0, minute: 22, second: 12, - micros: 0, tzo: None + year: 1995, + month: 4, + day: 4, + hour: 0, + minute: 22, + second: 12, + micros: 0, + tzo: None, }; - parse_and_assert(pdt, info, "Tue Apr 4 00:22:12 PDT 1995", None, None, false, false, - None, true, &HashMap::new()); + parse_and_assert( + pdt, + info, + "Tue Apr 4 00:22:12 PDT 1995", + None, + None, + false, + false, + None, + true, + &HashMap::new(), + ); } #[test] fn test_fuzzy_tzinfo0() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 49, second: 41, - micros: 0, tzo: Some(-10800) + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 49, + second: 41, + micros: 0, + tzo: Some(-10800), }; - parse_fuzzy_and_assert(pdt, None, info, "Today is 25 of September of 2003, exactly at 10:49:41 with timezone -03:00.", None, None, true, false, - None, false, &HashMap::new()); + parse_fuzzy_and_assert( + pdt, + None, + info, + "Today is 25 of September of 2003, exactly at 10:49:41 with timezone -03:00.", + None, + None, + true, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_fuzzy_tokens_tzinfo0() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 9, day: 25, - hour: 10, minute: 49, second: 41, - micros: 0, tzo: Some(-10800) + year: 2003, + month: 9, + day: 25, + hour: 10, + minute: 49, + second: 41, + micros: 0, + tzo: Some(-10800), }; - let tokens = vec!["Today is ".to_owned(), "of ".to_owned(), ", exactly at ".to_owned(), " with timezone ".to_owned(), ".".to_owned()]; - parse_fuzzy_and_assert(pdt, Some(tokens), info, "Today is 25 of September of 2003, exactly at 10:49:41 with timezone -03:00.", None, None, true, true, - None, false, &HashMap::new()); + let tokens = vec![ + "Today is ".to_owned(), + "of ".to_owned(), + ", exactly at ".to_owned(), + " with timezone ".to_owned(), + ".".to_owned(), + ]; + parse_fuzzy_and_assert( + pdt, + Some(tokens), + info, + "Today is 25 of September of 2003, exactly at 10:49:41 with timezone -03:00.", + None, + None, + true, + true, + None, + false, + &HashMap::new(), + ); } #[test] fn test_fuzzy_simple0() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 1974, month: 3, day: 1, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None + year: 1974, + month: 3, + day: 1, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_fuzzy_and_assert(pdt, None, info, "I have a meeting on March 1, 1974", None, None, true, false, - None, false, &HashMap::new()); + parse_fuzzy_and_assert( + pdt, + None, + info, + "I have a meeting on March 1, 1974", + None, + None, + true, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_fuzzy_simple1() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2020, month: 6, day: 8, - hour: 0, minute: 0, second: 0, - micros: 0, tzo: None + year: 2020, + month: 6, + day: 8, + hour: 0, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_fuzzy_and_assert(pdt, None, info, "On June 8th, 2020, I am going to be the first man on Mars", None, None, true, false, - None, false, &HashMap::new()); + parse_fuzzy_and_assert( + pdt, + None, + info, + "On June 8th, 2020, I am going to be the first man on Mars", + None, + None, + true, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_fuzzy_simple2() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 12, day: 3, - hour: 3, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 12, + day: 3, + hour: 3, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_fuzzy_and_assert(pdt, None, info, "Meet me at the AM/PM on Sunset at 3:00 AM on December 3rd, 2003", None, None, true, false, - None, false, &HashMap::new()); + parse_fuzzy_and_assert( + pdt, + None, + info, + "Meet me at the AM/PM on Sunset at 3:00 AM on December 3rd, 2003", + None, + None, + true, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_fuzzy_simple3() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2003, month: 12, day: 3, - hour: 3, minute: 0, second: 0, - micros: 0, tzo: None + year: 2003, + month: 12, + day: 3, + hour: 3, + minute: 0, + second: 0, + micros: 0, + tzo: None, }; - parse_fuzzy_and_assert(pdt, None, info, "Meet me at 3:00 AM on December 3rd, 2003 at the AM/PM on Sunset", None, None, true, false, - None, false, &HashMap::new()); + parse_fuzzy_and_assert( + pdt, + None, + info, + "Meet me at 3:00 AM on December 3rd, 2003 at the AM/PM on Sunset", + None, + None, + true, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_fuzzy_simple4() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 1945, month: 1, day: 29, - hour: 14, minute: 45, second: 0, - micros: 0, tzo: None + year: 1945, + month: 1, + day: 29, + hour: 14, + minute: 45, + second: 0, + micros: 0, + tzo: None, }; - parse_fuzzy_and_assert(pdt, None, info, "Jan 29, 1945 14:45 AM I going to see you there?", None, None, true, false, - None, false, &HashMap::new()); + parse_fuzzy_and_assert( + pdt, + None, + info, + "Jan 29, 1945 14:45 AM I going to see you there?", + None, + None, + true, + false, + None, + false, + &HashMap::new(), + ); } #[test] fn test_fuzzy_simple5() { let info = ParserInfo::default(); let pdt = PyDateTime { - year: 2017, month: 7, day: 17, - hour: 6, minute: 15, second: 0, - micros: 0, tzo: None + year: 2017, + month: 7, + day: 17, + hour: 6, + minute: 15, + second: 0, + micros: 0, + tzo: None, }; - parse_fuzzy_and_assert(pdt, None, info, "2017-07-17 06:15:", None, None, true, false, - None, false, &HashMap::new()); + parse_fuzzy_and_assert( + pdt, + None, + info, + "2017-07-17 06:15:", + None, + None, + true, + false, + None, + false, + &HashMap::new(), + ); } diff --git a/src/tests/pycompat_tokenizer.rs b/src/tests/pycompat_tokenizer.rs index 9cbbf21..a9ccdbf 100644 --- a/src/tests/pycompat_tokenizer.rs +++ b/src/tests/pycompat_tokenizer.rs @@ -1,4 +1,3 @@ - //! This code has been generated by running the `build_pycompat_tokenizer.py` script //! in the repository root. Please do not edit it, as your edits will be destroyed //! upon re-running code generation. @@ -12,7 +11,9 @@ fn tokenize_assert(test_str: &str, comparison: Vec<&str>) { #[test] fn test_tokenize0() { - let comp = vec!["Thu", " ", "Sep", " ", "25", " ", "10", ":", "36", ":", "28"]; + let comp = vec![ + "Thu", " ", "Sep", " ", "25", " ", "10", ":", "36", ":", "28", + ]; tokenize_assert("Thu Sep 25 10:36:28", comp); } @@ -294,7 +295,9 @@ fn test_tokenize46() { #[test] fn test_tokenize47() { - let comp = vec!["Thu", " ", "Sep", " ", "25", " ", "10", ":", "36", ":", "28", " ", "2003"]; + let comp = vec![ + "Thu", " ", "Sep", " ", "25", " ", "10", ":", "36", ":", "28", " ", "2003", + ]; tokenize_assert("Thu Sep 25 10:36:28 2003", comp); } @@ -306,7 +309,9 @@ fn test_tokenize48() { #[test] fn test_tokenize49() { - let comp = vec!["2003", "-", "09", "-", "25", "T", "10", ":", "49", ":", "41"]; + let comp = vec![ + "2003", "-", "09", "-", "25", "T", "10", ":", "49", ":", "41", + ]; tokenize_assert("2003-09-25T10:49:41", comp); } @@ -354,7 +359,9 @@ fn test_tokenize56() { #[test] fn test_tokenize57() { - let comp = vec!["2003", "-", "09", "-", "25", " ", "10", ":", "49", ":", "41.502"]; + let comp = vec![ + "2003", "-", "09", "-", "25", " ", "10", ":", "49", ":", "41.502", + ]; tokenize_assert("2003-09-25 10:49:41,502", comp); } @@ -510,7 +517,10 @@ fn test_tokenize82() { #[test] fn test_tokenize83() { - let comp = vec![" ", " ", "July", " ", " ", " ", "4", " ", ",", " ", " ", "1976", " ", " ", " ", "12", ":", "01", ":", "02", " ", " ", " ", "am", " ", " "]; + let comp = vec![ + " ", " ", "July", " ", " ", " ", "4", " ", ",", " ", " ", "1976", " ", " ", " ", "12", ":", + "01", ":", "02", " ", " ", " ", "am", " ", " ", + ]; tokenize_assert(" July 4 , 1976 12:01:02 am ", comp); } @@ -522,7 +532,9 @@ fn test_tokenize84() { #[test] fn test_tokenize85() { - let comp = vec!["1996", ".", "July", ".", "10", " ", "AD", " ", "12", ":", "08", " ", "PM"]; + let comp = vec![ + "1996", ".", "July", ".", "10", " ", "AD", " ", "12", ":", "08", " ", "PM", + ]; tokenize_assert("1996.July.10 AD 12:08 PM", comp); } @@ -558,25 +570,33 @@ fn test_tokenize90() { #[test] fn test_tokenize91() { - let comp = vec!["0", ":", "01", ":", "02", " ", "on", " ", "July", " ", "4", ",", " ", "1976"]; + let comp = vec![ + "0", ":", "01", ":", "02", " ", "on", " ", "July", " ", "4", ",", " ", "1976", + ]; tokenize_assert("0:01:02 on July 4, 1976", comp); } #[test] fn test_tokenize92() { - let comp = vec!["0", ":", "01", ":", "02", " ", "on", " ", "July", " ", "4", ",", " ", "1976"]; + let comp = vec![ + "0", ":", "01", ":", "02", " ", "on", " ", "July", " ", "4", ",", " ", "1976", + ]; tokenize_assert("0:01:02 on July 4, 1976", comp); } #[test] fn test_tokenize93() { - let comp = vec!["July", " ", "4", ",", " ", "1976", " ", "12", ":", "01", ":", "02", " ", "am"]; + let comp = vec![ + "July", " ", "4", ",", " ", "1976", " ", "12", ":", "01", ":", "02", " ", "am", + ]; tokenize_assert("July 4, 1976 12:01:02 am", comp); } #[test] fn test_tokenize94() { - let comp = vec!["Mon", " ", "Jan", " ", " ", "2", " ", "04", ":", "24", ":", "27", " ", "1995"]; + let comp = vec![ + "Mon", " ", "Jan", " ", " ", "2", " ", "04", ":", "24", ":", "27", " ", "1995", + ]; tokenize_assert("Mon Jan 2 04:24:27 1995", comp); } @@ -588,7 +608,9 @@ fn test_tokenize95() { #[test] fn test_tokenize96() { - let comp = vec!["Jan", " ", "1", " ", "1999", " ", "11", ":", "23", ":", "34.578"]; + let comp = vec![ + "Jan", " ", "1", " ", "1999", " ", "11", ":", "23", ":", "34.578", + ]; tokenize_assert("Jan 1 1999 11:23:34.578", comp); } @@ -618,13 +640,17 @@ fn test_tokenize100() { #[test] fn test_tokenize101() { - let comp = vec!["0099", "-", "01", "-", "01", "T", "00", ":", "00", ":", "00"]; + let comp = vec![ + "0099", "-", "01", "-", "01", "T", "00", ":", "00", ":", "00", + ]; tokenize_assert("0099-01-01T00:00:00", comp); } #[test] fn test_tokenize102() { - let comp = vec!["0031", "-", "01", "-", "01", "T", "00", ":", "00", ":", "00"]; + let comp = vec![ + "0031", "-", "01", "-", "01", "T", "00", ":", "00", ":", "00", + ]; tokenize_assert("0031-01-01T00:00:00", comp); } @@ -666,31 +692,42 @@ fn test_tokenize108() { #[test] fn test_tokenize109() { - let comp = vec!["Thu", " ", "Sep", " ", "25", " ", "10", ":", "36", ":", "28", " ", "BRST", " ", "2003"]; + let comp = vec![ + "Thu", " ", "Sep", " ", "25", " ", "10", ":", "36", ":", "28", " ", "BRST", " ", "2003", + ]; tokenize_assert("Thu Sep 25 10:36:28 BRST 2003", comp); } #[test] fn test_tokenize110() { - let comp = vec!["2003", " ", "10", ":", "36", ":", "28", " ", "BRST", " ", "25", " ", "Sep", " ", "Thu"]; + let comp = vec![ + "2003", " ", "10", ":", "36", ":", "28", " ", "BRST", " ", "25", " ", "Sep", " ", "Thu", + ]; tokenize_assert("2003 10:36:28 BRST 25 Sep Thu", comp); } #[test] fn test_tokenize111() { - let comp = vec!["Thu", ",", " ", "25", " ", "Sep", " ", "2003", " ", "10", ":", "49", ":", "41", " ", "-", "0300"]; + let comp = vec![ + "Thu", ",", " ", "25", " ", "Sep", " ", "2003", " ", "10", ":", "49", ":", "41", " ", "-", + "0300", + ]; tokenize_assert("Thu, 25 Sep 2003 10:49:41 -0300", comp); } #[test] fn test_tokenize112() { - let comp = vec!["2003", "-", "09", "-", "25", "T", "10", ":", "49", ":", "41.5", "-", "03", ":", "00"]; + let comp = vec![ + "2003", "-", "09", "-", "25", "T", "10", ":", "49", ":", "41.5", "-", "03", ":", "00", + ]; tokenize_assert("2003-09-25T10:49:41.5-03:00", comp); } #[test] fn test_tokenize113() { - let comp = vec!["2003", "-", "09", "-", "25", "T", "10", ":", "49", ":", "41", "-", "03", ":", "00"]; + let comp = vec![ + "2003", "-", "09", "-", "25", "T", "10", ":", "49", ":", "41", "-", "03", ":", "00", + ]; tokenize_assert("2003-09-25T10:49:41-03:00", comp); } @@ -708,19 +745,27 @@ fn test_tokenize115() { #[test] fn test_tokenize116() { - let comp = vec!["2018", "-", "08", "-", "10", " ", "10", ":", "00", ":", "00", " ", "UTC", "+", "3"]; + let comp = vec![ + "2018", "-", "08", "-", "10", " ", "10", ":", "00", ":", "00", " ", "UTC", "+", "3", + ]; tokenize_assert("2018-08-10 10:00:00 UTC+3", comp); } #[test] fn test_tokenize117() { - let comp = vec!["2018", "-", "08", "-", "10", " ", "03", ":", "36", ":", "47", " ", "PM", " ", "GMT", "-", "4"]; + let comp = vec![ + "2018", "-", "08", "-", "10", " ", "03", ":", "36", ":", "47", " ", "PM", " ", "GMT", "-", + "4", + ]; tokenize_assert("2018-08-10 03:36:47 PM GMT-4", comp); } #[test] fn test_tokenize118() { - let comp = vec!["2018", "-", "08", "-", "10", " ", "04", ":", "15", ":", "00", " ", "AM", " ", "Z", "-", "02", ":", "00"]; + let comp = vec![ + "2018", "-", "08", "-", "10", " ", "04", ":", "15", ":", "00", " ", "AM", " ", "Z", "-", + "02", ":", "00", + ]; tokenize_assert("2018-08-10 04:15:00 AM Z-02:00", comp); } @@ -828,91 +873,213 @@ fn test_tokenize135() { #[test] fn test_tokenize136() { - let comp = vec!["Thu", " ", "Sep", " ", "25", " ", "10", ":", "36", ":", "28", " ", "BRST", " ", "2003"]; + let comp = vec![ + "Thu", " ", "Sep", " ", "25", " ", "10", ":", "36", ":", "28", " ", "BRST", " ", "2003", + ]; tokenize_assert("Thu Sep 25 10:36:28 BRST 2003", comp); } #[test] fn test_tokenize137() { - let comp = vec!["1996", ".", "07", ".", "10", " ", "AD", " ", "at", " ", "15", ":", "08", ":", "56", " ", "PDT"]; + let comp = vec![ + "1996", ".", "07", ".", "10", " ", "AD", " ", "at", " ", "15", ":", "08", ":", "56", " ", + "PDT", + ]; tokenize_assert("1996.07.10 AD at 15:08:56 PDT", comp); } #[test] fn test_tokenize138() { - let comp = vec!["Tuesday", ",", " ", "April", " ", "12", ",", " ", "1952", " ", "AD", " ", "3", ":", "30", ":", "42", "pm", " ", "PST"]; + let comp = vec![ + "Tuesday", ",", " ", "April", " ", "12", ",", " ", "1952", " ", "AD", " ", "3", ":", "30", + ":", "42", "pm", " ", "PST", + ]; tokenize_assert("Tuesday, April 12, 1952 AD 3:30:42pm PST", comp); } #[test] fn test_tokenize139() { - let comp = vec!["November", " ", "5", ",", " ", "1994", ",", " ", "8", ":", "15", ":", "30", " ", "am", " ", "EST"]; + let comp = vec![ + "November", " ", "5", ",", " ", "1994", ",", " ", "8", ":", "15", ":", "30", " ", "am", + " ", "EST", + ]; tokenize_assert("November 5, 1994, 8:15:30 am EST", comp); } #[test] fn test_tokenize140() { - let comp = vec!["1994", "-", "11", "-", "05", "T", "08", ":", "15", ":", "30", "-", "05", ":", "00"]; + let comp = vec![ + "1994", "-", "11", "-", "05", "T", "08", ":", "15", ":", "30", "-", "05", ":", "00", + ]; tokenize_assert("1994-11-05T08:15:30-05:00", comp); } #[test] fn test_tokenize141() { - let comp = vec!["1994", "-", "11", "-", "05", "T", "08", ":", "15", ":", "30", "Z"]; + let comp = vec![ + "1994", "-", "11", "-", "05", "T", "08", ":", "15", ":", "30", "Z", + ]; tokenize_assert("1994-11-05T08:15:30Z", comp); } #[test] fn test_tokenize142() { - let comp = vec!["1976", "-", "07", "-", "04", "T", "00", ":", "01", ":", "02", "Z"]; + let comp = vec![ + "1976", "-", "07", "-", "04", "T", "00", ":", "01", ":", "02", "Z", + ]; tokenize_assert("1976-07-04T00:01:02Z", comp); } #[test] fn test_tokenize143() { - let comp = vec!["Tue", " ", "Apr", " ", "4", " ", "00", ":", "22", ":", "12", " ", "PDT", " ", "1995"]; + let comp = vec![ + "Tue", " ", "Apr", " ", "4", " ", "00", ":", "22", ":", "12", " ", "PDT", " ", "1995", + ]; tokenize_assert("Tue Apr 4 00:22:12 PDT 1995", comp); } #[test] fn test_tokenize144() { - let comp = vec!["Today", " ", "is", " ", "25", " ", "of", " ", "September", " ", "of", " ", "2003", ",", " ", "exactly", " ", "at", " ", "10", ":", "49", ":", "41", " ", "with", " ", "timezone", " ", "-", "03", ":", "00", "."]; - tokenize_assert("Today is 25 of September of 2003, exactly at 10:49:41 with timezone -03:00.", comp); + let comp = vec![ + "Today", + " ", + "is", + " ", + "25", + " ", + "of", + " ", + "September", + " ", + "of", + " ", + "2003", + ",", + " ", + "exactly", + " ", + "at", + " ", + "10", + ":", + "49", + ":", + "41", + " ", + "with", + " ", + "timezone", + " ", + "-", + "03", + ":", + "00", + ".", + ]; + tokenize_assert( + "Today is 25 of September of 2003, exactly at 10:49:41 with timezone -03:00.", + comp, + ); } #[test] fn test_tokenize145() { - let comp = vec!["Today", " ", "is", " ", "25", " ", "of", " ", "September", " ", "of", " ", "2003", ",", " ", "exactly", " ", "at", " ", "10", ":", "49", ":", "41", " ", "with", " ", "timezone", " ", "-", "03", ":", "00", "."]; - tokenize_assert("Today is 25 of September of 2003, exactly at 10:49:41 with timezone -03:00.", comp); + let comp = vec![ + "Today", + " ", + "is", + " ", + "25", + " ", + "of", + " ", + "September", + " ", + "of", + " ", + "2003", + ",", + " ", + "exactly", + " ", + "at", + " ", + "10", + ":", + "49", + ":", + "41", + " ", + "with", + " ", + "timezone", + " ", + "-", + "03", + ":", + "00", + ".", + ]; + tokenize_assert( + "Today is 25 of September of 2003, exactly at 10:49:41 with timezone -03:00.", + comp, + ); } #[test] fn test_tokenize146() { - let comp = vec!["I", " ", "have", " ", "a", " ", "meeting", " ", "on", " ", "March", " ", "1", ",", " ", "1974"]; + let comp = vec![ + "I", " ", "have", " ", "a", " ", "meeting", " ", "on", " ", "March", " ", "1", ",", " ", + "1974", + ]; tokenize_assert("I have a meeting on March 1, 1974", comp); } #[test] fn test_tokenize147() { - let comp = vec!["On", " ", "June", " ", "8", "th", ",", " ", "2020", ",", " ", "I", " ", "am", " ", "going", " ", "to", " ", "be", " ", "the", " ", "first", " ", "man", " ", "on", " ", "Mars"]; - tokenize_assert("On June 8th, 2020, I am going to be the first man on Mars", comp); + let comp = vec![ + "On", " ", "June", " ", "8", "th", ",", " ", "2020", ",", " ", "I", " ", "am", " ", + "going", " ", "to", " ", "be", " ", "the", " ", "first", " ", "man", " ", "on", " ", + "Mars", + ]; + tokenize_assert( + "On June 8th, 2020, I am going to be the first man on Mars", + comp, + ); } #[test] fn test_tokenize148() { - let comp = vec!["Meet", " ", "me", " ", "at", " ", "the", " ", "AM", "/", "PM", " ", "on", " ", "Sunset", " ", "at", " ", "3", ":", "00", " ", "AM", " ", "on", " ", "December", " ", "3", "rd", ",", " ", "2003"]; - tokenize_assert("Meet me at the AM/PM on Sunset at 3:00 AM on December 3rd, 2003", comp); + let comp = vec![ + "Meet", " ", "me", " ", "at", " ", "the", " ", "AM", "/", "PM", " ", "on", " ", "Sunset", + " ", "at", " ", "3", ":", "00", " ", "AM", " ", "on", " ", "December", " ", "3", "rd", ",", + " ", "2003", + ]; + tokenize_assert( + "Meet me at the AM/PM on Sunset at 3:00 AM on December 3rd, 2003", + comp, + ); } #[test] fn test_tokenize149() { - let comp = vec!["Meet", " ", "me", " ", "at", " ", "3", ":", "00", " ", "AM", " ", "on", " ", "December", " ", "3", "rd", ",", " ", "2003", " ", "at", " ", "the", " ", "AM", "/", "PM", " ", "on", " ", "Sunset"]; - tokenize_assert("Meet me at 3:00 AM on December 3rd, 2003 at the AM/PM on Sunset", comp); + let comp = vec![ + "Meet", " ", "me", " ", "at", " ", "3", ":", "00", " ", "AM", " ", "on", " ", "December", + " ", "3", "rd", ",", " ", "2003", " ", "at", " ", "the", " ", "AM", "/", "PM", " ", "on", + " ", "Sunset", + ]; + tokenize_assert( + "Meet me at 3:00 AM on December 3rd, 2003 at the AM/PM on Sunset", + comp, + ); } #[test] fn test_tokenize150() { - let comp = vec!["Jan", " ", "29", ",", " ", "1945", " ", "14", ":", "45", " ", "AM", " ", "I", " ", "going", " ", "to", " ", "see", " ", "you", " ", "there", "?"]; + let comp = vec![ + "Jan", " ", "29", ",", " ", "1945", " ", "14", ":", "45", " ", "AM", " ", "I", " ", + "going", " ", "to", " ", "see", " ", "you", " ", "there", "?", + ]; tokenize_assert("Jan 29, 1945 14:45 AM I going to see you there?", comp); } diff --git a/src/tokenize.rs b/src/tokenize.rs index 81cc512..6b39e29 100644 --- a/src/tokenize.rs +++ b/src/tokenize.rs @@ -14,7 +14,6 @@ pub(crate) enum ParseState { } impl Tokenizer { - pub(crate) fn new(parse_string: &str) -> Self { Tokenizer { token_stack: vec![], @@ -92,7 +91,7 @@ impl Iterator for Tokenizer { } else { break; } - }, + } ParseState::Alpha => { seenletters = true; if self.isword(nextchar) { @@ -105,19 +104,21 @@ impl Iterator for Tokenizer { self.parse_string.push(nextchar); break; } - }, + } ParseState::Numeric => { if self.isnum(nextchar) { // UNWRAP: Because we're in non-empty parse state, we're guaranteed to have a token token.as_mut().unwrap().push(nextchar); - } else if nextchar == '.' || (nextchar == ',' && token.as_ref().unwrap().len() >= 2) { + } else if nextchar == '.' + || (nextchar == ',' && token.as_ref().unwrap().len() >= 2) + { token.as_mut().unwrap().push(nextchar); state = ParseState::NumericDecimal; } else { self.parse_string.push(nextchar); break; } - }, + } ParseState::AlphaDecimal => { seenletters = true; if nextchar == '.' || self.isword(nextchar) { @@ -130,7 +131,7 @@ impl Iterator for Tokenizer { self.parse_string.push(nextchar); break; } - }, + } ParseState::NumericDecimal => { if nextchar == '.' || self.isnum(nextchar) { // UNWRAP: Because we're in non-empty parse state, we're guaranteed to have a token @@ -150,20 +151,25 @@ impl Iterator for Tokenizer { // We do something slightly different to express the same logic if state == ParseState::AlphaDecimal || state == ParseState::NumericDecimal { // UNWRAP: The state check guarantees that we have a value - let dot_count = token.as_ref().unwrap().chars().filter(|c| *c == '.').count(); + let dot_count = token + .as_ref() + .unwrap() + .chars() + .filter(|c| *c == '.') + .count(); let last_char = token.as_ref().unwrap().chars().last(); let last_splittable = last_char == Some('.') || last_char == Some(','); - + if seenletters || dot_count > 1 || last_splittable { let mut l = self.decimal_split(token.as_ref().unwrap()); let remaining = l.split_off(1); - + token = Some(l[0].clone()); for t in remaining { self.token_stack.push(t); } } - + if state == ParseState::NumericDecimal && dot_count == 0 { token = Some(token.unwrap().replace(',', ".")); } diff --git a/src/weekday.rs b/src/weekday.rs index 6a2e436..9cd81f9 100644 --- a/src/weekday.rs +++ b/src/weekday.rs @@ -1,5 +1,5 @@ -use ParseResult; use ParseError; +use ParseResult; #[derive(Debug, PartialEq)] pub enum DayOfWeek { @@ -9,11 +9,10 @@ pub enum DayOfWeek { Wednesday, Thursday, Friday, - Saturday + Saturday, } impl DayOfWeek { - pub fn to_numeral(&self) -> u32 { match *self { DayOfWeek::Sunday => 0, @@ -35,7 +34,7 @@ impl DayOfWeek { 4 => DayOfWeek::Thursday, 5 => DayOfWeek::Friday, 6 => DayOfWeek::Saturday, - _ => panic!("Unreachable.") + _ => panic!("Unreachable."), } } @@ -59,12 +58,12 @@ pub fn day_of_week(year: u32, month: u32, day: u32) -> ParseResult { 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 => { let c = year / 100; (c, year - 100 * c) - }, + } 1 | 2 => { let c = (year - 1) / 100; (c, year - 1 - 100 * c) - }, - _ => return Err(ParseError::ImpossibleTimestamp("Invalid month")) + } + _ => return Err(ParseError::ImpossibleTimestamp("Invalid month")), }; let e = match month { @@ -75,7 +74,7 @@ pub fn day_of_week(year: u32, month: u32, day: u32) -> ParseResult { 8 => 1, 9 | 12 => 4, 10 => 6, - _ => panic!("Unreachable.") + _ => panic!("Unreachable."), }; // This implementation is Gregorian-only. @@ -84,7 +83,7 @@ pub fn day_of_week(year: u32, month: u32, day: u32) -> ParseResult { 1 => 5, 2 => 3, 3 => 1, - _ => panic!("Unreachable.") + _ => panic!("Unreachable."), }; match (day + e + f + g + g / 4) % 7 { @@ -95,7 +94,7 @@ pub fn day_of_week(year: u32, month: u32, day: u32) -> ParseResult { 4 => Ok(DayOfWeek::Thursday), 5 => Ok(DayOfWeek::Friday), 6 => Ok(DayOfWeek::Saturday), - _ => panic!("Unreachable.") + _ => panic!("Unreachable."), } } @@ -114,7 +113,6 @@ mod test { #[test] fn weekday_difference() { - assert_eq!(DayOfWeek::Sunday.difference(&DayOfWeek::Sunday), 0); assert_eq!(DayOfWeek::Sunday.difference(&DayOfWeek::Monday), 1); assert_eq!(DayOfWeek::Sunday.difference(&DayOfWeek::Tuesday), 2); @@ -129,4 +127,4 @@ mod test { assert_eq!(DayOfWeek::Friday.difference(&DayOfWeek::Sunday), 2); assert_eq!(DayOfWeek::Saturday.difference(&DayOfWeek::Sunday), 1); } -} \ No newline at end of file +} From b81a8d954163b8610b4957531c742244bfc9e3aa Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Mon, 25 Nov 2019 20:57:56 -0500 Subject: [PATCH 3/4] Use 1.28 as minimum Rust version --- .travis.yml | 14 +------------- README.md | 2 +- src/lib.rs | 2 +- src/tests/tz.rs | 2 +- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index b08828f..14e0e35 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,19 +78,7 @@ matrix: # Historical Rust versions - env: TARGET=x86_64-unknown-linux-gnu - rust: 1.21.0 - - env: TARGET=x86_64-unknown-linux-gnu - rust: 1.22.0 - - env: TARGET=x86_64-unknown-linux-gnu - rust: 1.23.0 - - env: TARGET=x86_64-unknown-linux-gnu - rust: 1.24.0 - - env: TARGET=x86_64-unknown-linux-gnu - rust: 1.25.0 - - env: TARGET=x86_64-unknown-linux-gnu - rust: 1.26.0 - - env: TARGET=x86_64-unknown-linux-gnu - rust: 1.27.0 + rust: 1.28.0 # WASM support - env: TARGET=asmjs-unknown-emscripten USE_CARGO_WEB=true diff --git a/README.md b/README.md index 7d0762d..771ba1a 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Further examples can be found in the [examples](examples) directory on internati # Usage -`dtparse` requires a minimum Rust version of 1.21 to build, but is tested on Windows, OSX, +`dtparse` requires a minimum Rust version of 1.28 to build, but is tested on Windows, OSX, BSD, Linux, and WASM. The build is also compiled against the iOS and Android SDK's, but is not tested against them. diff --git a/src/lib.rs b/src/lib.rs index 04e84e2..3e8af54 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -63,7 +63,7 @@ //! //! # Usage //! -//! `dtparse` requires a minimum Rust version of 1.21 to build, but is tested on Windows, OSX, +//! `dtparse` requires a minimum Rust version of 1.28 to build, but is tested on Windows, OSX, //! BSD, Linux, and WASM. The build is also compiled against the iOS and Android SDK's, but is not //! tested against them. //! diff --git a/src/tests/tz.rs b/src/tests/tz.rs index 8e866f3..f71f1ee 100644 --- a/src/tests/tz.rs +++ b/src/tests/tz.rs @@ -1,4 +1,4 @@ -use crate::parse; +use parse; #[test] fn est() { From 0f7ac8538c6d7d95d90f71d9361fd81f5401df0a Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Mon, 25 Nov 2019 23:11:19 -0500 Subject: [PATCH 4/4] Remove WASM from Travis --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 14e0e35..0a50bdf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -80,11 +80,6 @@ matrix: - env: TARGET=x86_64-unknown-linux-gnu rust: 1.28.0 - # WASM support - - env: TARGET=asmjs-unknown-emscripten USE_CARGO_WEB=true - rust: nightly - - before_install: - set -e - rustup self update