Skip to content

DateInterval: significant difference in behaviour deserves to be formally noted #5653

Description

@danbettles

Good morning,

There's a user-contributed note on the documentation page for DateInterval::createFromDateString() that identifies a significant difference in behaviour that I think deserves to be formally noted in the official documentation above it.

"Example #1 Parsing valid date intervals" implies -- to me, at least -- that instantiating a DateInterval using an ISO string is equivalent to creating an interval using DateInterval::createFromDateString(), but the code in the user-contributed note does indeed demonstrate that DateInterval objects are definitely not all created equally. (I tested his code in my own environment (PHP 8.5.7 on Debian 13).)

To me, the issue is that you'll get different results when I really don't think you'd expect them. I think it'd be really helpful to acknowledge the difference in behaviour, and it'd probably be helpful if the documentation were to identify use-cases in which the differences make sense.

It's a tricky one, for sure. In the context of adding a DateInterval, it does make sense that you should get the same time tomorrow if you add 1440 minutes. But in the real world, where daylight saving applies, the actual, reported time would be adjusted because we lose/gain an hour 🤯

Many thanks

From manual page: https://php.net/dateinterval.createfromdatestring


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions