Skip to content

Commit

Permalink
Fix: Added support casting strings without time to timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelwjl committed Jan 9, 2023
1 parent 97bacd4 commit 78ead8b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions arrow-cast/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ pub fn string_to_timestamp_nanos(s: &str) -> Result<i64, ArrowError> {

// without a timezone specifier as a local time, only date
// Example: 2020-09-08
if let Ok(ts) = NaiveDateTime::parse_from_str(s, "%Y-%m-%d") {
if let Ok(ts) =
NaiveDateTime::parse_from_str(&format!("{} 00:00:00", s), "%Y-%m-%d %H:%M:%S")
{
return Ok(ts.timestamp_nanos());
}

Expand Down Expand Up @@ -506,7 +508,7 @@ mod tests {
// 2020-09-08 0:0:0
let naive_datetime_no_time = NaiveDateTime::new(
NaiveDate::from_ymd_opt(2020, 9, 8).unwrap(),
NaiveTime::from_hms_opt(0, 0, 0).unwrap()
NaiveTime::from_hms_opt(0, 0, 0).unwrap(),
);

assert_eq!(
Expand Down

0 comments on commit 78ead8b

Please sign in to comment.