-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
672 additions
and
46 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
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,16 @@ | ||
<?php | ||
|
||
namespace Bugsnag\DateTime; | ||
|
||
use DateTimeImmutable; | ||
|
||
final class Clock implements ClockInterface | ||
{ | ||
/** | ||
* @return DateTimeImmutable | ||
*/ | ||
public function now() | ||
{ | ||
return new 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,13 @@ | ||
<?php | ||
|
||
namespace Bugsnag\DateTime; | ||
|
||
use DateTimeImmutable; | ||
|
||
interface ClockInterface | ||
{ | ||
/** | ||
* @return DateTimeImmutable | ||
*/ | ||
public function 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,41 @@ | ||
<?php | ||
|
||
namespace Bugsnag\DateTime; | ||
|
||
use DateTimeImmutable; | ||
|
||
final class Date | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public static function now(ClockInterface $clock = null) | ||
{ | ||
if ($clock === null) { | ||
$clock = new Clock(); | ||
} | ||
|
||
$date = $clock->now(); | ||
|
||
return self::format($date); | ||
} | ||
|
||
/** | ||
* @param DateTimeImmutable $date | ||
* | ||
* @return string | ||
*/ | ||
private static function format(DateTimeImmutable $date) | ||
{ | ||
$dateTime = $date->format('Y-m-d\TH:i:s'); | ||
|
||
// The milliseconds format character ("v") was introduced in PHP 7.0, so | ||
// we need to take microseconds (PHP 5.2+) and convert to milliseconds | ||
$microseconds = $date->format('u'); | ||
$milliseconds = substr($microseconds, 0, 3); | ||
|
||
$offset = $date->format('P'); | ||
|
||
return "{$dateTime}.{$milliseconds}{$offset}"; | ||
} | ||
} |
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
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
Oops, something went wrong.