tz

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2020 License: BSD-3-Clause, MIT Imports: 2 Imported by: 92

README

tz

Tests Go Report Card Go docs

Deprecated: Use time/tzdata available in Go 1.15. time/tzdata does not work exactly the same as it defaults to local tzdata when available where as this package always uses embedded data. This package will be maintained until Go 1.16 is released.

Predictably load time.Locations regardless of operating system.

import "4d63.com/tz"
loc, err := tz.LoadLocation("Australia/Sydney")

Docs and examples at https://godoc.org/4d63.com/tz.

This package exists because of https://github.com/golang/go/issues/21881.

Documentation

Overview

Package tz contains time zone info so that you can predictably load Locations regardless of the locations available on the locally running operating system.

The stdlib time.LoadLocation function loads timezone data from the operating system or from zoneinfo.zip in a local Go installation. Both of these are often missing from some operating systems, especially Windows.

This package has the zoneinfo.zip from Go embedded into the package so that queries to load a location always return the same data regardless of operating system.

This package exists because of https://github.com/golang/go/issues/21881.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadLocation

func LoadLocation(name string) (*time.Location, error)

LoadLocation loads timezone data from embedded tzinfo and does not rely on the operating system providing tzdata.

Same as time.LoadLocation if name is "" or "UTC", time.UTC is returned, and if name is "Local", time.Local is returned.

Returns an error if the name is unknown.

Example
package main

import (
	"fmt"
	"time"

	"4d63.com/tz"
)

func main() {
	t := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
	fmt.Println(t)

	syd, _ := tz.LoadLocation("Australia/Sydney")
	fmt.Println(t.In(syd))

}
Output:

2009-11-10 23:00:00 +0000 UTC
2009-11-11 10:00:00 +1100 AEDT

Types

This section is empty.

Jump to

Keyboard shortcuts

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