Commit 38042739 authored by hujiebin's avatar hujiebin

根据header的Timezone获取时区

parent b4589560
......@@ -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
......
......@@ -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
}
......
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"))
}
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