@@ -100,6 +100,11 @@ func Equal(a, b interface{}) bool {
100100 case time.Time:
101101 return x.Equal(y)
102102 }
103+ case time.Duration:
104+ switch y := b.(type) {
105+ case time.Duration:
106+ return x == y
107+ }
103108 }
104109 if IsNil(a) && IsNil(b) {
105110 return true
@@ -120,6 +125,11 @@ func Less(a, b interface{}) bool {
120125 case time.Time:
121126 return x.Before(y)
122127 }
128+ case time.Duration:
129+ switch y := b.(type) {
130+ case time.Duration:
131+ return x < y
132+ }
123133 }
124134 panic(fmt.Sprintf("invalid operation: %T < %T", a, b))
125135}
@@ -137,6 +147,11 @@ func More(a, b interface{}) bool {
137147 case time.Time:
138148 return x.After(y)
139149 }
150+ case time.Duration:
151+ switch y := b.(type) {
152+ case time.Duration:
153+ return x > y
154+ }
140155 }
141156 panic(fmt.Sprintf("invalid operation: %T > %T", a, b))
142157}
@@ -154,6 +169,11 @@ func LessOrEqual(a, b interface{}) bool {
154169 case time.Time:
155170 return x.Before(y) || x.Equal(y)
156171 }
172+ case time.Duration:
173+ switch y := b.(type) {
174+ case time.Duration:
175+ return x <= y
176+ }
157177 }
158178 panic(fmt.Sprintf("invalid operation: %T <= %T", a, b))
159179}
@@ -171,6 +191,11 @@ func MoreOrEqual(a, b interface{}) bool {
171191 case time.Time:
172192 return x.After(y) || x.Equal(y)
173193 }
194+ case time.Duration:
195+ switch y := b.(type) {
196+ case time.Duration:
197+ return x >= y
198+ }
174199 }
175200 panic(fmt.Sprintf("invalid operation: %T >= %T", a, b))
176201}
@@ -192,6 +217,8 @@ func Add(a, b interface{}) interface{} {
192217 switch y := b.(type) {
193218 case time.Time:
194219 return y.Add(x)
220+ case time.Duration:
221+ return x + y
195222 }
196223 }
197224 panic(fmt.Sprintf("invalid operation: %T + %T", a, b))
@@ -204,6 +231,13 @@ func Subtract(a, b interface{}) interface{} {
204231 switch y := b.(type) {
205232 case time.Time:
206233 return x.Sub(y)
234+ case time.Duration:
235+ return x.Add(-y)
236+ }
237+ case time.Duration:
238+ switch y := b.(type) {
239+ case time.Duration:
240+ return x - y
207241 }
208242 }
209243 panic(fmt.Sprintf("invalid operation: %T - %T", a, b))
0 commit comments