Skip to content

Commit

Permalink
truncate timestamp to second in date_trunc_single
Browse files Browse the repository at this point in the history
  • Loading branch information
Weijun-H authored and alamb committed Jun 27, 2023
1 parent 3071716 commit d68ae79
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions datafusion/physical-expr/src/datetime_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,7 @@ fn quarter_month(date: &NaiveDateTime) -> u32 {
}

fn date_trunc_single(granularity: &str, value: i64) -> Result<i64> {
if granularity == "second"
|| granularity == "millisecond"
|| granularity == "microsecond"
{
if granularity == "millisecond" || granularity == "microsecond" {
return Ok(value);
}

Expand All @@ -228,6 +225,7 @@ fn date_trunc_single(granularity: &str, value: i64) -> Result<i64> {
})?
.with_nanosecond(0);
let value = match granularity {
"second" => value,
"minute" => value.and_then(|d| d.with_second(0)),
"hour" => value
.and_then(|d| d.with_second(0))
Expand Down Expand Up @@ -914,7 +912,7 @@ mod tests {
(
"2020-09-08T13:42:29.190855Z",
"second",
"2020-09-08T13:42:29.190855Z",
"2020-09-08T13:42:29.000000Z",
),
(
"2020-09-08T13:42:29.190855Z",
Expand Down

0 comments on commit d68ae79

Please sign in to comment.