fix(I18n): compute correct date in Time::today(), yesterday(), and tomorrow() across timezones - #10532
Open
gr8man wants to merge 1 commit into
Open
fix(I18n): compute correct date in Time::today(), yesterday(), and tomorrow() across timezones#10532gr8man wants to merge 1 commit into
gr8man wants to merge 1 commit into
Conversation
…terday(), and tomorrow() - Compute start of day relative to the requested timezone instead of the server default timezone - Respect Time::setTestNow() mock instance in today(), yesterday(), and tomorrow() - Add unit tests covering date boundary transitions across different timezones - Add changelog entry in v4.7.5.rst
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Time::today($timezone),Time::yesterday($timezone), andTime::tomorrow($timezone)previously used PHP's nativedate('Y-m-d 00:00:00')andstrtotime('-1 day')/strtotime('+1 day')to generate the date string passed to the constructor.Because
date()andstrtotime()evaluate in the server's default timezone (date_default_timezone_get()), the target$timezoneargument was ignored when determining the calendar day. For several hours each day (when the server timezone like UTC and the requested timezone likeAsia/TokyoorAmerica/New_Yorkare on different calendar days),today(),yesterday(), andtomorrow()produced the wrong calendar day in that timezone.Furthermore, passing a non-empty string from
date()intonew static(...)bypassedTime::setTestNow()in the constructor, preventingtoday(),yesterday(), andtomorrow()from respecting mocked test time.This PR fixes both issues by using
static::now($timezone, $locale)->setTime(0, 0, 0, 0)(andmodify('-1 day')/modify('+1 day')). This ensures:Time::setTestNow()mock instances are preserved and converted accurately.v4.7.5.rst.Checklist: