How to get the delta value from Time Zone

I agree, keeping everything in UTC and just converting for display purposes is the most consistent and least error prone way to do it, and would recommend following that first. There are reasons you might want to depart from that and use local times instead - it depends though on what you are doing. So here are some examples:

Sometimes the opera is broadcast live and people around the world can watch it in their local cinema in addition to the audience watching the live performance. So we have an app that tells users the timetable for these events. The show is on in New York starting at 7pm local time there. In UTC that is 12 midnight. A cinema in San Fransisco is showing it, and the start time there will be 4pm. Broadcasting means that this event is taking place at the same moment all over the world, so using UTC as a common currency to translate accross time zones makes sense.

You go on holiday and book a hire car to collect at the airport. You know your flight is due to get in at 11 and its going to take a while to get out of the airport so you put 11:30 as the collection time for the car. It doesn’t really make sense to translate this into UTC as it is a local event only. If you translate it into UTC and email the user to remind them of the pick up time in their home local time the message might say “remember your car booking at 03:30”. In that case you probably don’t even want to use Time.Posix although it does not contain the timezone so can be used for local times. I would just create my own data type to hold the local times for this application:

type alias LocalTime = 
    { hour : Int
    , minute : Int } -- That's all thats really needed for the car rental app.

Hope that helps you to decide which way is best for your particular application.

1 Like