gilbertbw

gilbertbw

Creating DateTime on a leap second and leap second list

Hello,

I am trying to work with DateTimes over leap seconds. I can’t create a %DateTime{} object on a leap second.

When using Tz I still get this issue:

My first attempt was to the ~U sigil:

iex> ~U[2016-12-30 23:59:60Z]
** (ArgumentError) cannot parse "2016-12-30 23:59:60Z" as UTC DateTime for Calendar.ISO, reason: :invalid_time
    (elixir 1.14.5) lib/kernel.ex:6260: Kernel.maybe_raise!/4
    (elixir 1.14.5) lib/kernel.ex:6239: Kernel.parse_with_calendar!/3
    (elixir 1.14.5) expanding macro: Kernel.sigil_U/2
    iex:5: (file)

Installing Tz and using it does not seem to help.

iex> DateTime.from_iso8601("2015-06-30T23:59:60Z", Tz.TimeZoneDatabase)
{:error, :invalid_time}

Trying to use ISO.Calendar directly does not work either

iex(19)> Calendar.ISO.datetime_to_string(2015, 12, 30, 23, 59, 60, {0, 0}, "Etc/UTC", "UTC", 0, 0, :basic)
** (FunctionClauseError) no function clause matching in Calendar.ISO.time_to_string/5    
    
    The following arguments were given to Calendar.ISO.time_to_string/5:
    
        # 1
        23
    
        # 2
        59
    
        # 3
        60
    
        # 4
        {0, 0}
    
        # 5
        :basic
    
    Attempted function clauses (showing 1 out of 1):
    
        def time_to_string(hour, minute, second, {ms_value, ms_precision} = microsecond, format) when is_integer(hour) and hour >= 0 and hour <= 23 and is_integer(minute) and minute >= 0 and minute <= 59 and is_integer(second) and second >= 0 and second <= 59 and is_integer(ms_value) and ms_value >= 0 and ms_value <= 999_999 and is_integer(ms_precision) and ms_precision >= 0 and ms_precision <= 6 and format === :basic or format === :extended
    
    (elixir 1.14.5) lib/calendar/iso.ex:1126: Calendar.ISO.time_to_string/5
    (elixir 1.14.5) lib/calendar/iso.ex:1306: Calendar.ISO.datetime_to_string/12
    iex:19: (file)

I belive this is the root of the issue, Calendar.ISO does not support leap second times. I’m not sure the Calendar is pluggable like the timezone is? Or if there is any third party, leap second supporting, Calendar implementation?

I was also trying to get a list of historic leap seconds (to convert from GPS time to a DateTime object) but I could not see an API in Tz to do this. So for now I have hardcoded a list of leapseconds in my application. Is there any built in way to get to this data in elixir or Tz?

First Post!

LostKobrakai

LostKobrakai

Calendar.ISO or really all of elixir’s core datetime handling does indeed not support leap seconds. Calendars are a behaviour though, so in theory you could have another calendar, which handles leap seconds. Practically the calendar alone is likely not enough though and it would need adjustments and considerations in places outside of those calendar implementations as well.

Iirc the latest stance of the elixir team I saw on github discussions was that leap second support would require more input and thought.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement