Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ impl From<RegexError> for ParseDateTimeError {
mod format {
pub const ISO_8601: &str = "%Y-%m-%d";
pub const ISO_8601_NO_SEP: &str = "%Y%m%d";
// US format for calendar date items:
// https://www.gnu.org/software/coreutils/manual/html_node/Calendar-date-items.html
pub const MMDDYYYY_SLASH: &str = "%m/%d/%Y";
pub const MMDDYY_SLASH: &str = "%m/%d/%y";
pub const POSIX_LOCALE: &str = "%a %b %e %H:%M:%S %Y";
pub const YYYYMMDDHHMM_DOT_SS: &str = "%Y%m%d%H%M.%S";
pub const YYYYMMDDHHMMSS: &str = "%Y-%m-%d %H:%M:%S.%f";
Expand Down Expand Up @@ -208,7 +212,12 @@ pub fn parse_datetime_at_date<S: AsRef<str> + Clone>(

let ts = s.as_ref().to_owned() + " 0000";
// Parse date only formats - assume midnight local timezone
for fmt in [format::ISO_8601, format::ISO_8601_NO_SEP] {
for fmt in [
format::ISO_8601,
format::ISO_8601_NO_SEP,
format::MMDDYYYY_SLASH,
format::MMDDYY_SLASH,
] {
let f = fmt.to_owned() + " %H%M";
if let Ok(parsed) = NaiveDateTime::parse_from_str(&ts, &f) {
if let Ok(dt) = naive_dt_to_fixed_offset(date, parsed) {
Expand Down Expand Up @@ -339,7 +348,7 @@ mod tests {
}

#[cfg(test)]
mod formats {
mod calendar_date_items {
use crate::parse_datetime;
use chrono::{DateTime, Local, TimeZone};

Expand All @@ -352,6 +361,10 @@ mod tests {
assert_eq!(Ok(expected), parse_datetime("1987-5-07"));
assert_eq!(Ok(expected), parse_datetime("1987-05-7"));
assert_eq!(Ok(expected), parse_datetime("1987-5-7"));
assert_eq!(Ok(expected), parse_datetime("5/7/1987"));
assert_eq!(Ok(expected), parse_datetime("5/07/1987"));
assert_eq!(Ok(expected), parse_datetime("05/7/1987"));
assert_eq!(Ok(expected), parse_datetime("05/07/1987"));
}
}

Expand Down
Loading