Skip to content

medama-io/go-timezone-country

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-timezone-country

This library converts timezones obtained from Intl.DateTimeFormat().resolvedOptions().timeZone to full country names.

Installation

go get -u github.com/medama-io/go-timezone-country

Usage

package main

import (
    "fmt"
    tz "github.com/medama-io/go-timezone-country"
)

func main() {
    // Load the timezone to country name map during startup.
    timezoneNameMap, err := tz.NewTimezoneCountryMap()
    if err != nil {
        panic(err)
    }

    // Obtain the country name from the timezone.
    countryName, err := timezoneNameMap.GetCountryName("Europe/London")
    if err != nil {
        panic(err)
    }
    fmt.Println(countryName) // United Kingdom
}

Contribution

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

The data is updated from time to time using the scripts/update.sh script. In the case of timezone differences according to the IANA standard, we print the discrepancies while running the script and maintain the old timezone mappings in the data/missing.json file. This data can be corrobated using the unicode-org/cldr-json repository.

It's also worth tracking the TC39 Canonical Timezone proposal, which is currently in Stage 3. This may be a future option to map timezones to countries natively and more accurately. The proposal can be found in the tc39/proposal-canonical-tz.

License

MIT

Acknowledgements

  • The idea behind this library was inspired by a blog post from Talha Awan

About

Convert IANA timezones into countries in Golang.

Resources

License

Stars

Watchers

Forks

Releases

No releases published