Explorar o código

Move EarlierOf and LaterOf to timeutil package

Signed-off-by: Niko Kovacevic <nikovacevic@gmail.com>
Niko Kovacevic %!s(int64=3) %!d(string=hai) anos
pai
achega
352883e481
Modificáronse 1 ficheiros con 16 adicións e 0 borrados
  1. 16 0
      pkg/util/timeutil/timeutil.go

+ 16 - 0
pkg/util/timeutil/timeutil.go

@@ -453,3 +453,19 @@ func leadingInt(s string) (x int64, rem string, err error) {
 	}
 	}
 	return x, s[i:], nil
 	return x, s[i:], nil
 }
 }
+
+// EarlierOf returns the second time passed in if both are equal
+func EarlierOf(timeOne, timeTwo time.Time) time.Time {
+	if timeOne.Before(timeTwo) {
+		return timeOne
+	}
+	return timeTwo
+}
+
+// LaterOf returns the second time passed in if both are equal
+func LaterOf(timeOne, timeTwo time.Time) time.Time {
+	if timeOne.After(timeTwo) {
+		return timeOne
+	}
+	return timeTwo
+}