Handling dates, times and timezones correctly

There are a few things:

  • You want to store wall datetimes and utc datetimes for future points in time, as the timezone definition could change between now and the event:

http://www.creativedeletion.com/2015/03/19/persisting_future_datetimes.html

  • Dates by themself don‘t really have timezones. You could have an interval of datetimes, which span the time of a certain date in a timezone though.

  • *_tz columns in postgres don‘t actually do much when using ecto. They don‘t store timezone information, but try to make sure a dt is converted to utc, which ecto already enforces. Unless you use other systems as well to use the db I‘d stick to non *_tz columns.

  • Using separate date and time columns for a single datetime is imo a really bad idea. If you want datetime or date to be possible use a datetime and a date column.

3 Likes