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
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
DateIntervalusing an ISO string is equivalent to creating an interval usingDateInterval::createFromDateString(), but the code in the user-contributed note does indeed demonstrate thatDateIntervalobjects 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