From 24fea8fc61adc45d593f9585850533bbf2d8e2bd Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Wed, 5 Apr 2017 13:57:57 -0600 Subject: [PATCH] tools/time: introduce TimeAtOrIn to calculate absolute time from optional relative --- tools/time_tools.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tools/time_tools.go diff --git a/tools/time_tools.go b/tools/time_tools.go new file mode 100644 index 00000000..6d8afb2c --- /dev/null +++ b/tools/time_tools.go @@ -0,0 +1,13 @@ +package tools + +import "time" + +// TimeAtOrIn returns either "at", or the "in" duration added to the current +// time. TimeAtOrIn prefers to add a duration rather than return the "at" +// parameter. +func TimeAtOrIn(at time.Time, in time.Duration) time.Time { + if in == 0 { + return at + } + return time.Now().Add(in) +}