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

aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
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
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from 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
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
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
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
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
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

We're in Beta

About us Mission Statement