parent
59dcc44883
commit
dcc28a6ec7
3 changed files with 37 additions and 1 deletions
|
@ -235,6 +235,30 @@ impl Number {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_negative(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Number::Int(v) => v < &0,
|
||||||
|
Number::Float(v) => v < &0.0,
|
||||||
|
Number::Decimal(v) => v < &BigDecimal::from(0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_zero_or_positive(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Number::Int(v) => v >= &0,
|
||||||
|
Number::Float(v) => v >= &0.0,
|
||||||
|
Number::Decimal(v) => v >= &BigDecimal::from(0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_zero_or_negative(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Number::Int(v) => v <= &0,
|
||||||
|
Number::Float(v) => v <= &0.0,
|
||||||
|
Number::Decimal(v) => v <= &BigDecimal::from(0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
// Simple conversion of number
|
// Simple conversion of number
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
|
|
|
@ -23,7 +23,7 @@ impl Start {
|
||||||
doc: Option<&Value>,
|
doc: Option<&Value>,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
match self.0.compute(ctx, opt, txn, doc).await {
|
match self.0.compute(ctx, opt, txn, doc).await {
|
||||||
Ok(v) if v.is_integer() && v.is_positive() => Ok(v.as_usize()),
|
Ok(v) if v.is_integer() && v.is_zero_or_positive() => Ok(v.as_usize()),
|
||||||
Ok(v) => Err(Error::InvalidStart {
|
Ok(v) => Err(Error::InvalidStart {
|
||||||
value: v.as_string(),
|
value: v.as_string(),
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -698,6 +698,18 @@ impl Value {
|
||||||
matches!(self, Value::Number(v) if v.is_positive())
|
matches!(self, Value::Number(v) if v.is_positive())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_negative(&self) -> bool {
|
||||||
|
matches!(self, Value::Number(v) if v.is_negative())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_zero_or_positive(&self) -> bool {
|
||||||
|
matches!(self, Value::Number(v) if v.is_zero_or_positive())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_zero_or_negative(&self) -> bool {
|
||||||
|
matches!(self, Value::Number(v) if v.is_zero_or_negative())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_datetime(&self) -> bool {
|
pub fn is_datetime(&self) -> bool {
|
||||||
matches!(self, Value::Datetime(_))
|
matches!(self, Value::Datetime(_))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue