mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-11-07 15:20:24 +08:00
93 lines
21 KiB
Go
93 lines
21 KiB
Go
|
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|||
|
|
|
|||
|
|
package nodeconfigs
|
|||
|
|
|
|||
|
|
import "time"
|
|||
|
|
|
|||
|
|
type TimeZoneGroupCode = string
|
|||
|
|
|
|||
|
|
const (
|
|||
|
|
TimeZoneGroupCodeAfrica TimeZoneGroupCode = "africa"
|
|||
|
|
TimeZoneGroupCodeEurope TimeZoneGroupCode = "europe"
|
|||
|
|
TimeZoneGroupCodeNorthAmerica TimeZoneGroupCode = "northamerica"
|
|||
|
|
TimeZoneGroupCodeSouthAmerica TimeZoneGroupCode = "southamerica"
|
|||
|
|
TimeZoneGroupCodeAntarctica TimeZoneGroupCode = "antarctica"
|
|||
|
|
TimeZoneGroupCodeAustralasia TimeZoneGroupCode = "australasia"
|
|||
|
|
TimeZoneGroupCodeAsia TimeZoneGroupCode = "asia"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
type TimeZoneGroup struct {
|
|||
|
|
Name string `json:"name"`
|
|||
|
|
Code TimeZoneGroupCode `json:"code"`
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func FindAllTimeZoneGroups() []*TimeZoneGroup {
|
|||
|
|
return []*TimeZoneGroup{
|
|||
|
|
{
|
|||
|
|
Name: "亚洲",
|
|||
|
|
Code: TimeZoneGroupCodeAsia,
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
Name: "北美",
|
|||
|
|
Code: TimeZoneGroupCodeNorthAmerica,
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
Name: "南美",
|
|||
|
|
Code: TimeZoneGroupCodeSouthAmerica,
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
Name: "欧洲",
|
|||
|
|
Code: TimeZoneGroupCodeEurope,
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
Name: "大洋洲",
|
|||
|
|
Code: TimeZoneGroupCodeAustralasia,
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
Name: "非洲",
|
|||
|
|
Code: TimeZoneGroupCodeAfrica,
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
Name: "南极洲",
|
|||
|
|
Code: TimeZoneGroupCodeAntarctica,
|
|||
|
|
},
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const DefaultTimeZoneLocation = "Asia/Shanghai"
|
|||
|
|
|
|||
|
|
type TimeZoneLocation struct {
|
|||
|
|
Name string `json:"name"`
|
|||
|
|
Offset string `json:"offset"`
|
|||
|
|
Group TimeZoneGroupCode `json:"group"`
|
|||
|
|
IsCanonical bool `json:"isCanonical"`
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var timeZones = []*TimeZoneLocation{}
|
|||
|
|
|
|||
|
|
func FindAllTimeZoneLocations() []*TimeZoneLocation {
|
|||
|
|
if len(timeZones) == 0 {
|
|||
|
|
var allTimeZones = []*TimeZoneLocation{{Name: "Africa/Ceuta", Offset: "+02:00", Group: "europe", IsCanonical: true}, {Name: "Africa/Kinshasa", Offset: "+01:00", Group: "africa", IsCanonical: false}, {Name: "Africa/Lagos", Offset: "+01:00", Group: "africa", IsCanonical: true}, {Name: "Africa/Lubumbashi", Offset: "+02:00", Group: "africa", IsCanonical: false}, {Name: "Africa/Maputo", Offset: "+02:00", Group: "africa", IsCanonical: true}, {Name: "America/Adak", Offset: "−09:00", Group: "northamerica", IsCanonical: true}, {Name: "America/Anchorage", Offset: "−08:00", Group: "northamerica", IsCanonical: true}, {Name: "America/Araguaina", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Argentina/Buenos_Aires", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Argentina/Catamarca", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Argentina/Cordoba", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Argentina/Jujuy", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Argentina/La_Rioja", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Argentina/Mendoza", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Argentina/Rio_Gallegos", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Argentina/Salta", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Argentina/San_Juan", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Argentina/San_Luis", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Argentina/Tucuman", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Argentina/Ushuaia", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Atikokan", Offset: "−05:00", Group: "northamerica", IsCanonical: false}, {Name: "America/Bahia", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Bahia_Banderas", Offset: "−05:00", Group: "northamerica", IsCanonical: true}, {Name: "America/Belem", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Blanc-Sablon", Offset: "−04:00", Group: "northamerica", IsCanonical: false}, {Name: "America/Boa_Vista", Offset: "−04:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Boise", Offset: "−06:00", Group: "northamerica", IsCanonical: true}, {Name: "America/Cambridge_Bay", Offset: "−06:00", Group: "northamerica", IsCanonical: true}, {Name: "America/Campo_Grande", Offset: "−04:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Cancun", Offset: "−05:00", Group: "northamerica", IsCanonical: true}, {Name: "America/Chicago", Offset: "−05:00", Group: "northamerica", IsCanonical: true}, {Name: "America/Chihuahua", Offset: "−06:00", Group: "northamerica", IsCanonical: true}, {Name: "America/Creston", Offset: "−07:00", Group: "northamerica", IsCanonical: false}, {Name: "America/Cuiaba", Offset: "−04:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Danmarkshavn", Offset: "+00:00", Group: "europe", IsCanonical: true}, {Name: "America/Dawson", Offset: "−07:00", Group: "northamerica", IsCanonical: true}, {Name: "America/Dawson_Creek", Offset: "−07:00", Group: "northamerica", IsCanonical: true}, {Name: "America/Denver", Offset: "−06:00", Group: "northamerica", IsCanonical: true}, {Name: "America/Detroit", Offset: "−04:00", Group: "northamerica", IsCanonical: true}, {Name: "America/Edmonton", Offset: "−06:00", Group: "northamerica", IsCanonical: true}, {Name: "America/Eirunepe", Offset: "−05:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Fort_Nelson", Offset: "−07:00", Group: "northamerica", IsCanonical: true}, {Name: "America/Fortaleza", Offset: "−03:00", Group: "southamerica", IsCanonical: true}, {Name: "America/Glace_Bay", Offset: "−03:00", Group: "northamerica", IsCanonical: true}, {Name: "America/G
|
|||
|
|
|
|||
|
|
// 检查是否存在
|
|||
|
|
var validTimeZones = []*TimeZoneLocation{}
|
|||
|
|
for _, location := range allTimeZones {
|
|||
|
|
_, err := time.LoadLocation(location.Name)
|
|||
|
|
if err == nil {
|
|||
|
|
validTimeZones = append(validTimeZones, location)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
timeZones = validTimeZones
|
|||
|
|
}
|
|||
|
|
return timeZones
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func FindTimeZoneLocation(name string) *TimeZoneLocation {
|
|||
|
|
for _, location := range FindAllTimeZoneLocations() {
|
|||
|
|
if location.Name == name {
|
|||
|
|
return location
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return nil
|
|||
|
|
}
|