From 38042739b6124359673eafccab28e1497cd75b90 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Sat, 17 Jun 2023 18:34:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AEheader=E7=9A=84Timezone?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=97=B6=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- route/cp_r/anniversary.go | 5 ++--- route/cp_r/space.go | 4 ++-- test/cp_test.go | 13 ++++++++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/route/cp_r/anniversary.go b/route/cp_r/anniversary.go index 2ad3e99..e3433ae 100644 --- a/route/cp_r/anniversary.go +++ b/route/cp_r/anniversary.go @@ -14,7 +14,6 @@ import ( "hilo-user/req" "hilo-user/resp" "strconv" - "time" ) type PostPutAnniversaryReq struct { @@ -95,8 +94,8 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { return myCtx, err } model := domain.CreateModelContext(myCtx) - loc, err := time.LoadLocation(c.GetHeader(mycontext.TIMEZONE)) - if err != nil { + loc := timezone_e.GetFixedTimezone(c.GetHeader(mycontext.TIMEZONE)) + if loc == nil { user, err := user_m.GetUser(model, userId) if err != nil { return myCtx, err diff --git a/route/cp_r/space.go b/route/cp_r/space.go index 1be7cc6..656b2fd 100644 --- a/route/cp_r/space.go +++ b/route/cp_r/space.go @@ -36,8 +36,8 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) { if err != nil { return myContext, err } - loc, err := time.LoadLocation(c.GetHeader(mycontext.TIMEZONE)) - if err != nil { + loc := timezone_e.GetFixedTimezone(c.GetHeader(mycontext.TIMEZONE)) + if loc == nil { if userInfo.Language == "ar" { loc = timezone_e.KSATimezoneLoc } diff --git a/test/cp_test.go b/test/cp_test.go index 0974f13..fb41739 100644 --- a/test/cp_test.go +++ b/test/cp_test.go @@ -1,9 +1,11 @@ package test import ( + "git.hilo.cn/hilo-common/_const/enum/timezone_e" "git.hilo.cn/hilo-common/domain" "hilo-user/domain/model/cp_m" "testing" + "time" ) func TestInitCpAnniversary(t *testing.T) { @@ -16,6 +18,15 @@ func TestInitCpAnniversary(t *testing.T) { } func TestCalcNextAnniversary(t *testing.T) { - t2 := cp_m.CalcNextAnniversary(1686211996) + t2 := cp_m.CalcNextAnniversary(1686211996, time.Local) println(t2) } + +func TestCalLoc(t *testing.T) { + loc := timezone_e.GetFixedTimezone("GMT+8") + println(time.Now().In(loc).Format("2006-01-02 15:04:05")) + loc = timezone_e.GetFixedTimezone("GMT+3") + println(time.Now().In(loc).Format("2006-01-02 15:04:05")) + loc = timezone_e.GetFixedTimezone("GMT+5") + println(time.Now().In(loc).Format("2006-01-02 15:04:05")) +} -- 2.22.0