diff --git a/src/php-8.1-strftime.php b/src/php-8.1-strftime.php index 18fc178..d34f065 100644 --- a/src/php-8.1-strftime.php +++ b/src/php-8.1-strftime.php @@ -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; diff --git a/tests/strftimeTest.php b/tests/strftimeTest.php index a0ca3fe..2540afc 100644 --- a/tests/strftimeTest.php +++ b/tests/strftimeTest.php @@ -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');