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.
elm install aeqz/timezone-abbreviationThe 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/timetypes. - That are non-locale-dependent and come strictly from the IANA Time Zone Database.
These are some alternatives that I'm aware of by looking at other existing Elm packages:
- If you just need displaying the time zone offset,
time-extrahas a function to obtain the offset in minutes, which then you can format as needed (e.g.GMT+1orUTC+01:00). deprecated-timeincludes aTime.TimeZone.abbreviationfunction. However, I don't know details about the abbreviations that it provides, doesn't use theelm/timetypes, and was intended to be used while upgrading a codebase to Elm0.19.
And these are some packages that could likely provide abbreviation data, but don't do at the moment:
elm-strftimedoesn't implement the%Z(i.e. time zone name or abbreviation) format specifier.cldrhas aShortNameandLongNametime zone formatting options, but they seem to provide a GMT offset (e.g.GMT+1for the short version andGMT+1:00for 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.
I found this page to be a useful reading when learning how abbreviations are represented in the IANA Time Zone Database source files.