zone

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider provides timezones.

func CreateProvider

func CreateProvider(zones []Zone, version string) Provider

CreateProvider creates a timezone Provider from given zones and version. Each zone ID in the given zones must be unique. For each zone of the zones, the transitions of the zone must be sorted in ascending order with respect to TransitionTimestamp field. OffsetMinutesAfter field of each transition of the transitions must match OffsetMinutesBefore field of the successor transition.

func LoadProvider

func LoadProvider(tzotJSONBytes []byte, version string) (Provider, error)

LoadProvider parses a JSON and returns a timezone Provider. tzotJSONBytes must be a JSON that is according to the format of tz-offset-transitions. https://github.com/Jumpaku/tz-offset-transitions

func (Provider) AvailableZoneIDs

func (p Provider) AvailableZoneIDs() []string

AvailableZoneIDs returns the timezone IDs of the available timezones.

func (Provider) Get

func (p Provider) Get(zoneID string) (zone Zone, found bool)

Get returns the timezone of the given zone ID.

func (Provider) Version

func (p Provider) Version() string

Version returns the version of the provider.

type Rule

type Rule interface {

	// Transition returns the transition of the timezone offset in the given year.
	Transition(year int) Transition
	// contains filtered or unexported methods
}

Rule defines when the yearly timezone offset transition occurs in the future.

type Transition

type Transition struct {
	TransitionTimestamp tokiope.Instant
	OffsetMinutesBefore datetime.OffsetMinutes
	OffsetMinutesAfter  datetime.OffsetMinutes
}

Transition represents a timezone offset transition.

type Zone

type Zone struct {
	// contains filtered or unexported fields
}

Zone represents a timezone with transitions and rules.

func Create

func Create(zoneID string, transitions []Transition, rules []Rule) Zone

Create creates a Zone with the given zone ID and transitions. The transitions must be sorted in ascending order with respect to TransitionTimestamp field. OffsetMinutesAfter field of each transition of the transitions must match OffsetMinutesBefore field of the successor transition.

func CreateFixed

func CreateFixed(zoneID string, offset datetime.OffsetMinutes) Zone

CreateFixed creates a Zone with the given zone ID and fixed offset.

func (Zone) FindOffset

func (z Zone) FindOffset(at tokiope.Instant) datetime.OffsetMinutes

FindOffset finds the timezone offset at the given instant.

func (Zone) ID

func (z Zone) ID() string

ID returns the ID of the zone.

type ZonedDateTime

type ZonedDateTime interface {
	// Date returns the date of the zoned datetime.
	Date() calendar.Date
	// Time returns the time of the zoned datetime.
	Time() datetime.Time
	// Zone returns the timezone of the zoned datetime.
	Zone() Zone
	// String returns the string representation of the zoned datetime.
	String() string
	// InstantCandidates returns the possible instants corresponding to the zoned datetime.
	// The returned slice contains a single instant if the corresponding instant exists uniquely.
	// The returned slice is empty if the corresponding instant does not exist due to gaps.
	// The returned slice contains multiple instants in ascending order if the corresponding instants are possible due to overlaps.
	InstantCandidates() []tokiope.Instant
}

ZonedDateTime represents a datetime with a timezone. Note that ZonedDateTime may represent no Instant or multiple possible Instants.

func NewZonedDateTime

func NewZonedDateTime(date calendar.Date, time datetime.Time, zone Zone) ZonedDateTime

NewZonedDateTime creates a ZonedDateTime from the date, time, and zone.

Jump to

Keyboard shortcuts

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