Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you determine the current date and time in the user's local time zone in Elm?

Tags:

elm

I want to get a Date in elm that represents the user's local date and time. I have looked at the core Date module as well as the elm-time package.

The elm-time package has a ZonedDateTime, but a TimeZone value must be supplied to it, and therefore, the time zone must be known ahead of time.

At its core, this issue is about reliably determining the user's timezone. The best solution I've come up with, which is too naive to be considered acceptable, is to pass the user's timezone offset via javascript as an application flag and modify a UTC date accordingly.

like image 331
w.brian Avatar asked Nov 20 '22 06:11

w.brian


1 Answers

With the current 0.19.1 version:

  • Use Time.here : Task x Zone to get the current time zone.
  • Use Time.now : Task x Posix to get the current date.
like image 170
adauguet Avatar answered Dec 18 '22 12:12

adauguet