LostKobrakai

LostKobrakai

Tzinfo - Parsing the time zone information format (zonefiles)

Over the holidays I worked on a library to parse zonefiles, which are present on most UNIX systems, as a potential source of timezone information. This might be useful if your elixir system does need to share timezone information with other systems, which also rely on the OS provided zonefiles, where tzdata doesn’t fit as it’s downloading/using its own database from the IANA.

The package also includes a parser for POSIX time zone strings, which is what zonefiles hold in their footer part of version 2/3.

It does not yet include code for searching the data though, which also means there’s not yet an implementation for Calendar.TimeZoneDatabase like there is for tzdata.

# https://tools.ietf.org/html/rfc8536#appendix-B.2
> Tzinfo.Parser.parse(binary_contents)
{:ok, 
%{
  bin: "",
  version: 2,
  data: %{
    designations: %{
      0 => "LMT",
      4 => "HST",
      8 => "HDT",
      12 => "HWT",
      16 => "HPT"
    },
    leap_seconds: [],
    std_wall_indicators: [0, 0, 0, 0, 1, 0],
    transition_types: [1, 2, 1, 3, 4, 1, 5],
    transitions: [
      -2_334_101_314,
      -1_157_283_000,
      -1_155_436_200,
      -880_198_200,
      -769_395_600,
      -765_376_200,
      -712_150_200
    ],
    types: [
      %{designation_index: 0, dst: false, offset: -37886},
      %{designation_index: 4, dst: false, offset: -37800},
      %{designation_index: 8, dst: true, offset: -34200},
      %{designation_index: 12, dst: true, offset: -34200},
      %{designation_index: 16, dst: true, offset: -34200},
      %{designation_index: 4, dst: false, offset: -36000}
    ],
    ut_local_indicators: [0, 0, 0, 0, 1, 0]
  },
  footer: "HST10"
}}

Source file: https://tools.ietf.org/html/rfc8536#appendix-B.2

iex(1)> Tzinfo.Posix.parse("PST8PDT,M3.2.0/2:00:00,M11.1.0/2:00:00")
{:ok,
 %{
   std: %{abbr: "PST", std_offset: 0, utc_offset: 28800},
   dst: %{
     abbr: "PDT",
     std_offset: 3600,
     utc_offset: 28800,
     start: %{
       midnight_offset: 7200,
       type: :month_based,
       value: %{day: 0, month: 3, week: 2}
     },
     end: %{
       midnight_offset: 7200,
       type: :month_based,
       value: %{day: 0, month: 11, week: 1}
     }
   }
 }}

Most Liked

wojtekmach

wojtekmach

Hex Core Team

Nice project! For anyone curious in trying it out with zone info files shipping with macOS you can do the following:

iex> Tzinfo.Parser.parse(File.read!("/usr/share/zoneinfo/America/New_York"))
{:ok,
 %{
   bin: "",
   counters: %{char: 20, isstd: 5, isut: 5, leap: 0, time: 236, type: 5},
   data: %{
     designations: %{
       0 => "LMT",
       4 => "EDT",
       8 => "EST",
       12 => "EWT",
       16 => "EPT"
     },
     ...
 }}

Where Next?

Popular in Libraries Top

Qqwy
Solution is a library to help you with working with ok/error-tuples in case and with-expressions by exposing special matching macros, as ...
New
marcuslankenau
I feel kind of stuck with the absence of a proper xml library for Elixir. Currently I use SweetXML which was ok for me more or less to pa...
New
asiniy
Hey there! I wrote a download elixir package which does exactly what its name about - an easy way to download files. I saw solutions ...
New
cjen07
parameterized pipe in elixir: |n> edit: negative index in |n> and mixed usage with |> are supported example: use ParamP...
New
jakub-zawislak
Hi everyone, I’m coming from the Symfony (PHP) framework. I like Phoenix, but it has a one thing that was build much better in the Symfo...
New
michalmuskala
Another small library today. PersistentEts Hex: persistent_ets | Hex GitHub: GitHub - michalmuskala/persistent_ets Ets table backed by...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 18262 141
New
ericlathrop
I built a silly site for Halloween that uses Phoenix Channels on the backend, and React on the frontend. I had many problems integrating ...
New
New

Other popular topics Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

Sub Categories:

We're in Beta

About us Mission Statement