| @@ 11-42 (lines=32) @@ | ||
| 8 | * @author Kristjan Siimson <[email protected]> |
|
| 9 | * @package Direction\Domain |
|
| 10 | */ |
|
| 11 | class Decreasing implements Direction |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * @param Period $period |
|
| 15 | */ |
|
| 16 | public function next(Period $period) |
|
| 17 | { |
|
| 18 | $period->previous(); |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @param string $first |
|
| 23 | * @param string $second |
|
| 24 | * @return int |
|
| 25 | */ |
|
| 26 | public function compare($first, $second) |
|
| 27 | { |
|
| 28 | // Discard time info |
|
| 29 | $first = substr($first, 0, 10); |
|
| 30 | $second = substr($second, 0, 10); |
|
| 31 | ||
| 32 | if ($first === $second) { |
|
| 33 | $result = 0; |
|
| 34 | } else if (new \DateTime($first) > new \DateTime($second)) { |
|
| 35 | $result = -1; |
|
| 36 | } else { |
|
| 37 | $result = 1; |
|
| 38 | } |
|
| 39 | ||
| 40 | return $result; |
|
| 41 | } |
|
| 42 | } |
|
| 43 | ||
| @@ 11-42 (lines=32) @@ | ||
| 8 | * @author Kristjan Siimson <[email protected]> |
|
| 9 | * @package Direction\Domain |
|
| 10 | */ |
|
| 11 | class Increasing implements Direction |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * @param Period $period |
|
| 15 | */ |
|
| 16 | public function next(Period $period) |
|
| 17 | { |
|
| 18 | $period->next(); |
|
| 19 | } |
|
| 20 | ||
| 21 | /** |
|
| 22 | * @param string $first |
|
| 23 | * @param string $second |
|
| 24 | * @return int |
|
| 25 | */ |
|
| 26 | public function compare($first, $second) |
|
| 27 | { |
|
| 28 | // Discard time info |
|
| 29 | $first = substr($first, 0, 10); |
|
| 30 | $second = substr($second, 0, 10); |
|
| 31 | ||
| 32 | if ($first === $second) { |
|
| 33 | $result = 0; |
|
| 34 | } else if (new \DateTime($first) > new \DateTime($second)) { |
|
| 35 | $result = 1; |
|
| 36 | } else { |
|
| 37 | $result = -1; |
|
| 38 | } |
|
| 39 | ||
| 40 | return $result; |
|
| 41 | } |
|
| 42 | } |
|
| 43 | ||