N°5279 - PHP 8.1: Migrate usages of deprecated strftime() function

In the end we made an adapter to keep using the strftime() format (https://www.php.net/manual/fr/function.strftime.php); not to ease migration but because we couldn't use \DateTime::format().
We can't use \DateTime::format() directly on the whole filename as it would also format characters that are not supposed to be. eg. "__DB__-Y-m-d-production" would become "itopdb-2023-02-09-+01:00Thu, 09 Feb 2023 11:34:01 +0100202309", mind the "production" part being converted.
This commit is contained in:
Molkobain
2023-02-10 21:49:30 +01:00
parent 35b0b16e20
commit f7ee21f1d7
10 changed files with 147 additions and 26 deletions

View File

@@ -423,6 +423,35 @@ class utilsTest extends ItopTestCase
];
}
/**
* @dataProvider StrftimeFormatToDateTimeFormatProvider
* @covers \utils::StrftimeFormatToDateTimeFormat
*
* @param string $sInput
* @param string $sExpectedFormat
*
* @return void
*/
public function testStrftimeFormatToDateTimeFormat(string $sInput, string $sExpectedFormat)
{
$sTestedFormat = utils::StrftimeFormatToDateTimeFormat($sInput);
$this->assertEquals($sExpectedFormat, $sTestedFormat, "DateTime format transformation for '$sInput' doesn't match. Got '$sTestedFormat', expected '$sExpectedFormat'.");
}
public function StrftimeFormatToDateTimeFormatProvider(): array
{
return [
'Standard date time' => [
'%Y-%m-%d %H:%M:%S',
'Y-m-d H:i:s',
],
'All placeholders' => [
'%d | %m | %y | %Y | %H | %M | %S | %a | %A | %e | %j | %u | %w | %U | %V | %W | %b | %B | %h | %C | %g | %G | %k | %I | %l | %p | %P | %r | %R | %T | %X | %z | %Z | %c | %D | %F | %s | %x | %n | %t | %%',
'd | m | y | Y | H | i | s | D | l | j | z | N | w | %U | W | %W | M | F | M | %C | y | Y | G | h | g | A | a | h:i:s A | H:i | H:i:s | %X | O | T | %c | m/d/y | Y-m-d | U | %x | %n | %t | %',
],
];
}
/**
* @dataProvider ToCamelCaseProvider
* @covers utils::ToCamelCase