Skip to content

fix: Time::setTimestamp()'s different behavior than DateTime - #9106

Merged
kenjis merged 4 commits into
codeigniter4:4.6from
kenjis:fix-Time-setTimestamp
Aug 21, 2024
Merged

fix: Time::setTimestamp()'s different behavior than DateTime#9106
kenjis merged 4 commits into
codeigniter4:4.6from
kenjis:fix-Time-setTimestamp

Conversation

@kenjis

@kenjiskenjis commented Aug 6, 2024

Copy link
Copy Markdown
Member

Description
Follow-up #9105

  • fix Time::setTimestamp() behavior.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjiskenjis added bug Verified issues on the current code behavior or pull requests that will fix them breaking change Pull requests that may break existing functionalities 4.6 labels Aug 6, 2024
@kenjiskenjis changed the title fix!: Time::setTimestamp()'s different behavior than DateTimefix: Time::setTimestamp()'s different behavior than DateTimeAug 6, 2024
Comment threadsystem/I18n/TimeTrait.php Outdated

@michalsnmichalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a changelog entry for this.

@kenjis
kenjisforce-pushed the fix-Time-setTimestamp branch from 1355800 to f2fb30cCompareAugust 20, 2024 06:45
@kenjis
kenjisforce-pushed the fix-Time-setTimestamp branch from f2fb30c to 9395543CompareAugust 20, 2024 06:56
@kenjis

Copy link
Copy Markdown
MemberAuthor

Added docs.

*
* @return static
*
* @throws Exception

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parent class (DateTimeImmutable) throws Exception.

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.


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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// After: 2024-08-19 19:00:00 -05:00
// After: 2024-08-19 19:00:00 -05:00

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The : symbols have been aligned for easier reading.


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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// After: 2024-08-20 00:00:00 -05:00
// After: 2024-08-20 00:00:00 -05:00

Time::setTimestamp() Behavior Fix
=================================

In previous versions, if you call ``Time::setTimestamp()`` on a Time instance with

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to use this?

Suggested change
In previous versions, if you call ``Time::setTimestamp()`` on a Time instance with
In previous versions, if you call :php:meth:`Time::setTimestamp()` on a Time instance with

@kenjiskenjisAug 20, 2024

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:php:meth: makes a link to the class reference.
But there is no class reference for Time::setTimestamp() method.

Class reference is something like the following:
https://codeigniter4.github.io/CodeIgniter4/outgoing/view_renderer.html#namespace-CodeIgniter\View

@datamwebdatamweb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@kenjis
kenjis merged commit 7e58971 into codeigniter4:4.6Aug 21, 2024
@kenjis
kenjis deleted the fix-Time-setTimestamp branch August 21, 2024 00:23
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking changePull requests that may break existing functionalitiesbugVerified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@kenjis@michalsn@samsonasik@datamweb