From 970cfd6b7341a1dc63dd00dee745b12d97ba1633 Mon Sep 17 00:00:00 2001 From: "vilet.yy" Date: Thu, 10 Jun 2021 14:49:46 +0800 Subject: [PATCH] add: timer --- timer/time.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 timer/time.go diff --git a/timer/time.go b/timer/time.go new file mode 100644 index 0000000..f0414f9 --- /dev/null +++ b/timer/time.go @@ -0,0 +1,24 @@ +/* + * @Date: 2021-06-10 14:41:54 + * @LastEditors: viletyy + * @LastEditTime: 2021-06-10 14:46:39 + * @FilePath: /yolk/timer/time.go + */ +package timer + +import "time" + +func GetNowTime() time.Time { + location, _ := time.LoadLocation("Asia/Shanghai") + + return time.Now().In(location) +} + +func GetCalculateTime(currentTimer time.Time, d string) (time.Time, error) { + duration, err := time.ParseDuration(d) + if err != nil { + return time.Time{}, err + } + + return currentTimer.Add(duration), nil +}