travisf

travisf

Timex.now(timezone)

I’m sending a daily report which should be showing the current time set to mountain daylight time. However, after daylight savings time the report has been consistently an hour behind. I if I run Timex.now("MDT") in the terminal I will get the current time in MDT. Our report is generated much the same way: {:ok, date} = Timex.format(Timex.now("MDT"), "{h12}:{m} {am}") Again, this works in my terminal but not on the report that gets sent out; it’s an hour behind.
However, if I change Timex.now("EST") I will get Eastern Time but an hour behind (right now it’s 11:15 EST but I’m getting 10:15).
Any ideas on what the cause of this might be? Is there a Phoenix config somewhere that sets time?

Marked As Solved

travisf

travisf

I think I’ve realized the issue. Our code was actually using Timex.now("MST") I thought MST and MDT were interchangeable or that Timex would account for daylight saving time. It seems like MST will be incorrect about 8 months out of the year, I can’t verify MDT seems like America/Denver is the way to go.

@dimitarvp your daylight savings mention got me on this track.

Also Liked

thojanssens1

thojanssens1

Perfect :ok_hand:

Just to show you what I meant:

iex> Tzdata.zone_exists?("MST")
true
iex> Tzdata.zone_exists?("MDT")
false # <- see here
iex> Timex.now("MDT")
#DateTime<2020-03-26 19:55:03.637000-06:00 MDT MST7MDT>

“MDT” doesn’t exist as a time zone ID, but Timex will find a time zone ID that contains the string “MDT”, and finds MST7MDT, whish does change according to US DST rules.

Ouch… I don’t know why Timex would not return an error instead honestly, that leads to bugs ;-p

If one ever needs a fixed offset, better use a time zone ID such as Etc/GMT-7.

Anyway, it was just to complete the information. You use the right time zone ID now.

thojanssens1

thojanssens1

I think I confuse you more:) but the IANA tz database can be very confusing.

“MST” can be used as a time zone ID; but for example “MDT” seems not to be a valid time zone ID.

^ So this should actually throw an error

Anyway, this is not what you want. You want to use “America/Denver” as a time zone ID.

When you use “America/Denver” as a time zone ID, the offset will change throughout the year:
-07:00/MST and -06:00/MDT

LostKobrakai

LostKobrakai

This is actually how timezones work. Timezone names alike MDT are names for certain UTC offsets. Area names like “America/Denver” are the names, which define which of those timezones is in effect in a certain area of the world at a certain time.

Last Post!

thojanssens1

thojanssens1

I had that feeling :sweat_smile:

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
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
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
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
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
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40082 209
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
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

We're in Beta

About us Mission Statement