1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-22 17:16:18 +02:00

Deprecate DateTimeImmutable (#1928)

Fixes #1926
This commit is contained in:
Ruud Kamphuis
2024-12-05 15:38:02 +01:00
committed by GitHub
parent e940004193
commit a258e4fe90
12 changed files with 83 additions and 49 deletions

View File

@@ -11,38 +11,13 @@
namespace Monolog;
use DateTimeZone;
class_alias(JsonSerializableDateTimeImmutable::class, 'Monolog\DateTimeImmutable');
/**
* Overrides default json encoding of date time objects
*
* @author Menno Holtkamp
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class DateTimeImmutable extends \DateTimeImmutable implements \JsonSerializable
{
private bool $useMicroseconds;
public function __construct(bool $useMicroseconds, ?DateTimeZone $timezone = null)
if (false) {
/**
* @deprecated Use \Monolog\JsonSerializableDateTimeImmutable instead.
*/
class DateTimeImmutable extends JsonSerializableDateTimeImmutable
{
$this->useMicroseconds = $useMicroseconds;
// if you like to use a custom time to pass to Logger::addRecord directly,
// call modify() or setTimestamp() on this instance to change the date after creating it
parent::__construct('now', $timezone);
}
public function jsonSerialize(): string
{
if ($this->useMicroseconds) {
return $this->format('Y-m-d\TH:i:s.uP');
}
return $this->format('Y-m-d\TH:i:sP');
}
public function __toString(): string
{
return $this->jsonSerialize();
}
}