package main
import (
"fmt"
"github.com/Jumpaku/go-tzot"
)
func main() {
fmt.Println(tzot.GetTZVersion())
for _, zoneID := range tzot.AvailableZoneIDs() {
tzot.GetZone(zoneID) // Got tzot.Zone object
}
}
Available API
package tzot
import (
"time"
)
type Zone struct {
ID string
Transitions []Transition
}
type Transition struct {
When time.Time
OffsetBefore time.Duration
OffsetAfter time.Duration
}
func GetTZVersion() string
func AvailableZoneIDs() []string
func GetZone(zoneID string) Zone
CLI tool tzot
Installation
Using go install
go install "github.com/Jumpaku/go-tzot@latest"
Using go generate
package main
//go:generate go run "github.com/Jumpaku/go-tzot/cmd/tzot" gen -package=examples -output-path=tzot.go Asia/Tokyo Pacific/Pago_Pago Europe/Zurich Zulu
go generate ./...
Generated API
The generated API is similar to the above but available zone IDs are narrowed to the specified ones with command line arguments to tzot.
Usage
tzot gen
Generates Go code to handle timezone offset transitions for specified timezone IDs.
Usage:
$ gen [
type TransitionJSON struct {
TransitionTimestamp string `json:"transition_timestamp"`
OffsetSecondsBefore int `json:"offset_seconds_before"`
OffsetSecondsAfter int `json:"offset_seconds_after"`
}