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://github.com/LostKobrakai/tzinfo

# 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: RFC 8536 - The Time Zone Information Format (TZif)

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 Announcing Top

wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: GitHub - tmbb/phoenix_ws: Websockets implemented over Phoenix Ch...
New
mspanc
I am pleased to announce an initial release of the Membrane Framework - an Elixir-based framework with special focus on processing multim...
New
mathieuprog
Hello :waving_hand: Allow me to introduce you to Tz, an alternative time zone database support to Tzdata. Why another library? First a...
New
mischov
import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story <- Meeseeks.all(html, css("tr.athing")) do...
New
seancribbs
Today I released a new dialyzer Mix task as the dialyzex package! At the time we started writing this task, the existing dialyzer integra...
New
gabrielpoca
Hello everyone! I want to share with you something that I’m really proud of: https://stillstatic.io/ Still is a static site builder for...
New
Eiji
ExApi is a library that I’m developing now and hope release soon This library will allow to: list all apis list all api implementation...
New
Crowdhailer
Experimenting with this code. OK.try do user <- fetch_user(1) cart <- fetch_cart(1) order = checkout(cart, user) save_orde...
New
archan937
It is a well-know topic within the Elixir community: “To mock or not to mock? :)” Every alchemist probably has his / her own opinion con...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
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
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement