timezones

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package timezones resolves IANA zone identifiers, mirroring lib/tasks/timezones.rb as far as the read path and the probe need it: the identifier gate, the detection precedence, and the tzdb self-report.

Index

Constants

View Source
const Fallback = "Etc/UTC"

Fallback is the zone every detection failure lands on.

Variables

This section is empty.

Functions

func Ambiguous

func Ambiguous(year int, month time.Month, day, hour, minute int, location *time.Location) bool

Ambiguous reports a wall time that names TWO instants — the hour a fall-back transition repeats. It is the question `fold` answers, and the only way a caller can know that answering it matters.

func Detect

func Detect(tz string, localtime string) (string, string, bool)

Detect resolves the host's zone: the TZ variable, then the /etc/localtime symlink, then the UTC fallback. The third return value is the "we fell back" warning flag Config carries.

func EarliestOn

func EarliestOn(year int, month time.Month, day int, location *time.Location) (time.Time, error)

EarliestOn is the first instant of a calendar date in a zone. It scans forward a minute at a time because midnight itself can be skipped: some zones have moved their clock forward at 00:00 local.

func FirstValidLocalAfter

func FirstValidLocalAfter(year int, month time.Month, day, hour, minute int, location *time.Location) (string, bool)

FirstValidLocalAfter is the hint a nonexistent-time diagnostic carries: the next wall time on the same date that the zone does observe.

func Get

func Get(identifier string) (string, error)

Get validates an identifier and returns its canonical spelling. The gate is deliberately narrow: anything without a "/" is refused unless it is exactly "UTC", so a POSIX TZ string cannot masquerade as a zone.

func InstantsFor

func InstantsFor(year int, month time.Month, day, hour, minute int, location *time.Location) []time.Time

InstantsFor is TZInfo's periods_for_local, expressed as the UTC instants a wall time maps to: none across a spring-forward gap, one ordinarily, two across a fall-back overlap.

Go's time.Date cannot answer this — it silently picks one instant for an ambiguous wall time and an unspecified one for a nonexistent one — so the candidate offsets are probed either side of the transition and each is kept only when it round-trips back to the wall time that was asked for.

func Load

func Load(identifier string) (*time.Location, error)

Load resolves an identifier to a location. It goes through Get first, so the narrow IANA gate applies here too and a POSIX TZ string cannot slip past.

func LocalTime

func LocalTime(instant time.Time, location *time.Location) time.Time

LocalTime projects an instant into a zone.

func TZDBVersion

func TZDBVersion() string

TZDBVersion is the advisory self-report of where zone data came from. Ruby answers with TZInfo's data source; Go's is the zoneinfo directory the runtime found, or its embedded copy.

func UTCFor

func UTCFor(year int, month time.Month, day, hour, minute int, location *time.Location, fold int) (time.Time, error)

UTCFor resolves a local wall time in a zone to its UTC instant. `fold` picks the SECOND instant of an overlap, matching the stored `fold: 1` marker.

Types

type Error

type Error struct{ Message string }

Error is the one failure this package raises, matching Tasks::Timezones::Error.

func (*Error) Error

func (e *Error) Error() string

type NonexistentLocalTime

type NonexistentLocalTime struct{ Message string }

NonexistentLocalTime is Tasks::Timezones::NonexistentLocalTime: a wall time the zone skips over, such as 02:30 on a spring-forward morning.

func (*NonexistentLocalTime) Error

func (e *NonexistentLocalTime) Error() string

Jump to

Keyboard shortcuts

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