-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Time::setTimestamp()'s different behavior than DateTime #9106
Changes from all commits
f3a9ebb
b20df7c
9395543
3884480
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -85,6 +85,25 @@ Also, methods that returns an ``int`` still lose the microseconds. | |||||
.. literalinclude:: upgrade_460/005.php | ||||||
:lines: 2- | ||||||
|
||||||
.. _upgrade-460-time-set-timestamp: | ||||||
|
||||||
Time::setTimestamp() Behavior Fix | ||||||
================================= | ||||||
|
||||||
In previous versions, if you call ``Time::setTimestamp()`` on a Time instance with | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it better to use this?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Class reference is something like the following: |
||||||
a timezone other than the default timezone might return a Time instance with the | ||||||
wrong date/time. | ||||||
|
||||||
This bug has been fixed, and it now behaves in the same way as ``DateTimeImmutable``: | ||||||
|
||||||
.. literalinclude:: upgrade_460/008.php | ||||||
:lines: 2- | ||||||
|
||||||
Note that if you use the default timezone, the behavior is not changed: | ||||||
|
||||||
.. literalinclude:: upgrade_460/009.php | ||||||
:lines: 2- | ||||||
|
||||||
.. _upgrade-460-registrars-with-dirty-hack: | ||||||
|
||||||
Registrars with Dirty Hack | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||
<?php | ||||||
|
||||||
use CodeIgniter\I18n\Time; | ||||||
|
||||||
// The Application Timezone is "UTC". | ||||||
|
||||||
// Set $time1 timezone to "America/Chicago". | ||||||
$time1 = Time::parse('2024-08-20', 'America/Chicago'); | ||||||
|
||||||
// The timestamp is "2024-08-20 00:00" in "UTC". | ||||||
$stamp = strtotime('2024-08-20'); // 1724112000 | ||||||
|
||||||
// But $time2 timezone is "America/Chicago". | ||||||
$time2 = $time1->setTimestamp($stamp); | ||||||
|
||||||
echo $time2->format('Y-m-d H:i:s P'); | ||||||
// Before: 2024-08-20 00:00:00 -05:00 | ||||||
// After: 2024-08-19 19:00:00 -05:00 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||
<?php | ||||||
|
||||||
use CodeIgniter\I18n\Time; | ||||||
|
||||||
// The Application Timezone is "America/Chicago". | ||||||
|
||||||
// $time1 timezone is "America/Chicago". | ||||||
$time1 = Time::parse('2024-08-20'); | ||||||
|
||||||
// The timestamp is "2024-08-20 00:00" in "America/Chicago". | ||||||
$stamp = strtotime('2024-08-20'); // 1724130000 | ||||||
|
||||||
// $time2 timezone is also "America/Chicago". | ||||||
$time2 = $time1->setTimestamp($stamp); | ||||||
|
||||||
echo $time2->format('Y-m-d H:i:s P'); | ||||||
// Before: 2024-08-20 00:00:00 -05:00 | ||||||
// After: 2024-08-20 00:00:00 -05:00 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the docs for the
setTimestamp
method, it mentions that an Exception may be thrown, but the method itself does not handle any exceptions directly. Should an appropriate exception be thrown?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parent class (
DateTimeImmutable
) throwsException
.CI is kind of thin wrapper for PHP, so I don't think it's necessary to change PHP's behavior unless there is a need to do so.