-
Couldn't load subscription status.
- Fork 2.8k
Add answer to a recurring question re UTC #1257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add answer to a recurring question re UTC #1257
Conversation
The question "why not to convert to UTC" comes up very frequently so Larry asked to add the answer to the meta-docs for PSR-20.
proposed/clock-meta.md
Outdated
|
|
||
| ### Why not simply convert all times to UTC? | ||
|
|
||
| Timezones change! Regularily! And unforseeably! So when you are converting a DateTime in the future to UTC you are using the offset that is known today to convert from the local time to UTC. When that offset changes between now and the datetime then you have no chance to adapt to that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're talking about timestamp, it's not only timezones. DST is problem by itself for delivery service i.e. you order to deliver a package at day X at 12:00 and that's converted to int. Then DST comes into effect some days before and you get your package either at 11:00 or 13:00 instead of 12:00.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Regularily/Regularly/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not an issue as that information is encoded into the timezone-information.
Remember: A timezone is a geographical region that is observing the same date and time by governmental definition. Such a timezone is identified by a timezone-identifier such as Europe/Moskow.
Do not confuse timezones with offsets that are defining the difference to the time-standard (which can be either GMT or UTC) or with named offsets like MSK that cover some (but not all) timezones that are observing a certain offset. A timezone can be referenced via different named offsets at different times due to DST changes.
So when using a timezone, the DST information is available. When using an offset then you do not know whether that offset is standard-time or daylight saving time.
|
Notice that there is a case when storing the time in local time with timezone can loose information. If we would store |
|
@hvanoch Hm. Another fun and exciting problem... I can't tell if that's an argument for or against using UTC, though, just that datetime is fugly. 😄 |
|
That is indeed correct. And in a perfect world you would store As long as it is not supported to call Nevertheless: this one possible lost hour for future datetimes is much less hassle than converting everything back and forth to and from UTC. And Log-like Information (everything that happens right now can easily be stored in UTC (Yes. it might happen that the calculation from local time to UTC might be broken due to changes that should have been applied now have not yet found their way into the TZDB due to governments thinking one day in advance is enough time for everyone to react) For the ClockInterface though that is irrelevant as the clock returns a slice of the current time and this one slice will also during the transition backwards return the correct information so when your business-logic calls |
|
The analogy based argument isn't really convincing for me. At this point I've essentially resigned myself to the fact that the timezone will be undefined, but the argument for it needs to be solid enough to avoid 10 years of people whining about it. (See also: PSR-7.) I don't feel like this is. |
From advocating the use of local times (which is hard to do for local times) this argumentation moves towards explaining that the interface itself, the explicit contract, does not care about the implementation and with this rather open explicit contract everyone can also implement their own implicit contract to use "UTC" or whatever they want. If they want to. The interface itself is as open as possible while at the same time being as strict as necessary
aa89846 to
d366693
Compare
|
I've redone the argumentation completely away from advocating the use of local time over UTC (which is still a good idea, but kinda hard to convince people that it makes sense even for current date-times) over to trying to make it clear that the interface is as open as possible while at the same time being as strict as necessary. Not enforcing UTC on the explicit contract that the interface defines does not hinder an implicit contract on the implementation level which defines that the interface will always return objects with a certain timezone preset. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The addition itself is fine. Minor issues are easy to be fixed.
Co-authored-by: Alexander Makarov <[email protected]>
Co-authored-by: Alexander Makarov <[email protected]>
Co-authored-by: Alexander Makarov <[email protected]>
Co-authored-by: Alexander Makarov <[email protected]>
Co-authored-by: Alexander Makarov <[email protected]>
|
What is the hold-up here - can we move this forward? |
| use-cases that do require something else will have to explicitly work around that or find other ways of | ||
| handling the problem, the contract tries to solve as the contract does not fit the needs. This is different | ||
| from the issue of i.e., immutability which can also not be enforced on the language level but which is | ||
| necessary to adhere to other calls on the contract. IN the case of the `clock`-interface there will be no |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| necessary to adhere to other calls on the contract. IN the case of the `clock`-interface there will be no | |
| necessary to adhere to other calls on the contract. In the case of the `clock`-interface there will be no |
Typo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the "English flow" could be tweaked, but content seems good to me.
|
@cseufert ping... Github shows you still active in general, so reaching out to you here rather than just on Discord to confirm you're still interested in this PSR... ? |
|
@cseufert, as Editor, you can merge these, right? |
|
I cant merge it, can only approve it for merging |
Ok, I'll find out who can, and get both open PRs merged. Thanks for getting them both approved, and welcome back ;-) |
|
Done, my pleasure! 😄 |
The question "why not to convert to UTC" comes up very frequently so
Larry asked to add the answer to the meta-docs for PSR-20.