From 6ba1050711ed685c2c1aa3a030f0bceed928d1aa Mon Sep 17 00:00:00 2001 From: tiglog Date: Tue, 19 Sep 2023 15:30:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=BC=BA=20time=20helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper/time_helper.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/helper/time_helper.go b/helper/time_helper.go index dcfda62..c1fef24 100644 --- a/helper/time_helper.go +++ b/helper/time_helper.go @@ -24,3 +24,26 @@ func FormatDt(ts int64) string { func FormatDateTime(ts int64) string { return Format(ts, "2006-01-02 15:04:05") } + +func IsUnixZero(t time.Time) bool { + return t.Unix() == 0 +} + +func GetTimeUTCPointer() *time.Time { + t := time.Now().UTC() + return &t +} + +func TimeToPointer(t time.Time) *time.Time { + if t.IsZero() { + return nil + } + return &t +} + +func UnixToTimePointer(v int64) *time.Time { + if v == 0 { + return nil + } + return TimeToPointer(time.Unix(v, 0)) +}