notsure

notsure

Hello all and thanks in advance!

I am writing tests to handle time changes from DST and back. I cannot seem to trigger the %Timex.Ambiguous{} response from Timex.to_datetime():

iex(10)> Timex.to_datetime({{2023, 11, 5},{01, 30, 00}}, "US/Mountain") 
#DateTime<2023-11-05 01:30:00-06:00 MDT US/Mountain>

I originally was setup on {:timex, "~> 3.6.1"}, where I was able to trigger the correct response, but then I upgraded to {:timex, "~> 3.7.11"}. I don’t know if that change caused the response to change as I was not looking for it (was still learning how Timex works). But now that I know what I am looking for I have done a mix.deps clean --all and rebuilt to {:timex, "~> 3.6.1"}. I still do not get the expected result.

Any ideas what I am doing wrong?

Showing Posts 1 to 3

LostKobrakai

LostKobrakai

I’d suggest sticking to core APIs wherever possible:

iex(1)> DateTime.new(~D[2023-11-05], ~T[01:30:00], "US/Mountain")
{:ambiguous, #DateTime<2023-11-05 01:30:00-06:00 MDT US/Mountain>,
 #DateTime<2023-11-05 01:30:00-07:00 MST US/Mountain>}

Edit: This requires a timezone database (like tzdata) to be installed and configured for usage.

mathieuprog

mathieuprog

It can only work with tzdata as it has been designed for the moment.

notsure

notsure OP

I was missing the Tzdata — tzdata v1.1.4 piece. Followed the directions to setup tzdata. Although when Timex is installed, it does install the tzdata dependency, but setting up tzdata requires more effort. Even with installing tzdata and performing the setup, I was not able to get the Ambiguous response with Timex but was able to with DateTime.new():

  def test do
    ts = timestamp(~D[2023-03-12], ~T[01:30:00], "US/Mountain")
    IO.inspect(ts, label: "test a valid time")
    ts = timestamp(~D[2023-03-12], ~T[02:30:00], "US/Mountain")
    IO.inspect(ts, label: "test a time that should not exist")
    ts = timestamp(~D[2023-11-05], ~T[01:30:00], "US/Mountain")
    IO.inspect(ts, label: "test a time that is ambiguous")
  end
  def timestamp(date, time, time_zone) do
    case DateTime.new(date, time, time_zone) do
      {:ok, timestamp} -> timestamp
      {:gap, timestamp1, timestamp2} -> # spring ahead, time in hour gap
        timestamp(date, Time.add(time, 3600, :second), time_zone)
      {:ambiguous, timestamp1, timestamp2} -> # fall back; which 1:30?
        timestamp1
      timestamp -> timestamp
    end
  end

Thanks for all the help and quick response!

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
perzanko
Do we have maintainer of absinthe-graphql/dataloader here? We have a PR that we’d like to merge to the library. Relatively small additive...
New

Other Trending Topics Top

rodloboz
Hi everyone! I’d like to share Fude (筆, “brush”), a charting library for Phoenix LiveView. I built it for dashboards and reports where y...
New
dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews