Documentation
¶
Overview ¶
Package gotz provides direct access to IANA timezone data, exposing transitions, zone types, and POSIX TZ rules that Go's time.Location keeps private.
Timezone data is compiled from the official IANA source and embedded in the package. Use Load to get a Zone by IANA name:
z, err := gotz.Load("America/New_York")
for _, t := range z.Transitions() {
fmt.Println(t.When, z.Types()[t.Type].Abbrev)
}
Index ¶
- Variables
- type LeapSecond
- type PosixTZ
- type RuleKind
- type Transition
- type TransitionRule
- type Zone
- func (z *Zone) Extend() *PosixTZ
- func (z *Zone) ExtendRaw() string
- func (z *Zone) LeapSeconds() []LeapSecond
- func (z *Zone) Location() (*time.Location, error)
- func (z *Zone) Lookup(t time.Time) ZoneType
- func (z *Zone) Name() string
- func (z *Zone) String() string
- func (z *Zone) Transitions() []Transition
- func (z *Zone) TransitionsForRange(start, end time.Time) []Transition
- func (z *Zone) Types() []ZoneType
- func (z *Zone) Version() int
- type ZoneType
Constants ¶
This section is empty.
Variables ¶
var ErrBadData = errors.New("gotz: malformed timezone data")
Functions ¶
This section is empty.
Types ¶
type LeapSecond ¶
LeapSecond represents a leap second record.
type PosixTZ ¶
type PosixTZ struct {
StdAbbrev string // standard time abbreviation
StdOffset int // standard time UTC offset in seconds (positive = east)
DSTAbbrev string // DST abbreviation (empty if no DST)
DSTOffset int // DST UTC offset in seconds
Start TransitionRule
End TransitionRule
}
PosixTZ represents a parsed POSIX-style TZ string. Example: "EST5EDT,M3.2.0,M11.1.0"
func ParsePosixTZ ¶
ParsePosixTZ parses a POSIX-style TZ string.
func (*PosixTZ) Lookup ¶
Lookup returns the zone abbreviation, UTC offset, and DST flag in effect at the given Unix timestamp according to this POSIX TZ rule.
type RuleKind ¶
type RuleKind int
RuleKind identifies the type of transition rule in a POSIX TZ string.
type Transition ¶
type Transition struct {
When int64 // Unix timestamp
Type int // index into Zone.Types()
IsStd bool // transition time is standard (not wall clock)
IsUT bool // transition time is UT (not local)
}
Transition represents a moment when the timezone rule changes.
type TransitionRule ¶
type TransitionRule struct {
Kind RuleKind
Day int // Julian day (1-365), DOY (0-365), or day-of-week (0=Sunday)
Week int // week of month (1-5), only for RuleMonthWeekDay
Mon int // month (1-12), only for RuleMonthWeekDay
Time int // seconds after midnight (default 7200 = 02:00:00)
}
TransitionRule specifies when a DST transition occurs within a year.
type Zone ¶
type Zone struct {
// contains filtered or unexported fields
}
Zone represents a parsed IANA timezone with all raw data exposed.
func Load ¶
Load returns a Zone for the given IANA timezone name. Results are cached; subsequent calls for the same name return the same *Zone.
func (*Zone) Extend ¶
Extend returns the parsed POSIX TZ rule for computing future transitions, or nil if the TZif file has no footer string.
func (*Zone) LeapSeconds ¶
func (z *Zone) LeapSeconds() []LeapSecond
LeapSeconds returns a copy of the leap second records.
func (*Zone) Location ¶
Location returns a *time.Location equivalent to this Zone. This uses time.LoadLocationFromTZData with the original TZif binary data.
func (*Zone) Lookup ¶
Lookup returns the zone type in effect at the given time. It searches transitions and falls back to the POSIX TZ rule for times after the last transition.
func (*Zone) Transitions ¶
func (z *Zone) Transitions() []Transition
Transitions returns a copy of the transition records.
func (*Zone) TransitionsForRange ¶
func (z *Zone) TransitionsForRange(start, end time.Time) []Transition
TransitionsForRange returns all transitions in the half-open interval [start, end), combining stored transitions from the TZif file with dynamically generated ones from the POSIX TZ extend rule.