|
2 | 2 |
|
3 | 3 | ## 1. Summary
|
4 | 4 |
|
5 |
| -Getting the current time in applications is typically achieved using the `time()` or `microtime` functions, or by using a `new \DateTimeImmutable()` class. |
| 5 | +Getting the current time in applications is typically achieved using the `\time()` or `\microtime` functions, or by using a `new \DateTimeImmutable()` class. |
6 | 6 |
|
7 | 7 | Due to the nature of time progression, these methods cannot be used when predictable results are needed, such as during testing.
|
8 | 8 |
|
9 |
| -This `ClockInterface` aims to provide a standard way to consume time that allows interoperability, not only when consuming the "real" time, but also when predictable results need to be available. This avoids the need to use PHP extensions for testing or redeclaring the `time()` function in a local namespace. |
| 9 | +This `ClockInterface` aims to provide a standard way to consume time that allows interoperability, not only when consuming the "real" time, but also when predictable results need to be available. This avoids the need to use PHP extensions for testing or redeclaring the `\time()` function in a local namespace. |
10 | 10 |
|
11 | 11 | ## 2. Why Bother?
|
12 | 12 |
|
|
24 | 24 | Cons:
|
25 | 25 |
|
26 | 26 | * Extra overhead and developer effort to get the current time;
|
27 |
| -* Not as simple as calling `time()` or `date()`. |
| 27 | +* Not as simple as calling `\time()` or `\date()`. |
28 | 28 |
|
29 | 29 | ## 3. Scope
|
30 | 30 |
|
@@ -54,15 +54,15 @@ We have decided to formalize the existing practices used by several other packag
|
54 | 54 |
|
55 | 55 | Some of these provide interfaces and some rely on extending a clock class to mock the current time.
|
56 | 56 |
|
57 |
| -These implementations all provide a `now()` method which returns a `DateTimeImmutable` object. As the `DateTimeImmutable` object allows retrieving the Unix timestamp, by calling `getTimestamp()` or `format('u.U')`, this interface does not define any special methods to retrieve a Unix timestamp or any other time information that is not available from a `DateTimeImmutable` object. |
| 57 | +These implementations all provide a `now()` method which returns a `\DateTimeImmutable` object. As the `\DateTimeImmutable` object allows retrieving the Unix timestamp, by calling `getTimestamp()` or `format('u.U')`, this interface does not define any special methods to retrieve a Unix timestamp or any other time information that is not available from a `\DateTimeImmutable` object. |
58 | 58 |
|
59 | 59 | ### 4.2 Timezones
|
60 | 60 |
|
61 | 61 | Time by now is defined by interaction of electromagnetic radiation with the excited states of certain atoms, where the SI defines one second as the duration of 9192631770 cycles of radiation corresponding to the transition between two energy levels of the ground state of the caesium-133 atom at 0K. This means that retrieving the current time will always return the same time, no matter where it is observed. While the timezone defines *where* the time was observed, it does not modify the actual "slice" of time.
|
62 | 62 |
|
63 | 63 | This means that, for the sake of this PSR, the timezone is considered an implementation detail of the interface.
|
64 | 64 |
|
65 |
| -It is up to the implementation to make sure that the timezone is handled according to the business logic of the application. That is either by making sure that a call to `now()` will only return a `DateTimeImmutable` object with a known timezone (implicit contract) or by explicitly changing the timezone to be correct for the application. This can be done by calling `setTimezone()` to create a new `DateTimeImmutable` object with the given timezone. |
| 65 | +It is up to the implementation to make sure that the timezone is handled according to the business logic of the application. That is either by making sure that a call to `now()` will only return a `\DateTimeImmutable` object with a known timezone (implicit contract) or by explicitly changing the timezone to be correct for the application. This can be done by calling `setTimezone()` to create a new `\DateTimeImmutable` object with the given timezone. |
66 | 66 |
|
67 | 67 | These actions are not defined in this interface.
|
68 | 68 |
|
|
0 commit comments