-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4004 from mjansenDatabay/feature/8/clock-service
Clock: Introduce `PSR-20 Clock Service` as `src/Data` type
- Loading branch information
Showing
13 changed files
with
400 additions
and
6 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/****************************************************************************** | ||
* | ||
* This file is part of ILIAS, a powerful learning management system. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, you should have received a copy | ||
* of said license along with the source code. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*****************************************************************************/ | ||
|
||
namespace ILIAS\Data\Clock; | ||
|
||
use DateTimeZone; | ||
|
||
interface ClockFactory | ||
{ | ||
public function system() : ClockInterface; | ||
|
||
public function utc() : ClockInterface; | ||
|
||
public function local(DateTimeZone $time_zone) : ClockInterface; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/****************************************************************************** | ||
* | ||
* This file is part of ILIAS, a powerful learning management system. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, you should have received a copy | ||
* of said license along with the source code. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*****************************************************************************/ | ||
|
||
namespace ILIAS\Data\Clock; | ||
|
||
use DateTimeZone; | ||
|
||
class ClockFactoryImpl implements ClockFactory | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function system() : ClockInterface | ||
{ | ||
return new SystemClock(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function utc() : ClockInterface | ||
{ | ||
return new UtcClock(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function local(DateTimeZone $time_zone) : ClockInterface | ||
{ | ||
return new LocalClock($time_zone); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/****************************************************************************** | ||
* | ||
* This file is part of ILIAS, a powerful learning management system. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, you should have received a copy | ||
* of said license along with the source code. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*****************************************************************************/ | ||
|
||
namespace ILIAS\Data\Clock; | ||
|
||
use DateTimeImmutable; | ||
|
||
interface ClockInterface | ||
{ | ||
public function now() : DateTimeImmutable; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/****************************************************************************** | ||
* | ||
* This file is part of ILIAS, a powerful learning management system. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, you should have received a copy | ||
* of said license along with the source code. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*****************************************************************************/ | ||
|
||
namespace ILIAS\Data\Clock; | ||
|
||
use DateTimeImmutable; | ||
use DateTimeZone; | ||
|
||
class LocalClock implements ClockInterface | ||
{ | ||
private DateTimeZone $time_zone; | ||
|
||
public function __construct(DateTimeZone $time_zone) | ||
{ | ||
$this->time_zone = $time_zone; | ||
} | ||
|
||
public function now() : DateTimeImmutable | ||
{ | ||
return new DateTimeImmutable('now', $this->time_zone); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/****************************************************************************** | ||
* | ||
* This file is part of ILIAS, a powerful learning management system. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, you should have received a copy | ||
* of said license along with the source code. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*****************************************************************************/ | ||
|
||
namespace ILIAS\Data\Clock; | ||
|
||
use DateTimeImmutable; | ||
|
||
class SystemClock implements ClockInterface | ||
{ | ||
public function now() : DateTimeImmutable | ||
{ | ||
return new DateTimeImmutable('now'); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/****************************************************************************** | ||
* | ||
* This file is part of ILIAS, a powerful learning management system. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, you should have received a copy | ||
* of said license along with the source code. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*****************************************************************************/ | ||
|
||
namespace ILIAS\Data\Clock; | ||
|
||
use DateTimeImmutable; | ||
use DateTimeZone; | ||
|
||
class UtcClock implements ClockInterface | ||
{ | ||
public function now() : DateTimeImmutable | ||
{ | ||
return new DateTimeImmutable('now', new DateTimeZone('UTC')); | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
# Roadmap |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/****************************************************************************** | ||
* | ||
* This file is part of ILIAS, a powerful learning management system. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, you should have received a copy | ||
* of said license along with the source code. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*****************************************************************************/ | ||
|
||
namespace ILIAS\Data\Clock; | ||
|
||
use DateTimeZone; | ||
use ILIAS\Data\Clock\LocalClock; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class LocalClockTest extends TestCase | ||
{ | ||
private string $default_timezone; | ||
|
||
protected function setUp() : void | ||
{ | ||
$this->default_timezone = date_default_timezone_get(); | ||
} | ||
|
||
protected function tearDown() : void | ||
{ | ||
date_default_timezone_set($this->default_timezone); | ||
} | ||
|
||
public function testUtcClockIsNotAffectedByGlobalTimezoneChanges() : void | ||
{ | ||
date_default_timezone_set('UTC'); | ||
|
||
$clock = new LocalClock(new DateTimeZone('Africa/Windhoek')); | ||
|
||
self::assertSame('Africa/Windhoek', $clock->now()->getTimezone()->getName()); | ||
} | ||
} |
Oops, something went wrong.