From 25926cba836699bce894145ce9512610ed2498c7 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 24 Sep 2022 11:17:47 +0100 Subject: [PATCH] Remove / functionality in favour of time::floor function Closes #1213 --- lib/src/sql/duration.rs | 14 -------------- lib/src/sql/value/value.rs | 26 +++----------------------- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/lib/src/sql/duration.rs b/lib/src/sql/duration.rs index 807e2203..88a430e0 100644 --- a/lib/src/sql/duration.rs +++ b/lib/src/sql/duration.rs @@ -3,7 +3,6 @@ use crate::sql::datetime::Datetime; use crate::sql::error::IResult; use crate::sql::serde::is_internal_serialization; use crate::sql::value::Value; -use chrono::DurationRound; use nom::branch::alt; use nom::bytes::complete::tag; use nom::multi::many1; @@ -204,19 +203,6 @@ impl ops::Sub for Duration { } } -impl ops::Div for Duration { - type Output = Datetime; - fn div(self, other: Datetime) -> Datetime { - match chrono::Duration::from_std(self.0) { - Ok(d) => match other.duration_trunc(d) { - Ok(v) => Datetime::from(v), - Err(_) => Datetime::default(), - }, - Err(_) => Datetime::default(), - } - } -} - impl Sum for Duration { fn sum(iter: I) -> Duration where diff --git a/lib/src/sql/value/value.rs b/lib/src/sql/value/value.rs index a3dd0438..65b51a6a 100644 --- a/lib/src/sql/value/value.rs +++ b/lib/src/sql/value/value.rs @@ -1229,29 +1229,9 @@ impl ops::Mul for Value { impl ops::Div for Value { type Output = Self; fn div(self, other: Self) -> Self { - match (self, other) { - (Value::Number(v), Value::Number(w)) => { - if w == Number::Int(0) { - Value::None - } else { - Value::Number(v / w) - } - } - (Value::Datetime(v), Value::Duration(w)) => { - if w.is_zero() { - Value::None - } else { - Value::Datetime(w / v) - } - } - (v, w) => { - let w = w.as_number(); - if w == Number::Int(0) { - Value::None - } else { - Value::from(v.as_number() / w) - } - } + match (self.as_number(), other.as_number()) { + (_, w) if w == Number::Int(0) => Value::None, + (v, w) => Value::Number(v / w), } } }