Documentation
¶
Overview ¶
Package tz implements the functions, types, and interfaces for the module.
Package tz implements the functions, types, and interfaces for the module.
Package tz implements the functions, types, and interfaces for the module.
Package tz implements the functions, types, and interfaces for the module.
Package tz implements the functions, types, and interfaces for the module.
Package tz implements the functions, types, and interfaces for the module.
Package tz implements the functions, types, and interfaces for the module.
Package tz implements enhanced Windows timezone support with caching and fallback strategies.
Package tz implements enhanced Windows timezone mapping with validation and fallback.
Index ¶
- Constants
- Variables
- func ConvertTime(t time.Time, fromZone, toZone string) (time.Time, error)
- func ConvertWindowsToIANA(windowsID string) ([]string, bool)
- func ConvertWindowsToPreferredIANA(windowsID string) (string, bool)
- func GenerateJSON() error
- func GetLocation() (*time.Location, error)
- func GetLocationString() string
- func GetOffset(zone string) (int64, error)
- func GetSystemTimezone() (string, error)
- func IsDST(t time.Time, zone string) (bool, error)
- type Country
- type MappingError
- type RawTimeZone
- type TimeZone
- type TimeZoneConverter
- type TimeZoneFinder
- type TimeZoneInfo
- type TimezoneDetectionError
- type WindowsMapper
- func (m *WindowsMapper) GetAllMappings() map[string]WindowsTimeZoneMapping
- func (m *WindowsMapper) IANAToWindows(ianaZone string) ([]string, bool)
- func (m *WindowsMapper) LoadMappings() error
- func (m *WindowsMapper) ValidateMapping(windowsID, ianaZone string) error
- func (m *WindowsMapper) WindowsToIANA(windowsID string) ([]string, bool)
- func (m *WindowsMapper) WindowsToPreferredIANA(windowsID string) (string, bool)
- type WindowsTimeZoneDetector
- type WindowsTimeZoneMapping
Constants ¶
const ( OffsetCountryName = 0 OffsetCountryCode = 1 )
const ( OffsetZoneName = 0 OffsetZoneCountryCode = 1 OffsetZoneAbbreviation = 2 OffsetZoneTimeStart = 3 OffsetZoneGmtOffset = 4 OffsetZoneDst = 5 )
Variables ¶
var ( ErrTimeZoneNotFound = errors.New("timezone not found") ErrInvalidTimeZone = errors.New("invalid timezone format") ErrConversionFailed = errors.New("timezone conversion failed") ErrLocationNotFound = errors.New("location not found") ErrWindowsTimeZoneNotFound = errors.New("Windows timezone not found") ErrIANATimeZoneNotFound = errors.New("IANA timezone not found") ErrNotImplemented = errors.New("feature not implemented") ErrCacheExpired = errors.New("cache expired") ErrDetectionFailed = errors.New("timezone detection failed") )
Common timezone errors
Functions ¶
func ConvertTime ¶
ConvertTime converts time from one timezone to another
func ConvertWindowsToIANA ¶
ConvertWindowsToIANA converts a Windows timezone ID to IANA zones using the global mapper
func ConvertWindowsToPreferredIANA ¶
ConvertWindowsToPreferredIANA converts a Windows timezone ID to the preferred IANA zone
func GenerateJSON ¶
func GenerateJSON() error
func GetLocation ¶
GetLocation returns the current system timezone
func GetLocationString ¶
func GetLocationString() string
GetLocationString returns the current system timezone as string
func GetSystemTimezone ¶
GetSystemTimezone gets the current system timezone using enhanced detection
Types ¶
type Country ¶
type Country struct {
CountryName string `json:"country_name"`
CountryCode string `json:"country_code"`
}
Country country_name,country_code
func CountriesFromCSV ¶
type MappingError ¶
MappingError represents errors during timezone mapping operations
func (*MappingError) Error ¶
func (e *MappingError) Error() string
func (*MappingError) Unwrap ¶
func (e *MappingError) Unwrap() error
type RawTimeZone ¶
type RawTimeZone struct {
ZoneName string `json:"zone_name"`
CountryCode string `json:"country_code"`
Abbreviation string `json:"abbreviation"`
TimeStart int64 `json:"time_start"`
GmtOffset int64 `json:"gmt_offset"`
Dst int64 `json:"dst"`
}
RawTimeZone represents the raw timezone data from JSON
type TimeZone ¶
type TimeZone struct {
ZoneName string `json:"zone_name"`
ZoneID string `json:"zone_id"`
CountryCode string `json:"country_code"`
Abbreviation string `json:"abbreviation"`
TimeStart int64 `json:"time_start"`
GmtOffset int64 `json:"gmt_offset"`
Dst int64 `json:"dst"` // 1 or 0 means DST
}
TimeZone zone_name,country_code,abbreviation,time_start,gmt_offset,dst
func FindTimeZoneByZoneName ¶
FindTimeZoneByZoneName finds timezone by zone name
func FindTimeZonesByAbbreviation ¶
FindTimeZonesByAbbreviation finds timezones by abbreviation
func FindTimeZonesByCountryCode ¶
FindTimeZonesByCountryCode finds timezones by country code
func TimeZonesFromCSV ¶
type TimeZoneConverter ¶
type TimeZoneConverter interface {
Convert(t time.Time, fromZone, toZone string) (time.Time, error)
GetOffset(zone string) (int, error)
IsDST(t time.Time, zone string) (bool, error)
}
TimeZoneConverter interface for timezone conversion
type TimeZoneFinder ¶
type TimeZoneFinder interface {
FindByZoneName(name string) (*TimeZone, bool)
FindByCountryCode(code string) ([]*TimeZone, bool)
FindByAbbreviation(abbrev string) ([]*TimeZone, bool)
GetCurrentLocation() (*time.Location, error)
GetAllTimeZones() []*TimeZone
}
TimeZoneFinder interface for finding timezones
type TimeZoneInfo ¶
type TimeZoneInfo struct {
Name string `json:"name"`
Country string `json:"country"`
Offset int64 `json:"offset"` // in seconds
OffsetString string `json:"offset_string"` // "+08:00" format
IsDST bool `json:"is_dst"`
Abbreviation string `json:"abbreviation"`
Location *time.Location `json:"-"`
}
TimeZoneInfo provides detailed timezone information
func GetTimeZoneInfo ¶
func GetTimeZoneInfo(name string) (*TimeZoneInfo, error)
GetTimeZoneInfo returns detailed timezone information
type TimezoneDetectionError ¶
TimezoneDetectionError represents errors during timezone detection
func (*TimezoneDetectionError) Error ¶
func (e *TimezoneDetectionError) Error() string
func (*TimezoneDetectionError) Unwrap ¶
func (e *TimezoneDetectionError) Unwrap() error
type WindowsMapper ¶
type WindowsMapper struct {
// contains filtered or unexported fields
}
WindowsMapper provides enhanced Windows timezone mapping capabilities
func NewWindowsMapper ¶
func NewWindowsMapper() *WindowsMapper
NewWindowsMapper creates a new mapper instance
func (*WindowsMapper) GetAllMappings ¶
func (m *WindowsMapper) GetAllMappings() map[string]WindowsTimeZoneMapping
GetAllMappings returns all timezone mappings
func (*WindowsMapper) IANAToWindows ¶
func (m *WindowsMapper) IANAToWindows(ianaZone string) ([]string, bool)
IANAToWindows finds Windows timezone IDs that map to the given IANA zone
func (*WindowsMapper) LoadMappings ¶
func (m *WindowsMapper) LoadMappings() error
LoadMappings loads timezone mappings from embedded data or external source
func (*WindowsMapper) ValidateMapping ¶
func (m *WindowsMapper) ValidateMapping(windowsID, ianaZone string) error
ValidateMapping validates a Windows to IANA timezone mapping
func (*WindowsMapper) WindowsToIANA ¶
func (m *WindowsMapper) WindowsToIANA(windowsID string) ([]string, bool)
WindowsToIANA converts a Windows timezone ID to IANA zones
func (*WindowsMapper) WindowsToPreferredIANA ¶
func (m *WindowsMapper) WindowsToPreferredIANA(windowsID string) (string, bool)
WindowsToPreferredIANA converts a Windows timezone ID to the preferred IANA zone
type WindowsTimeZoneDetector ¶
type WindowsTimeZoneDetector struct {
// contains filtered or unexported fields
}
WindowsTimeZoneDetector provides enhanced Windows timezone detection
func NewWindowsTimeZoneDetector ¶
func NewWindowsTimeZoneDetector(ttl time.Duration) *WindowsTimeZoneDetector
NewWindowsTimeZoneDetector creates a new detector with configurable TTL
func (*WindowsTimeZoneDetector) GetSystemTimezone ¶
func (d *WindowsTimeZoneDetector) GetSystemTimezone() (string, error)
GetSystemTimezone safely gets the system timezone with caching
type WindowsTimeZoneMapping ¶
type WindowsTimeZoneMapping struct {
WindowsID string `json:"windows_id"`
IANAZones []string `json:"iana_zones"`
Territory string `json:"territory"`
LastUpdated time.Time `json:"last_updated"`
Preferred string `json:"preferred,omitempty"` // Preferred IANA zone for this Windows zone
}
WindowsTimeZoneMapping represents a mapping from Windows timezone to IANA zones