From 39c991ee72bf0335c206505b42e5bc6c191cb498 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Sat, 17 Jun 2023 18:34:43 +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 --- _const/enum/timezone_e/tz.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/_const/enum/timezone_e/tz.go b/_const/enum/timezone_e/tz.go index 3e31ff9..c423a7c 100644 --- a/_const/enum/timezone_e/tz.go +++ b/_const/enum/timezone_e/tz.go @@ -1,6 +1,10 @@ package timezone_e -import "time" +import ( + "regexp" + "strconv" + "time" +) type Timezone int @@ -19,3 +23,15 @@ var TimezoneLocMap = map[Timezone]*time.Location{ TimezoneBeijing: BeijingTimezoneLoc, TimezoneKSA: KSATimezoneLoc, } + +// 根据header的Timezone获取时区 +// return nil: 无法解析 +func GetFixedTimezone(tz string) *time.Location { + re := regexp.MustCompile(`\d+`) + timeZone := re.FindString(tz) + offset, _ := strconv.Atoi(timeZone) + if offset <= 0 { + return nil + } + return time.FixedZone("CST", offset*3600) +} -- 2.22.0