From 474096c71131f8259a10c3ffa3e095853f5440c4 Mon Sep 17 00:00:00 2001 From: maqc1 Date: Tue, 10 Jan 2023 19:54:53 -0500 Subject: [PATCH 1/2] Minus prefix should also remove space Standard PHP strftime() also remove leading space when using the minus prefix. --- src/php-8.1-strftime.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/php-8.1-strftime.php b/src/php-8.1-strftime.php index 1c7ee37..a7451c1 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; From 8f5aa95017c703f85d741bd9806318464c2440bd Mon Sep 17 00:00:00 2001 From: Fernando Herrero Date: Fri, 26 Jan 2024 22:04:53 +0100 Subject: [PATCH 2/2] Add asserts for test '%#e' and '%-e' --- tests/strftimeTest.php | 6 ++++++ 1 file changed, 6 insertions(+) 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');