timezones

package module
v0.0.0-...-e20e7f4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 6 Imported by: 2

README

Package timezones builds new time.Locations.

Documentation: https://pkg.go.dev/github.com/martin-sucha/timezones

Documentation

Overview

Package timezones builds new time.Locations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLocation

func NewLocation(template Template) (*time.Location, error)

NewLocation creates a new time.Location from the template.

func TZData

func TZData(template Template) ([]byte, error)

TZData converts the template to TZif data. The returned data will be compatible with Go's time package. Compatilibity with other TZif readers is not guaranteed, in particular readers that support only version 1 of TZif will not work as TZData does not emit any V1 data.

Types

type Change

type Change struct {
	// Start is time when the previous zone changes to ZoneIndex.
	Start time.Time

	// ZoneIndex which takes effect since Start.
	// Must be in range 0 to len(Zones)-1.
	ZoneIndex int
}

Change describes a change from one Zone to another.

type Template

type Template struct {
	// Name of the new location.
	Name string

	// Zones lists local zones.
	// At the beginning of time, Zone at index 0 applies.
	// When that zone changes to another zone is specified in Changes.
	// Maximum of 254 zones can be present.
	Zones []Zone

	// Changes specifies zone transitions.
	// Changes Start times must be in strictly increasing order.
	// If Extend is non-empty, the ZoneIndex of the last Change is ignored, Extend is used instead.
	// Changes might be empty, in that case Extend must be non-empty.
	Changes []Change

	// If Extend is non-empty, it replaces the definition of zones since the last change.
	// If there is at most one zone specified by Zones and Changes, Extend applies since the beginning of time.
	// Extend is a TZ string conforming to RFC 8536, section 3.3.
	Extend string
}

Template describes how to build a time.Location.

func LoadTZData

func LoadTZData(tzdata []byte) (*Template, error)

LoadTZData into a template.

type Zone

type Zone struct {
	// Name of the zone.
	Name string

	// Offset to add to UTC time to get local time.
	// Zones with positive offsets are east of UTC.
	Offset time.Duration

	// IsDST reports whether Daylight Savings Time is in effect.
	IsDST bool
}

Zone describes a single zone.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL