Fixed the date shift by making date-only strings stay in the user timezone instead of being converted from UTC, which caused the one-day rollback.
This commit is contained in:
@@ -167,8 +167,13 @@ class TimeService
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sourceTz = $sourceTz ?: $this->serverTimezone;
|
|
||||||
$targetTz = $targetTz ?: $this->userTimezone();
|
$targetTz = $targetTz ?: $this->userTimezone();
|
||||||
|
if ($sourceTz === null && $this->isDateOnlyString($value)) {
|
||||||
|
// Date-only strings should not shift across timezones.
|
||||||
|
$sourceTz = $targetTz;
|
||||||
|
} else {
|
||||||
|
$sourceTz = $sourceTz ?: $this->serverTimezone;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($value instanceof Time) {
|
if ($value instanceof Time) {
|
||||||
@@ -204,4 +209,14 @@ class TimeService
|
|||||||
{
|
{
|
||||||
return (string) ($this->toUTC($value, $fromTz, $format) ?? '');
|
return (string) ($this->toUTC($value, $fromTz, $format) ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function isDateOnlyString($value): bool
|
||||||
|
{
|
||||||
|
if (!is_string($value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = trim($value);
|
||||||
|
return (bool) preg_match('/^\d{4}-\d{2}-\d{2}$/', $value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user