-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add timezone parameter to ChronosClock
- Loading branch information
odan
authored and
odan
committed
Oct 24, 2023
1 parent
ac94c9c
commit e3c3f6e
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,20 +16,33 @@ | |
*/ | ||
|
||
use DateTimeImmutable; | ||
use DateTimeZone; | ||
use Psr\Clock\ClockInterface; | ||
|
||
/** | ||
* PSR-20 Clock implementation. | ||
*/ | ||
class ChronosClock implements ClockInterface | ||
{ | ||
private DateTimeZone|string|null $timezone; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param DateTimeZone|string|null $timezone | ||
Check failure on line 32 in src/ChronosClock.php GitHub Actions / cs-stan / Coding Standard & Static Analysis
|
||
*/ | ||
public function __construct(DateTimeZone|string|null $timezone = null) | ||
{ | ||
$this->timezone = $timezone; | ||
} | ||
|
||
/** | ||
* Returns the current time as a Chronos Object | ||
* | ||
* @return \Cake\Chronos\Chronos The current time | ||
*/ | ||
public function now(): DateTimeImmutable | ||
{ | ||
return Chronos::now(); | ||
return Chronos::now($this->timezone); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters