I wanted to add timezone support to my blog app but got stuck with a design problem.
Every post has a published_on field which stores the publication date in a timezone aware format (UTC converted to user’s timezone). So far so good. But the permalink of a post is created from the publication date as well. It has the format: /year/month/day/slug.
This of course is not timezone aware and must be the same for all users around the world. So I have to define a timezone to use for the permalink. There are three options which make sense:
- The author’s timezone
- UTC
- The default timezone of the server.
Which would be the most appropriate?
1
I’d go with UTC. It has several advantages:
- It’s universal and doesn’t change with daylight saving time.
- It won’t change if your server changes timezone.
- It won’t change if authors change timezone.
- There are standard conversions between UTC and local time zones.
Despite the problems it sometimes causes (confusion over the “day”) it can be explained and is consistent.
1
We had the same problem in our project and we persisted all the time in database as UTC.
The UTC time is converted to local timezone of the user when accessing / reading the data. This simplified our entire design.
1