Skip to content

aeqz/timezone-abbreviation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timezone-abbreviation

This Elm package provides time zone name abbreviations from the IANA Time Zone Database for using with elm/time:

import Time
import TimeZone
import TimeZone.Abbreviation exposing (Abbreviation(..))

Time.millisToPosix 1743465600000
    |> TimeZone.Abbreviation.forZone
        ( Time.Name "Europe/London"
          -- Using zone offset data from `timezone-data`
        , TimeZone.europe__london ()
        )
--> Ok (ShortName "BST")

See some end-to-end example code in the examples/ folder.

Installation

elm install aeqz/timezone-abbreviation

Design Goals

The aim of providing time zone abbreviation data only may seem niche, but it's motivated by the fact that the Time.Zone type from elm/time doesn't have room for it. This package is expected to be used together with any other Time.Zone data source like justinmimbs/timezone-data and complete it with missing abbreviation data.

One difference to note with other alternatives like JavaScript's Intl API is that Intl.DateTimeFormat provides abbreviations that are locale-dependent, whereas this package provides abbreviations as they are in the IANA Time Zone Database, also including those that have not been used since 1970, uninhabited indicators and local mean times. Next releases effort may be put into trying to improve the internal representation to reduce the data size, apart from providing updates with more recent versions of the database.

As a summary, you may want to use this package if you want time zone name abbreviations:

  • In pure Elm, by using the elm/time types.
  • That are non-locale-dependent and come strictly from the IANA Time Zone Database.

Alternatives

These are some alternatives that I'm aware of by looking at other existing Elm packages:

And these are some packages that could likely provide abbreviation data, but don't do at the moment:

  • elm-strftime doesn't implement the %Z (i.e. time zone name or abbreviation) format specifier.
  • cldr has a ShortName and LongName time zone formatting options, but they seem to provide a GMT offset (e.g. GMT+1 for the short version and GMT+1:00 for the long one) instead of localized abbreviations.

You can also handle human time formatting in the JavaScript side, where you can get localized abbreviations by using Intl.DateTimeFormat, for instance via custom elements.

Learning resources

I found this page to be a useful reading when learning how abbreviations are represented in the IANA Time Zone Database source files.

About

Time zone name abbreviations from the IANA Time Zone Database

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors