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
21 changes: 19 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ pub fn parse_datetime_at_date<S: AsRef<str> + Clone>(
}
}

let ts = s.as_ref().to_owned() + "0000";
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] {
let f = fmt.to_owned() + "%H%M";
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) {
return Ok(dt);
Expand Down Expand Up @@ -327,6 +327,23 @@ mod tests {
}
}

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

#[test]
fn single_digit_month_day() {
let x = Local.with_ymd_and_hms(1987, 5, 7, 0, 0, 0).unwrap();
let expected = DateTime::fixed_offset(&x);

assert_eq!(Ok(expected), parse_datetime("1987-05-07"));
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"));
}
}

#[cfg(test)]
mod offsets {
use chrono::Local;
Expand Down