Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/php-8.1-strftime.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function strftime (string $format, $timestamp = null, ?string $locale = null) :
case '#':
case '-':
// remove leading zeros but keep last char if also zero
return preg_replace('/^0+(?=.)/', '', $result);
return preg_replace('/^[0\s]+(?=.)/', '', $result);
}

return $result;
Expand Down
6 changes: 6 additions & 0 deletions tests/strftimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public function testDayFormats () {
$result = strftime('%e', '20220306 13:02:03');
$this->assertEquals(' 6', $result, '%e: Day of the month, with a space preceding single digits');

$result = strftime('%#e', '20220306 13:02:03');
$this->assertEquals('6', $result, '%#e: Day of the month, without leading space');

$result = strftime('%-e', '20220306 13:02:03');
$this->assertEquals('6', $result, '%-e: Day of the month, without leading space');

$result = strftime('%j', '20220306 13:02:03');
$this->assertEquals('065', $result, '%j: Day of the year, 3 digits with leading zeros');

Expand Down