Disable date_time_create_from_format_call#6480
Disable date_time_create_from_format_call#6480paulbalandan merged 1 commit intocodeigniter4:developfrom
date_time_create_from_format_call#6480Conversation
|
|
||
| $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.
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.
The sample code doesn't make sense to begin with.
There was a problem hiding this comment.
Based on the docs, this is expected.
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.
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.
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: