-
Notifications
You must be signed in to change notification settings - Fork 2k
Disable date_time_create_from_format_call
#6480
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
Disable date_time_create_from_format_call
#6480
Conversation
|
|
||
| $response->setLastModified(date('D, d M Y H:i:s')); | ||
| $response->setLastModified(DateTime::createFromFormat('u', $time)); | ||
| $response->setLastModified(DateTime::createFromFormat('!u', $time)); |
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.
This change is incorrect.
php > var_dump(DateTime::createFromFormat('u', 654321));
php shell code:1:
class DateTime#1 (3) {
public $date =>
string(26) "2022-09-04 00:00:00.654321"
public $timezone_type =>
int(3)
public $timezone =>
string(3) "UTC"
}
php > var_dump(DateTime::createFromFormat('!u', 654321));
php shell code:1:
class DateTime#1 (3) {
public $date =>
string(26) "1970-01-01 00:00:00.654321"
public $timezone_type =>
int(3)
public $timezone =>
string(3) "UTC"
}
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 sample code doesn't make sense to begin with.
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.
Based on the docs, this is expected.
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.
What do you mean?
Neither of the following seems to have a use case. What do we specify by $time?
$response->setLastModified(DateTime::createFromFormat('u', $time));
$response->setLastModified(DateTime::createFromFormat('!u', $time));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.
Resets all fields (year, month, day, hour, minute, second, fraction and timezone information) to zero-like values ( 0 for hour, minute, second and fraction, 1 for month and day, 1970 for year and UTC for timezone information)
This means that since the format lacks any of "Y, m, d, H, i, s", the ! resets them.
I think the format should have been the capital U.
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.
I think you're correct. u generates only the microseconds segment, so: 2022-09-10 07:37:24.5238 yields 5238. This was supposed to be U for an actual full timestamp.
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.
There is no microseconds in the Last-Modified header:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified
The sample code should be like the following:
$response->setLastModified(DateTime::createFromFormat('U', $timestamp));And it is the same as:
$response->setLastModified(DateTime::createFromFormat('!U', $timestamp));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.
I sent a PR #6526
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.
I think by definition !U is redundant.
|
|
||
| $date = DateTime::createFromFormat('j-M-Y', '15-Feb-2016'); | ||
| $date = DateTime::createFromFormat('!j-M-Y', '15-Feb-2016'); | ||
| $response->setDate($date); |
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.
I do not know in which case such a sample code would be used.
https://codeigniter4.github.io/CodeIgniter4/outgoing/response.html#CodeIgniter\HTTP\Response::setDate
So I also don't know the change is correct or not.
|
Skipping this one for now, looks like it may need some more work. |
c893ec3 to
ddf5b3e
Compare
date_time_create_from_format_calldate_time_create_from_format_call
|
I disabled it for now. |
kenjis
left a comment
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.
I think that enabling date_time_create_from_format_call and fixing existing sample code that I can't imagine use cases might be better.
|
I can't find documentation on |
|
Ah thanks! It's specific to this method, makes sense. Anyone else bothered by this in that link?
Yes I think this is a good change to apply but it will require taking them case by case. I will start going through as I have time. |
MGatner
left a comment
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.
Disabling for now is fine but please set this to true in the Coding Standard.
ddf5b3e to
046e77f
Compare
Description
This might need discussion.
Checklist: