Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 1.75 KB

README.md

File metadata and controls

51 lines (35 loc) · 1.75 KB

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