In elixir need some suggestions on handling daylight savings time without having to take systems down
Especially for medication administration for patients where time given is extremely important.
Have a Ghost hour 01:00 - 02:00 for fall back.
If you follow best practices, i.e.:
- convert any datetime to UTC at the system boundaries, as close to the user as possible
- in business parts of the application deal with UTC exclusively
- in database, store UTC only
- convert to local timezone when giving output to the user
There should be no issues with timezones. The new
DateTime struct includes timezone, and libraries like
calendar can help you with conversions. Ecto since 2.1 (currently in rc) supports native elixir calendar types and offers a
utc_datetime type, that expects database to store the time in UTC and gives you the
DateTime structs in UTC timezone.
What about making use of the server’s system time?
Usually you can set a timezone and specify a time server which the server uses to sync the correct time.
I cannot overstate how important it is to be using a time format in your storage that is agnostic to all that, like UTC or unixtime or so. You should never absolutely ever be thinking about something like daylight savings time or anything of the sort unless you are converting the internal backend format to a user-displayable value, ever. I’ve personally in my 20 years doing this never seen a system that stores anything else that behaves well…
Yeah I agree. I’m quite honestly kind of confused why daylights savings time would require taking any system down at all ever, maybe someone can explain the motivation here?