Skip to content

Latest commit

 

History

History
70 lines (51 loc) · 2.04 KB

README.md

File metadata and controls

70 lines (51 loc) · 2.04 KB

Package tz (timezone)

Project status Build Status Go Report Card GoDoc License

Package tz contains information about Timezones (Country, Zone and Timezones) generated from timezonedb.com

This library is nothing special, it contains alphabetically sorted Country, Zone and Timezone info that can be used within your project.

Motivation

I got timezone abbreviation and offset in browser and I wanted to find timezone by this data. This package can do it.

I found https://github.com/go-playground/tz and forked it. I hope it is help you!

Thank you @go-playground!

Get zones by country, abbreviation and offset
tz.GetZones(country string, abbr string, offset int)
Get zones by abbreviation and offset
tz.GetZonesByAbbrAndOffset(abbr string, offset int)
Get zones by country code
tz.GetZonesByCountry(countryCode string)
Get zone by id
GetZoneById(zoneId int)
Get all countries
tz.GetCountries()
Get country by code
tz.GetCountry(countryCode string)
Example using with
timezones := tz.GetZones("AF", "LMT", 16608)
if len(timezones) > 0 {
    loc, _ := time.LoadLocation(timezones[0])
    // now that you have location can use with Go's time package which handles timezone offsets & Daylight savings times.
    time.ParseInLocation(...)
    time.Now().In(loc)
}

NOTES

This is intended to be used along side Go's own time logic eg. time.LoadLocation

Licence

This project is released under the MIT licence. See LICENCE for more details.