@@ -15,13 +15,15 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | public function __construct($interval = 'PT0S') |
| 17 | 17 | { |
| 18 | - if ($interval === NULL) |
|
| 19 | - $interval = 'PT0S'; |
|
| 18 | + if ($interval === NULL) { |
|
| 19 | + $interval = 'PT0S'; |
|
| 20 | + } |
|
| 20 | 21 | $this->refDT = new DateTimeImmutable('midnight'); |
| 21 | 22 | $invert = FALSE; |
| 22 | 23 | if ($interval instanceof \DateInterval) { |
| 23 | - if ($interval->invert) |
|
| 24 | - $invert = TRUE; |
|
| 24 | + if ($interval->invert) { |
|
| 25 | + $invert = TRUE; |
|
| 26 | + } |
|
| 25 | 27 | $interval = self::parse($interval); |
| 26 | 28 | } elseif (is_string($interval)) { |
| 27 | 29 | if (strpos($interval, '-') === 0) { |
@@ -29,12 +31,14 @@ discard block |
||
| 29 | 31 | $interval = substr($interval, 1); |
| 30 | 32 | } |
| 31 | 33 | } elseif (is_int($interval)) { |
| 32 | - if ($interval < 0) |
|
| 33 | - $invert = TRUE; |
|
| 34 | + if ($interval < 0) { |
|
| 35 | + $invert = TRUE; |
|
| 36 | + } |
|
| 34 | 37 | $interval = sprintf("PT%uS", abs($interval)); |
| 35 | 38 | } elseif (is_float($interval)) { |
| 36 | - if ($interval < 0) |
|
| 37 | - $invert = TRUE; |
|
| 39 | + if ($interval < 0) { |
|
| 40 | + $invert = TRUE; |
|
| 41 | + } |
|
| 38 | 42 | $interval = sprintf("PT%uS", abs(round($interval))); |
| 39 | 43 | } |
| 40 | 44 | try { |
@@ -57,8 +61,9 @@ discard block |
||
| 57 | 61 | $d1->add(new self($interval)); |
| 58 | 62 | $int = ($this->getRefDT())->diff($d1); |
| 59 | 63 | $this->__construct(self::parse($int)); |
| 60 | - if ($d1 < $this->getRefDT()) |
|
| 61 | - $this->invert = 1; |
|
| 64 | + if ($d1 < $this->getRefDT()) { |
|
| 65 | + $this->invert = 1; |
|
| 66 | + } |
|
| 62 | 67 | return $this; |
| 63 | 68 | } |
| 64 | 69 | |
@@ -69,8 +74,9 @@ discard block |
||
| 69 | 74 | $d1->sub(new self($interval)); |
| 70 | 75 | $int = ($this->getRefDT())->diff($d1); |
| 71 | 76 | $this->__construct(self::parse($int)); |
| 72 | - if ($d1 < $this->getRefDT()) |
|
| 73 | - $this->invert = 1; |
|
| 77 | + if ($d1 < $this->getRefDT()) { |
|
| 78 | + $this->invert = 1; |
|
| 79 | + } |
|
| 74 | 80 | return $this; |
| 75 | 81 | } |
| 76 | 82 | |
@@ -100,12 +106,13 @@ discard block |
||
| 100 | 106 | |
| 101 | 107 | if (isset($time['H']) && $time['H'] < 0) { |
| 102 | 108 | $time['H'] = 24 + $time['H']; |
| 103 | - if ($date['D'] >= 1) |
|
| 104 | - $date['D']--; |
|
| 105 | - elseif ($date['M'] >= 1) |
|
| 106 | - $date['M']--; |
|
| 107 | - elseif ($date['Y'] >= 1) |
|
| 108 | - $date['Y']--; |
|
| 109 | + if ($date['D'] >= 1) { |
|
| 110 | + $date['D']--; |
|
| 111 | + } elseif ($date['M'] >= 1) { |
|
| 112 | + $date['M']--; |
|
| 113 | + } elseif ($date['Y'] >= 1) { |
|
| 114 | + $date['Y']--; |
|
| 115 | + } |
|
| 109 | 116 | } |
| 110 | 117 | |
| 111 | 118 | if ($time['H'] === 24) { |
@@ -145,9 +152,11 @@ discard block |
||
| 145 | 152 | private function validateRelativeFormat($interval, \Exception $e = NULL) |
| 146 | 153 | { |
| 147 | 154 | $parse = date_parse($interval); |
| 148 | - if ($parse['error_count']) |
|
| 149 | - throw new DateInterval\InvalidArgumentException(($e) ? $e->getMessage() : NULL, ($e) ? $e->getCode() : NULL, ($e) ? $e : NULL); |
|
| 150 | - if (!isset($parse['relative'])) |
|
| 151 | - throw new DateInterval\InvalidArgumentException(sprintf("First argument '%s' is not in supported relative date format.", $interval), ($e) ? $e->getCode() : NULL, ($e) ? $e : NULL); |
|
| 155 | + if ($parse['error_count']) { |
|
| 156 | + throw new DateInterval\InvalidArgumentException(($e) ? $e->getMessage() : NULL, ($e) ? $e->getCode() : NULL, ($e) ? $e : NULL); |
|
| 157 | + } |
|
| 158 | + if (!isset($parse['relative'])) { |
|
| 159 | + throw new DateInterval\InvalidArgumentException(sprintf("First argument '%s' is not in supported relative date format.", $interval), ($e) ? $e->getCode() : NULL, ($e) ? $e : NULL); |
|
| 160 | + } |
|
| 152 | 161 | } |
| 153 | 162 | } |