DateTimeConstantsUsage
error on by default quick-fixGroup: Probable bugs · PhpStorm name: DateTimeConstantsUsageInspection
The ISO8601 date format constants do not actually produce ISO-8601 output (the offset lacks a colon). The ATOM variants produce the compliant format and should be used instead.
Example
php
<?php
class Stamp { const ISO8601 = 'Y'; }
class LocalTime extends DateTime {}
function formats(DateTimeImmutable $at)
{
return [
DATE_ISO8601,
\DATE_ISO8601,
DateTime::ISO8601,
DateTimeInterface::ISO8601,
LocalTime::ISO8601,
Stamp::ISO8601,
DATE_ISO8601_LEGACY,
DATE_RFC3339,
$at->format('c'),
];
}php
<?php
class Stamp { const ISO8601 = 'Y'; }
class LocalTime extends DateTime {}
function formats(DateTimeImmutable $at)
{
return [
DATE_ATOM,
\DATE_ATOM,
DateTime::ATOM,
DateTimeInterface::ATOM,
LocalTime::ATOM,
Stamp::ISO8601,
DATE_ISO8601_LEGACY,
DATE_RFC3339,
$at->format('c'),
];
}Reported:
- line 8: DATE_ISO8601 is not ISO-8601 compliant; use DATE_ATOM.
- line 9: DATE_ISO8601 is not ISO-8601 compliant; use DATE_ATOM.
- line 10: ISO8601 is not ISO-8601 compliant; use the ATOM constant.
- line 11: ISO8601 is not ISO-8601 compliant; use the ATOM constant.
- line 12: ISO8601 is not ISO-8601 compliant; use the ATOM constant.
Configure
In custos.json:
json
{
"rules": {
"DateTimeConstantsUsage": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file), either of:
php
// @custos-ignore DateTimeConstantsUsage
/**
* @noinspection DateTimeConstantsUsageInspection
*/