@@ -140,44 +140,34 @@ _**Note:** Order descending chronologically._
140
140
141
141
## 9. FAQ
142
142
143
- ### Why not simply convert all times to UTC?
144
-
145
- ` now() ` should be considered to be the equivalent of checking your wallclock at home or your wristwatch.
146
- It usually gives you the current point in time at your current location. And from that point you can
147
- then – if you need to – transpose to other timezones. That makes life much easier than setting your
148
- wallclock to UTC and having to transpose every time you want to communicate with someone.
149
-
150
- As this interface is a generic interface it can not impose a certain usecase and therefore needs to
151
- be as open as possible. That means to allow people to use any DateTimeImmutable object possible.
152
- And that also means to make sure users understand the consequence of that. Which is that it is
153
- the users requirement to make sure the returned DateTimeImmutable object conforms to their requirements.
154
-
155
- Much as you would tell someone calling you on the phone your local time when they ask you for the time.
156
- And if they have some special requirements they need to make sure that they handle the information
157
- you gave them properly.
158
-
159
- Besides that it has shown that transposing times is usually error prone and should be avoided at
160
- all cost and only done if absolutely necessary.
161
-
162
- That is due to timezones being based on political definitions. Therefore they change: regularily and unforseeably.
163
- And sometimes even for past times. So when you are converting a DateTime to UTC you are using the
164
- offset that is known today to convert from the local time to UTC. When that offset changes due
165
- to political decisions then you have no chance to adapt to that.
166
-
167
- An Example: In summer 2016 you scheduled an event in turkey for 14:00 on the 25th of December 2016.
168
- With the information known in summer 2016 you would calculate that that is 12:00 UTC. What you couldn't imagine is,
169
- that the Government decided later that year to stay on daylight saving time and not go back to standard time for the
170
- winter. So when the time comes you would show up at 12:00 UTC. With the then relevant timezone information that would
171
- be 15:00 local time. But your appointment was at 14:00 local time. Would you have * not* converted to UTC you would
172
- have stored ` 14:00 Asia/Istanbul ` and you would have been on time.
173
-
174
- ** Note:** While this might only seem relevant for
175
- future datetimes it illustrates that transposing between timezones can cause much more confusion than just keeping
176
- and using the existing timezone information. And as there have been requests to the timezone database maintainers like
177
- "We changed from offset x to offset y 2 weeks ago" or "we will change from offset x to offset y tomorrow" that can also
178
- concern your current conversion from local time to UTC. So to avoid confusion is to avoid transposing between timezones
179
- as much as possible and save it to the last possible moment.
180
-
181
-
182
-
143
+ ### Why not simply use UTC?
144
+
145
+ There are different reasons why this interface does not enforce a specific timezone.
146
+
147
+ For one thing there is a purely technical reason. The interface provides an explicit contract. Part of this
148
+ contract is the value that is returned by the ` now ` -function. The only thing that currently can explicitly
149
+ be enforced on the language level is, that the returned value is of type ` DateTimeImmutable ` . There
150
+ currently is no way to enforce that this object has a certain timezone as its value. So from a language
151
+ level perspective there is no way to explicitly enforce a certain timezone in the returned object.
152
+
153
+ On the other hand there is also a logical reason. The explicit contract should be usable in all situations
154
+ where one needs a way to retrieve the current time. And on the contract level we should not make an
155
+ assumption about what the caller might need. So would the contract define that only UTC is returned, then
156
+ use-cases that do require something else will have to explicitly work around that or find other ways of
157
+ handling the problem the contract tries to solve as the contract does not fit the needs. This is different
158
+ from the issue of i.e. immutability which can also not be enforced on the language level but which is
159
+ necessary to adhere to other calls on the contract. IN the case of the ` clock ` -interface there will be no
160
+ other calls.
161
+
162
+ And most important of all, the explicit contract provided by this interface does not reduce a users
163
+ possibilities to use an implicit contract within their application, that defines that the interface
164
+ will only return ` DateTimeImmutable ` s with a specific timezone set. And whether that is ` UTC ` or reduce
165
+ ` Antarctica/Troll ` is completely up to the user.
166
+
167
+ The explicit contract that is defined by the interface does not limit a user in what they are doing. It
168
+ tries to solve the problem of getting the current time in a reliable way. Which view on the current time
169
+ that is, is not part of the explicit contract.
170
+
171
+ So all in all: This interface tries to be as open as possible while at the same time being as
172
+ strict as necessary.
183
173
0 commit comments