Skip to content

Commit 6b32d58

Browse files
committed
fix: Time loses microseconds
1 parent d4cf9bc commit 6b32d58

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

system/I18n/TimeTrait.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ public function __construct(?string $time = null, $timezone = null, ?string $loc
8181
if ($time === '' && static::$testNow instanceof self) {
8282
if ($timezone !== null) {
8383
$testNow = static::$testNow->setTimezone($timezone);
84-
$time = $testNow->format('Y-m-d H:i:s');
84+
$time = $testNow->format('Y-m-d H:i:s.u');
8585
} else {
8686
$timezone = static::$testNow->getTimezone();
87-
$time = static::$testNow->format('Y-m-d H:i:s');
87+
$time = static::$testNow->format('Y-m-d H:i:s.u');
8888
}
8989
}
9090

@@ -97,7 +97,7 @@ public function __construct(?string $time = null, $timezone = null, ?string $loc
9797
if ($time !== '' && static::hasRelativeKeywords($time)) {
9898
$instance = new DateTime('now', $this->timezone);
9999
$instance->modify($time);
100-
$time = $instance->format('Y-m-d H:i:s');
100+
$time = $instance->format('Y-m-d H:i:s.u');
101101
}
102102

103103
parent::__construct($time, $this->timezone);
@@ -253,7 +253,7 @@ public static function createFromFormat($format, $datetime, $timezone = null)
253253
throw I18nException::forInvalidFormat($format);
254254
}
255255

256-
return new self($date->format('Y-m-d H:i:s'), $timezone);
256+
return new self($date->format('Y-m-d H:i:s.u'), $timezone);
257257
}
258258

259259
/**
@@ -283,7 +283,7 @@ public static function createFromTimestamp(int $timestamp, $timezone = null, ?st
283283
*/
284284
public static function createFromInstance(DateTimeInterface $dateTime, ?string $locale = null)
285285
{
286-
$date = $dateTime->format('Y-m-d H:i:s');
286+
$date = $dateTime->format('Y-m-d H:i:s.u');
287287
$timezone = $dateTime->getTimezone();
288288

289289
return new self($date, $timezone, $locale);
@@ -348,7 +348,7 @@ public static function setTestNow($datetime = null, $timezone = null, ?string $l
348348
if (is_string($datetime)) {
349349
$datetime = new self($datetime, $timezone, $locale);
350350
} elseif ($datetime instanceof DateTimeInterface && ! $datetime instanceof self) {
351-
$datetime = new self($datetime->format('Y-m-d H:i:s'), $timezone);
351+
$datetime = new self($datetime->format('Y-m-d H:i:s.u'), $timezone);
352352
}
353353

354354
static::$testNow = $datetime;
@@ -941,9 +941,9 @@ public function equals($testTime, ?string $timezone = null): bool
941941

942942
$ourTime = $this->toDateTime()
943943
->setTimezone(new DateTimeZone('UTC'))
944-
->format('Y-m-d H:i:s');
944+
->format('Y-m-d H:i:s.u');
945945

946-
return $testTime->format('Y-m-d H:i:s') === $ourTime;
946+
return $testTime->format('Y-m-d H:i:s.u') === $ourTime;
947947
}
948948

949949
/**
@@ -956,15 +956,15 @@ public function equals($testTime, ?string $timezone = null): bool
956956
public function sameAs($testTime, ?string $timezone = null): bool
957957
{
958958
if ($testTime instanceof DateTimeInterface) {
959-
$testTime = $testTime->format('Y-m-d H:i:s');
959+
$testTime = $testTime->format('Y-m-d H:i:s.u O');
960960
} elseif (is_string($testTime)) {
961961
$timezone = $timezone ?: $this->timezone;
962962
$timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
963963
$testTime = new DateTime($testTime, $timezone);
964-
$testTime = $testTime->format('Y-m-d H:i:s');
964+
$testTime = $testTime->format('Y-m-d H:i:s.u O');
965965
}
966966

967-
$ourTime = $this->toDateTimeString();
967+
$ourTime = $this->format('Y-m-d H:i:s.u O');
968968

969969
return $testTime === $ourTime;
970970
}

0 commit comments

Comments
 (0)