Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions system/I18n/TimeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static function parse(string $datetime, $timezone = null, ?string $locale
*/
public static function today($timezone = null, ?string $locale = null)
{
return new static(date('Y-m-d 00:00:00'), $timezone, $locale);
return static::now($timezone, $locale)->setTime(0, 0, 0, 0);
}

/**
Expand All @@ -158,7 +158,7 @@ public static function today($timezone = null, ?string $locale = null)
*/
public static function yesterday($timezone = null, ?string $locale = null)
{
return new static(date('Y-m-d 00:00:00', strtotime('-1 day')), $timezone, $locale);
return static::now($timezone, $locale)->modify('-1 day')->setTime(0, 0, 0, 0);
}

/**
Expand All @@ -172,7 +172,7 @@ public static function yesterday($timezone = null, ?string $locale = null)
*/
public static function tomorrow($timezone = null, ?string $locale = null)
{
return new static(date('Y-m-d 00:00:00', strtotime('+1 day')), $timezone, $locale);
return static::now($timezone, $locale)->modify('+1 day')->setTime(0, 0, 0, 0);
}

/**
Expand Down
51 changes: 51 additions & 0 deletions tests/system/I18n/TimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,57 @@ public function testTomorrow(): void
$this->assertSame(date('Y-m-d 00:00:00', strtotime('+1 day')), $time->toDateTimeString());
}

public function testTodayWithTimezoneAcrossDateBoundary(): void
{
// When UTC is 2026-09-07 23:30:00, in Asia/Tokyo (+09:00) it is already 2026-09-08 08:30:00
Time::setTestNow('2026-09-07 23:30:00', 'UTC');

$tokyoToday = Time::today('Asia/Tokyo');
$this->assertSame('2026-09-08 00:00:00', $tokyoToday->toDateTimeString());

// When UTC is 2026-09-08 02:00:00, in America/New_York (-04:00 EDT) it is still 2026-09-07 22:00:00
Time::setTestNow('2026-09-08 02:00:00', 'UTC');

$nyToday = Time::today('America/New_York');
$this->assertSame('2026-09-07 00:00:00', $nyToday->toDateTimeString());

Time::setTestNow();
}

public function testYesterdayWithTimezoneAcrossDateBoundary(): void
{
// When UTC is 2026-09-07 23:30:00, in Tokyo it is 2026-09-08, so Tokyo yesterday is 2026-09-07
Time::setTestNow('2026-09-07 23:30:00', 'UTC');

$tokyoYesterday = Time::yesterday('Asia/Tokyo');
$this->assertSame('2026-09-07 00:00:00', $tokyoYesterday->toDateTimeString());

// When UTC is 2026-09-08 02:00:00, in NY it is 2026-09-07, so NY yesterday is 2026-09-06
Time::setTestNow('2026-09-08 02:00:00', 'UTC');

$nyYesterday = Time::yesterday('America/New_York');
$this->assertSame('2026-09-06 00:00:00', $nyYesterday->toDateTimeString());

Time::setTestNow();
}

public function testTomorrowWithTimezoneAcrossDateBoundary(): void
{
// When UTC is 2026-09-07 23:30:00, in Tokyo it is 2026-09-08, so Tokyo tomorrow is 2026-09-09
Time::setTestNow('2026-09-07 23:30:00', 'UTC');

$tokyoTomorrow = Time::tomorrow('Asia/Tokyo');
$this->assertSame('2026-09-09 00:00:00', $tokyoTomorrow->toDateTimeString());

// When UTC is 2026-09-08 02:00:00, in NY it is 2026-09-07, so NY tomorrow is 2026-09-08
Time::setTestNow('2026-09-08 02:00:00', 'UTC');

$nyTomorrow = Time::tomorrow('America/New_York');
$this->assertSame('2026-09-08 00:00:00', $nyTomorrow->toDateTimeString());

Time::setTestNow();
}

public function testCreateFromDate(): void
{
$time = Time::createFromDate(2017, 03, 05, 'America/Chicago');
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.7.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Bugs Fixed
- **Files:** Fixed a bug where ``File::move()`` and ``UploadedFile::move()`` set executable and overly permissive file permissions (``0777 & ~umask()`` instead of ``0666 & ~umask()``), and ``UploadedFile::move()`` targeted the parent directory instead of the destination file for ``chmod()``.
- **Helpers:** Fixed a bug where ``get_dir_file_info()`` returned incomplete entries for subdirectories and missing files instead of omitting them.
- **Honeypot:** Fixed a bug where bot detection returned an HTTP 500 response instead of 403 (Forbidden).
- **I18n:** Fixed a bug where ``Time::today()``, ``Time::yesterday()``, and ``Time::tomorrow()`` ignored the specified ``$timezone`` and ``setTestNow()`` when calculating the day.
- **Logger:** Fixed a bug where interpolating a log message with array or non-stringable context values could raise PHP warnings or errors.
- **Cache:** Fixed ``MemcachedHandler::decrement()`` initializing a non-existent counter to the positive offset. Missing counters are now initialized to ``0``, reflecting Memcached's unsigned, saturating counter semantics.

Expand Down
Loading