mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
add timestamp compare support (#7832)
This commit is contained in:
parent
90a3b830f4
commit
55092bede1
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user