tzot

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

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

Go to latest
Published: Feb 21, 2024 License: BSD-2-Clause Imports: 7 Imported by: 0

README

go-tzot

Overview

This repository provides the following program to utilize timezone offset transitions:

  • Go package "github.com/Jumpaku/go-tzot".
  • CLI tool tzot to generate a slim Go API.

This module is based on the IANA TZ database through a wrapper repository https://github.com/Jumpaku/tz-offset-transitions .

Go package "github.com/Jumpaku/go-tzot"

Installation
go get "github.com/Jumpaku/go-tzot@latest"
Example
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:
    $ <program> gen [<option>|<argument>]... [-- [<argument>]...]


Options:
    -all[=<boolean>], -a[=<boolean>]  (default=false):
        Generates Go code for all timezone IDs if true.

    -help[=<boolean>], -h[=<boolean>]  (default=false):
        Shows description of this subcommand.

    -output-path=<string>, -o=<string>  (default=""):
        Specifies output path of gen subcommand. If not specified, stdout is used.

    -package=<string>, -p=<string>  (default="tzot_gen"):
        Specifies package that output API belongs to.


Arguments:
    [0:] [<timezone_id_list:string>]...
        specifies timezone IDs for which Go code is generated.

tzot list
Lists all available timezone IDs.

Usage:
    $ <program> list [<option>]...


Options:
    -help[=<boolean>], -h[=<boolean>]  (default=false):
        Shows description of this subcommand.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AvailableZoneIDs

func AvailableZoneIDs() []string

func GetTZVersion

func GetTZVersion() string

func ModuleVersion

func ModuleVersion() string

Types

type Transition

type Transition struct {
	When         time.Time
	OffsetBefore time.Duration
	OffsetAfter  time.Duration
}

type TransitionJSON

type TransitionJSON struct {
	TransitionTimestamp string `json:"transition_timestamp"`
	OffsetSecondsBefore int    `json:"offset_seconds_before"`
	OffsetSecondsAfter  int    `json:"offset_seconds_after"`
}

type Zone

type Zone struct {
	ID          string
	Transitions []Transition
}

func GetZone

func GetZone(zoneID string) (zone Zone, found bool)

type ZoneJSON

type ZoneJSON struct {
	Zone        string           `json:"zone"`
	Transitions []TransitionJSON `json:"transitions"`
}

Directories

Path Synopsis
cmd
tzot
Code generated by cyamli v0.0.12, DO NOT EDIT.
Code generated by cyamli v0.0.12, DO NOT EDIT.
Code generated by go-tizot v0.0.1, DO NOT EDIT.
Code generated by go-tizot v0.0.1, DO NOT EDIT.

Jump to

Keyboard shortcuts

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