diff --git a/_const/enum/timezone_e/tz.go b/_const/enum/timezone_e/tz.go index 3e31ff9616c7ea09366ccb61c4d59f01ebd37fd0..c423a7cefe9878cd897d24d1f513f668e90b0536 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) +}