Skip to content

Commit

Permalink
Add support for +XX seconds in DateTimeImmutable
Browse files Browse the repository at this point in the history
  • Loading branch information
dstankovd committed Nov 8, 2019
1 parent 78ff3b0 commit 943642d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/std/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public function __construct($t = 'now', $zone = null) {
if ($t === 'now' || $t === 'NOW' || $t === null) {
$date = new DateTime($t, $zone);
parent::__construct($date->format('Y-m-d H:i:s'), $zone);
} else if (substr($t, 0, 1) === '+' || substr($t, 0, 1) === '-') {
$date = new DateTime('now', $zone);
$date->setTimestamp(time() + explode(' ', $t)[0]);
parent::__construct($date->format('Y-m-d H:i:s'), $zone);
} else {
parent::__construct($t, $zone);
}
Expand Down

0 comments on commit 943642d

Please sign in to comment.