1 | <?php |
||
25 | class DateTimeHasher implements Hasher |
||
26 | { |
||
27 | /** |
||
28 | * Checks whether the current relation is considered equal to another. |
||
29 | * |
||
30 | * Since this class is stateless, its instances will always be considered |
||
31 | * equal if they are of the same type. |
||
32 | */ |
||
33 | 4 | public function equals(Equatable $other) |
|
37 | |||
38 | /** |
||
39 | * Checks whether the given values are considered equivalent. |
||
40 | * |
||
41 | * This equivalence relation considers two instances of {@link DateTime} to |
||
42 | * be equivalent if they have the same date, time and time zone. |
||
43 | * |
||
44 | * @param DateTime $left The date/time to compare. |
||
45 | * @param mixed $right The value to compare. |
||
46 | * |
||
47 | * @return boolean Returns `true` if the date/time are considered |
||
48 | * equivalent, `false` otherwise. |
||
49 | */ |
||
50 | 34 | public function equivalent($left, $right) |
|
69 | |||
70 | /** |
||
71 | * Returns a hash code for the given DateTime instance. |
||
72 | * |
||
73 | * The resulting hash code is guaranteed to be _coherent_ with the |
||
74 | * {@link equivalent()} method, which means that for any references |
||
75 | * `$x` and `$y`, if `equivalent($x, $y)`, then `hash($x) === hash($y)`. |
||
76 | * It is computed by summing the values returned by the methods |
||
77 | * {@link \DateTimeInterface::getTimestamp()} and |
||
78 | * {@link \DateTimeInterface::getOffset()}, as shown in the following |
||
79 | * expression: |
||
80 | * |
||
81 | * ```php |
||
82 | * $hashCode = $date->getTimestamp() + $date->getOffset(); |
||
83 | * ``` |
||
84 | * |
||
85 | * @param DateTime $value The date/time to compare. |
||
86 | * |
||
87 | * @return integer The hash code. |
||
88 | * |
||
89 | * @see equivalent() |
||
90 | */ |
||
91 | 10 | public function hash($value) |
|
99 | |||
100 | /** |
||
101 | * Asserts the given value is an instance of {@link DateTime}. |
||
102 | * |
||
103 | * @param mixed $value The value to assert. |
||
104 | * |
||
105 | * @throws UnexpectedTypeException If the given value is not an instance of |
||
106 | * {@link DateTime}. |
||
107 | */ |
||
108 | 34 | protected function assertDateTime($value) |
|
114 | } |
||
115 |