Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
    
After some thought, the author's timezone drops out. It would be much more complicated to filter entries that all use a different timezone. –  sbaechler Aug 21 '12 at 12:33
add comment

2 Answers 2

up vote 12 down vote accepted

I'd go with UTC. It has several advantages:

  1. It's universal and doesn't change with daylight saving time.
  2. It won't change if your server changes timezone.
  3. It won't change if authors change timezone.
  4. 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.

share|improve this answer
    
The killer argument here is number 2. URLs might change if the server changes timezone. Number 1 and 3 are not really an issue since the timezone information is stored in the date as well. –  sbaechler Aug 21 '12 at 12:35
add comment

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.

share|improve this answer
    
The date is already stored as UTC in the database. This question is about the permalink only. –  sbaechler Aug 21 '12 at 7:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.