Remove <datetime> / <duration> functionality in favour of time::floor function

Closes #1213
This commit is contained in:
Tobie Morgan Hitchcock 2022-09-24 11:17:47 +01:00
parent d141605266
commit 25926cba83
2 changed files with 3 additions and 37 deletions

View file

@ -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<Datetime> for Duration {
}
}
impl ops::Div<Datetime> 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<Self> for Duration {
fn sum<I>(iter: I) -> Duration
where

View file

@ -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),
}
}
}