6 Replies - 1234 Views - Last Post: 16 July 2010 - 10:40 PM Rate Topic: -----

#1 Crimson Wings   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 215
  • Joined: 11-July 09

DST "Dilemma"

Posted 16 July 2010 - 04:23 PM

Hi guys.
So I am making my own DateTime class for PHP. I found a "dilemma" though, related to the DST.

Suppose a user posts in my custom made made forums at 01:23 PM when the DST is in effect. Then we find ourselves a few months later, when the DST is no longer in effect: What time should I show in that post, 01:23 since it was made at that time with DST, or 12:23 since the DST is no longer in effect?
Is This A Good Question/Topic? 0
  • +

Replies To: DST "Dilemma"

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: DST "Dilemma"

Posted 16 July 2010 - 04:25 PM

first option, time zones usually have a separate name when DST is in effect (e.g. CET & CEST in Europe). and even if you were omitting those names, you can re-calculate it from the date, since DST is usually in a certain defined date range.

This post has been edited by Dormilich: 16 July 2010 - 04:26 PM

Was This Post Helpful? 0
  • +
  • -

#3 Crimson Wings   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 215
  • Joined: 11-July 09

Re: DST "Dilemma"

Posted 16 July 2010 - 05:00 PM

Okay yeah, I can recalculate everything, but I need to know whether I need to recalculate everything depending on whether DST is in effect or not =P.

What is making this complex is the fact that I don't know whether the recalculation is necessary. I could show the post was made at 01:23 when DST is in effect, but should I show the post was made at 12:23 when DST is not effective, or should it show the post was indeed made 01:23? It's really a hard question for me, and I can't see how sites answer to this dilemma because I can't test anything because my country doesn't use DST.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: DST "Dilemma"

Posted 16 July 2010 - 05:04 PM

if the timezone, you’re displaying the date in, has DST, then calculate as if the DST is in effect. if July 2nd is in DST, then not calculating with it is wrong, because everyone would expect it to be this way. however, you can get around that by giving the dates in UTC. that is always the same, whether there is DST or not.
Was This Post Helpful? 0
  • +
  • -

#5 Crimson Wings   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 215
  • Joined: 11-July 09

Re: DST "Dilemma"

Posted 16 July 2010 - 05:47 PM

Wait wait, don't think I understand. If I get all my times in UTC (the date() function does that), I don't have to attempt to use any DST settings? Because it will be fetched properly with the date() function.
Was This Post Helpful? 0
  • +
  • -

#6 grimpirate   User is offline

  • Pirate King
  • member icon

Reputation: 149
  • View blog
  • Posts: 717
  • Joined: 03-August 06

Re: DST "Dilemma"

Posted 16 July 2010 - 08:13 PM

You should use the time() function to store a proper date. This UTC is regardless of DST or not as it counts number of seconds elapsed since a particular date. Your code should then calculate DST where it is pertinent or not. If you take a look at the date() function's editing parameters there is one that corresponds to showing whether DST is in effect or not.
Was This Post Helpful? 1
  • +
  • -

#7 Crimson Wings   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 215
  • Joined: 11-July 09

Re: DST "Dilemma"

Posted 16 July 2010 - 10:40 PM

I LOVE you for pointing that out, grimpirate. I though the date() function fetched a UTC time, turns out I was wrong, and thanks to you pointing that out, I solved the problem before I introduced some nasty bugs to my site that it would take me ages to find.
I solved my little dilemma too, and I will show the time a post was posted in the DST even when it is no longer in effect.

My problem is now is to detect when the DST is in effect and when is not. I just did some research since we don't use DST in my country, and I never though the start and end of the DST varied from year to year.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1