FAQ
Hello!

PHP's DateTime class has unexpected outcomes when dealing with the
transitions between Daylight Saving Time and Standard Time.

Properly defining, documenting and unit testing DateTime's behaviors is
important for PHP's future. This document seeks agreement on what the
expected behaviors should be.

Please take a moment to review the RFC and post any questions or
concerns here.

https://wiki.php.net/rfc/datetime_and_daylight_saving_time

Thanks,

--Dan

--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409

Search Discussions

  • Lester Caine at Oct 19, 2011 at 7:18 am

    Daniel Convissor wrote:
    PHP's DateTime class has unexpected outcomes when dealing with the
    transitions between Daylight Saving Time and Standard Time.

    Properly defining, documenting and unit testing DateTime's behaviors is
    important for PHP's future. This document seeks agreement on what the
    expected behaviors should be.

    Please take a moment to review the RFC and post any questions or
    concerns here.

    https://wiki.php.net/rfc/datetime_and_daylight_saving_time
    I feel that it is worth pointing out that handling the transitions is more a
    matter of making the right design choices in the underlying design. Having had
    to manage this for many years in timetabling systems for railways, I've come to
    one simple conclusion, and that is that the internal system always works with
    UTC times. All of the calculations and 'timing diagrams' therefore have unique
    and sequential times.

    The discussion then comes back to mapping UTC times to and from the local times
    which is a lot easier to manage?

    Rather than complex maths to try and correct the 'Type3' times, if they are
    automatically stored internally as a UTC time, and only the displayed
    information is varied, then the maths problem goes away? This will handle any
    complex daylight saving offsets cleanly? Having the same mechanism for all time
    values would also remove the need to have to handle that processing in the
    application?

    Moving to multi-timezone applications, by working purely in UTC in the stored
    data, all that the application requires is to know the timezone of the client (
    long time grip - this needs to be provided via the browser! ) or the timezone of
    the location. Single timezone only really exist if there is no daylight saving
    in the area being served, and then it simply does not matter if the system is
    using UTC on the server or the local time.

    --
    Lester Caine - G8HFL
    -----------------------------
    Contact - http://lsces.co.uk/wiki/?page=contact
    L.S.Caine Electronic Services - http://lsces.co.uk
    EnquirySolve - http://enquirysolve.com/
    Model Engineers Digital Workshop - http://medw.co.uk//
    Firebird - http://www.firebirdsql.org/index.php
  • Daniel Convissor at Oct 19, 2011 at 12:34 pm

    On Wed, Oct 19, 2011 at 08:18:50AM +0100, Lester Caine wrote:
    I've come to one simple
    conclusion, and that is that the internal system always works with
    UTC times. All of the calculations and 'timing diagrams' therefore
    have unique and sequential times.
    That is how PHP's DateTime works.

    --Dan

    --
    T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
    data intensive web and database programming
    http://www.AnalysisAndSolutions.com/
    4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
  • Daniel Convissor at Oct 24, 2011 at 2:36 pm

    I will move this to voting phase tomorrow unless I hear objections.

    Thanks,

    --Dan

    --
    T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
    data intensive web and database programming
    http://www.AnalysisAndSolutions.com/
    4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
  • Stas Malyshev at Oct 24, 2011 at 4:57 pm
    Hi!
    I will move this to voting phase tomorrow unless I hear objections.
    Not an objection but more a side question - is this related to fixing
    TLA timezones in general? Right now they fail in a multitude of
    scenarios which have nothing to do with transitions, such as:

    $t = new DateTime('2010-07-06 18:38:28 EDT');
    $ts = $t->format('U');
    $t->setTimestamp($ts);
    var_dump($t);



    --
    Stanislav Malyshev, Software Architect
    SugarCRM: http://www.sugarcrm.com/
    (408)454-6900 ext. 227
  • Daniel Convissor at Oct 24, 2011 at 6:55 pm
    Hi Stas:
    On Mon, Oct 24, 2011 at 09:57:51AM -0700, Stas Malyshev wrote:

    Not an objection but more a side question - is this related to
    fixing TLA timezones in general? Right now they fail in a multitude
    of scenarios which have nothing to do with transitions, such as:

    $t = new DateTime('2010-07-06 18:38:28 EDT');
    $ts = $t->format('U');
    $t->setTimestamp($ts);
    var_dump($t);
    Fun! I have a feeling that has the same underlying issue as
    https://bugs.php.net/bug.php?id=55253 which needs to be fixed as part of
    implementing the RFC.

    Thanks,

    --Dan

    --
    T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
    data intensive web and database programming
    http://www.AnalysisAndSolutions.com/
    4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
  • Daniel Convissor at Oct 25, 2011 at 3:06 pm
    Hi Folks:

    Please take a moment to review the DateTime transitions RFC and vote on
    it. I encourage voting on it to ensure we are all on the same page as
    to how PHP will handle transitions. Voting is open through 10/31.

    Read: https://wiki.php.net/rfc/datetime_and_daylight_saving_time
    Vote: https://wiki.php.net/rfc/datetime_and_daylight_saving_time/vote

    Thanks,

    --Dan

    --
    T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
    data intensive web and database programming
    http://www.AnalysisAndSolutions.com/
    4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
  • Thomas Nunninger at Oct 26, 2011 at 8:43 am
    Hi,

    sorry for late comment.

    You write: "The ST or DST modifiers can only be used when specifying times
    during the backward transition period. Using the modifiers at other times
    will throw an exception in object-oriented style code while procedural style
    code will return false without triggering errors."

    In my opinion this makes code more difficult as I need to check if the time is
    in the transition time. In my opinion it should be ok to add (D)ST all the
    time when it is (D)ST - and I don't see that it should be wrong (but I don't
    know enough about standard formats). Just ignore it internally if you don't
    need that information.

    Thomas


    Am Dienstag, 25. Oktober 2011 17:06:38 schrieb Daniel Convissor:
    Hi Folks:

    Please take a moment to review the DateTime transitions RFC and vote on
    it. I encourage voting on it to ensure we are all on the same page as
    to how PHP will handle transitions. Voting is open through 10/31.

    Read: https://wiki.php.net/rfc/datetime_and_daylight_saving_time
    Vote: https://wiki.php.net/rfc/datetime_and_daylight_saving_time/vote

    Thanks,

    --Dan

    --
    T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
    data intensive web and database programming
    http://www.AnalysisAndSolutions.com/
    4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
  • Stas Malyshev at Oct 26, 2011 at 5:12 pm
    Hi!
    Please take a moment to review the DateTime transitions RFC and vote on
    it. I encourage voting on it to ensure we are all on the same page as
    to how PHP will handle transitions. Voting is open through 10/31.
    Reading this RFC, I have some questions:

    1. Would this ST/DST be used on format() too? If yes, then we;d get a
    format that nobody but PHP can parse. If no, then we don't have
    roundtrip for format/parse to read the same date as you wrote.

    2. What is the intended use case for this syntax? I.e., if I am getting
    a date from somewhere, how this ST/DST is getting there? It can't come
    from the UI since no user and no external system would know how to
    generate these, and if it's supposed to be generated by the code, we get
    kind of chicken-and-egg problem here - to generate right ST/DST suffix,
    we already need to know what this date string says. So I'm a bit unclear
    on the use case here, especially if you're proposing to throw exceptions
    if the times are out of very specific hour - that means to create this
    suffix I'd have to know if we're in this hour or not - but how would I
    know that?

    --
    Stanislav Malyshev, Software Architect
    SugarCRM: http://www.sugarcrm.com/
    (408)454-6900 ext. 227
  • Derick Rethans at Oct 26, 2011 at 5:18 pm

    On Wed, 26 Oct 2011, Stas Malyshev wrote:

    Please take a moment to review the DateTime transitions RFC and vote
    on it. I encourage voting on it to ensure we are all on the same
    page as to how PHP will handle transitions. Voting is open through
    10/31.
    Reading this RFC, I have some questions:

    1. Would this ST/DST be used on format() too? If yes, then we;d get a
    format that nobody but PHP can parse. If no, then we don't have
    roundtrip for format/parse to read the same date as you wrote.
    No, why would it show up in format? The problem with expressing date and
    time when they exist twice is just an annoyance, and it's difficult to
    do a roundtrip in any case. We can add a format argument for it though,
    but I am not sure how useful that is.
    2. What is the intended use case for this syntax? I.e., if I am getting a date
    from somewhere, how this ST/DST is getting there? It can't come from the UI
    since no user and no external system would know how to generate these, and if
    it's supposed to be generated by the code, we get kind of chicken-and-egg
    problem here - to generate right ST/DST suffix, we already need to know what
    this date string says. So I'm a bit unclear on the use case here, especially
    if you're proposing to throw exceptions if the times are out of very specific
    hour - that means to create this suffix I'd have to know if we're in this hour
    or not - but how would I know that?
    If you don't know it, don't pass it in! Then PHP will guess, just as it
    does now and always has done. It's just an extra help in case you need
    to be specific about whether you want the ST or DST variant of "02:30".

    You can just use EDT/EST anyway, and that would work too (but of course
    not set a tz=3 timezone on the object).

    Derick

    --
    http://derickrethans.nl | http://xdebug.org
    Like Xdebug? Consider a donation: http://xdebug.org/donate.php
    twitter: @derickr and @xdebug
  • Stas Malyshev at Oct 26, 2011 at 5:45 pm
    Hi!
    If you don't know it, don't pass it in! Then PHP will guess, just as it
    does now and always has done. It's just an extra help in case you need
    to be specific about whether you want the ST or DST variant of "02:30".

    You can just use EDT/EST anyway, and that would work too (but of course
    not set a tz=3 timezone on the object).
    That's what I don't understand - so in the real code, what would be the
    use case where I'd want to use ST/DST? I.e., if I know the exact time, I
    could just use the timestamp or GMT time which doesn't have transitions.
    If I know only the formatted string, how I know if I should add ST/DST
    or not? I'm a bit unclear on that - how I can make a code that would be
    able to use this syntax.
    --
    Stanislav Malyshev, Software Architect
    SugarCRM: http://www.sugarcrm.com/
    (408)454-6900 ext. 227
  • Daniel Convissor at Oct 29, 2011 at 12:00 pm

    Hi Stas:

    That's what I don't understand - so in the real code, what would be
    the use case where I'd want to use ST/DST? I.e., if I know the exact
    time, I could just use the timestamp or GMT time which doesn't have
    transitions.
    Yeah, this stuff is very edge case. It is for use when one needs to
    have the transition information and create a time zone object that's in
    the repeated period during a backward transition. One case it's needed
    is in unit testing DateTime.

    Thanks,

    --Dan

    --
    T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
    data intensive web and database programming
    http://www.AnalysisAndSolutions.com/
    4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedOct 18, '11 at 9:46p
activeOct 29, '11 at 12:00p
posts12
users5
websitephp.net

People

Translate

site design / logo © 2022 Grokbase