add timestamp compare support (#7832)

This commit is contained in:
Yao Zongyou 2019-06-26 02:05:37 +08:00 committed by kannappanr
parent 90a3b830f4
commit 55092bede1

View file

@ -340,6 +340,12 @@ func (v *Value) compareOp(op string, a *Value) (res bool, err error) {
return boolCompare(op, boolV, boolA)
}
timestampV, ok1t := v.ToTimestamp()
timestampA, ok2t := a.ToTimestamp()
if ok1t && ok2t {
return timestampCompare(op, timestampV, timestampA), nil
}
return false, errCmpMismatchedTypes
}
@ -721,6 +727,25 @@ func boolCompare(op string, left, right bool) (bool, error) {
}
}
func timestampCompare(op string, left, right time.Time) bool {
switch op {
case opLt:
return left.Before(right)
case opLte:
return left.Before(right) || left.Equal(right)
case opGt:
return left.After(right)
case opGte:
return left.After(right) || left.Equal(right)
case opEq:
return left.Equal(right)
case opIneq:
return !left.Equal(right)
}
// This case does not happen
return false
}
func isValidArithOperator(op string) bool {
switch op {
case opPlus: