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?

#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

Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
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
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
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

Other popular topics Top

SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
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
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
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

We're in Beta

About us Mission Statement