فهرست منبع

Move EarlierOf and LaterOf to timeutil package

Signed-off-by: Niko Kovacevic <nikovacevic@gmail.com>
Niko Kovacevic 3 سال پیش
والد
کامیت
352883e481
1فایلهای تغییر یافته به همراه16 افزوده شده و 0 حذف شده
  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
 }
+
+// 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
+}