views:

70

answers:

3

this might be stupid question, but ill ask anyway.

do i really need to implement gmt on site to get proper timestamp on a post? well im building a site like twitter. my feeds are working fine and showing me the time i need, like it shows "posted 11 minutes, posted yesterday, posted 5 days ago.. " just like this site, so i was thinking it should work for everyone properly, what you think? or do you think i need to implement gmt on it and do you recommand or have any article on it for implementing it proper way?

sorry if this sound stupid :O

+1  A: 

It's a good point, but consider the case when 1 day ago suggests "yesterday", and it's currently 1:05am for some user. I suppose if you're using days = hours % 24 rather than days = datediff(then, now).days, then it would work fine.

I think the issue is: how accurate does your site need to be? If it's for medical readings, so someone can know when their medication is due, then yes, you want to account for timezones properly, and give accurate times rather than just "x ago". If it's just for "joe said hi two days ago", though, then it's not a big deal.

Lee B
well i have my own method, but it still need two dates to get the posted weeks/days/minutes/seconds. how can i do days, hours % 24? like you mention above.. im coding in php.
Basit
+1  A: 

When you're talking about time periods like hours, minutes and seconds, then that's not even anything to do with timezones. Look at the timestamp of when it was created, and look at the timestamp now. Do some subtraction and voila!

The only time it's slightly strange is when you are in the range of a couple of days. Does yesterday mean "some time in the 24 hours prior to the last midnight", or does it mean "over 24 hours ago"? In any case, if the only level of granularity you are providing is "days", then once it's gone past about 2 days, then it doesn't really matter.

One nice way to avoid confusion is the same method used here on SO: put the readable, friendly date on the screen ("yesterday"), but put the exact time (in GMT or in the user's TZ) as a tooltip.

nickf
+1  A: 

In the long term, it is best to store time stamps always in GMT/UTC, no matter how the user interface is rendered. This has two advantages:

  • when changing the UI at some point, you won't need to touch the data
  • it gives a clear design guideline (in terms of a clear right/wrong decision): any specific function dealing with time can be independently reviewed wrt. processing timestamps in UTC

As for specific programming guidelines: these depend very much on the functionality you want to execute. Most of the time, you need either from-utc or to-utc operations.

Martin v. Löwis