Commit 38042739 authored by hujiebin's avatar hujiebin

根据header的Timezone获取时区

parent b4589560
...@@ -14,7 +14,6 @@ import ( ...@@ -14,7 +14,6 @@ import (
"hilo-user/req" "hilo-user/req"
"hilo-user/resp" "hilo-user/resp"
"strconv" "strconv"
"time"
) )
type PostPutAnniversaryReq struct { type PostPutAnniversaryReq struct {
...@@ -95,8 +94,8 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -95,8 +94,8 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
return myCtx, err return myCtx, err
} }
model := domain.CreateModelContext(myCtx) model := domain.CreateModelContext(myCtx)
loc, err := time.LoadLocation(c.GetHeader(mycontext.TIMEZONE)) loc := timezone_e.GetFixedTimezone(c.GetHeader(mycontext.TIMEZONE))
if err != nil { if loc == nil {
user, err := user_m.GetUser(model, userId) user, err := user_m.GetUser(model, userId)
if err != nil { if err != nil {
return myCtx, err return myCtx, err
......
...@@ -36,8 +36,8 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -36,8 +36,8 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) {
if err != nil { if err != nil {
return myContext, err return myContext, err
} }
loc, err := time.LoadLocation(c.GetHeader(mycontext.TIMEZONE)) loc := timezone_e.GetFixedTimezone(c.GetHeader(mycontext.TIMEZONE))
if err != nil { if loc == nil {
if userInfo.Language == "ar" { if userInfo.Language == "ar" {
loc = timezone_e.KSATimezoneLoc loc = timezone_e.KSATimezoneLoc
} }
......
package test package test
import ( import (
"git.hilo.cn/hilo-common/_const/enum/timezone_e"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"hilo-user/domain/model/cp_m" "hilo-user/domain/model/cp_m"
"testing" "testing"
"time"
) )
func TestInitCpAnniversary(t *testing.T) { func TestInitCpAnniversary(t *testing.T) {
...@@ -16,6 +18,15 @@ func TestInitCpAnniversary(t *testing.T) { ...@@ -16,6 +18,15 @@ func TestInitCpAnniversary(t *testing.T) {
} }
func TestCalcNextAnniversary(t *testing.T) { func TestCalcNextAnniversary(t *testing.T) {
t2 := cp_m.CalcNextAnniversary(1686211996) t2 := cp_m.CalcNextAnniversary(1686211996, time.Local)
println(t2) 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"))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment