tz icon indicating copy to clipboard operation
tz copied to clipboard

Bug when using `:nanosecond` precision with DateTime.add/3

Open ceolinrenato opened this issue 6 months ago • 0 comments

Running the below raises an exception right now:

iex(2)> DateTime.add(DateTime.utc_now(), 1_000, :nanosecond, Tz.TimeZoneDatabase)
** (FunctionClauseError) no function clause matching in Tz.TimeZoneDatabase.iso_days_to_gregorian_seconds/1    
    
    The following arguments were given to Tz.TimeZoneDatabase.iso_days_to_gregorian_seconds/1:
    
        # 1
        {739794, {60856908923000, 86400000000000}}
    
    Attempted function clauses (showing 1 out of 1):
    
        defp iso_days_to_gregorian_seconds({days, {parts_in_day, 86_400_000_000}})
    
    (tz 0.28.1) lib/tz/time_zone_database.ex:135: Tz.TimeZoneDatabase.iso_days_to_gregorian_seconds/1
    (tz 0.28.1) lib/tz/time_zone_database.ex:14: Tz.TimeZoneDatabase.time_zone_period_from_utc_iso_days/2
    (elixir 1.18.2) lib/calendar/datetime.ex:754: DateTime.shift_zone_for_iso_days_utc/5
    (elixir 1.18.2) lib/calendar/datetime.ex:1680: DateTime.add/4
    iex:2: (file)

I've submitted a PR to fix it https://github.com/mathieuprog/tz/pull/34

ceolinrenato avatar Jun 27 '25 16:06 ceolinrenato