tz

package module
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 9 Imported by: 1

README

go-tz

Go Reference

Time zone lookup by Lon and Lat

Usage

import "github.com/ugjka/go-tz/v2"
Example
// Loading Zone for Line Islands, Kiritimati
zone, err := tz.GetZone(tz.Point{
    Lon: -157.21328, Lat: 1.74294,
})
if err != nil {
    panic(err)
}
fmt.Println(zone[0])
[ugjka@archee example]$ go run main.go
Pacific/Kiritimati

Uses simplified shapefile from timezone-boundary-builder

GeoJson Simplification done with mapshaper

Features

  • The timezone shapefile is embedded in the build binary
  • Supports overlapping zones
  • You can load your custom geojson shapefile if you want
  • Sub-millisecond lookup even on old hardware

Problems

  • Shapefile is simplified using a lossy method so it may be inaccurate along the borders
  • This is purely in-memory. Uses ~50MB of ram

Licenses

The code used to look up the timezone for a location is licensed under the MIT License.

The data in the timezone shapefile is licensed under the Open Data Commons Open Database License (ODbL).

Documentation

Overview

Package tz provides timezone lookup for a given location

Features

* The timezone shapefile is embedded in the build binary using go-bindata

* Supports overlapping zones

* You can load your own geojson shapefile if you want

* Sub millisecond lookup even on old hardware

Problems

* The shapefile is simplified using a lossy method so it may be innacurate along the borders

* This is purerly in-memory. Uses ~50MB of ram

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNoZoneFound = errors.New("no corresponding zone found in shapefile")

ErrNoZoneFound is returned when a zone for the given point is not found in the shapefile

View Source
var ErrOutOfRange = errors.New("point's coordinates out of range")

ErrOutOfRange is returned when latitude exceeds 90 degrees or longitude exceeds 180 degrees

Functions

func GetZone

func GetZone(p Point) (tzid []string, err error)

GetZone returns a slice of strings containing time zone id's for a given Point

Example
// Loading Zone for Line Islands, Kiritimati
p := tz.Point{
	Lon: -157.21328, Lat: 1.74294,
}
zone, err := tz.GetZone(p)
if err != nil {
	panic(err)
}
fmt.Println(zone[0])
Output:

Pacific/Kiritimati

func LoadGeoJSON

func LoadGeoJSON(r io.Reader) error

LoadGeoJSON loads a custom GeoJSON shapefile from a Reader

Types

type Feature

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

Feature ...

type FeatureCollection

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

FeatureCollection ...

type Geometry

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

Geometry ...

func (*Geometry) UnmarshalJSON

func (g *Geometry) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON ...

type Point

type Point struct {
	Lon float64
	Lat float64
}

Point describes a location by Latitude and Longitude

Directories

Path Synopsis
Code generation tool for embedding the timezone shapefile in the gotz package run "go generate" in the parent directory after changing the -release flag in gen.go You need mapshaper to be installed and it must be in your $PATH More info on mapshaper: https://github.com/mbloch/mapshaper
Code generation tool for embedding the timezone shapefile in the gotz package run "go generate" in the parent directory after changing the -release flag in gen.go You need mapshaper to be installed and it must be in your $PATH More info on mapshaper: https://github.com/mbloch/mapshaper

Jump to

Keyboard shortcuts

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