Skip to content

Commit 2ee69eb

Browse files
maqc1alphp
andauthored
Minus prefix should also remove leading space (#13)
* Minus prefix should also remove space Standard PHP strftime() also remove leading space when using the minus prefix. * Add asserts for test '%#e' and '%-e' --------- Co-authored-by: Fernando Herrero <[email protected]>
1 parent cc286d6 commit 2ee69eb

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/php-8.1-strftime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ function strftime (string $format, $timestamp = null, ?string $locale = null) :
206206
case '#':
207207
case '-':
208208
// remove leading zeros but keep last char if also zero
209-
return preg_replace('/^0+(?=.)/', '', $result);
209+
return preg_replace('/^[0\s]+(?=.)/', '', $result);
210210
}
211211

212212
return $result;

tests/strftimeTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public function testDayFormats () {
4848
$result = strftime('%e', '20220306 13:02:03');
4949
$this->assertEquals(' 6', $result, '%e: Day of the month, with a space preceding single digits');
5050

51+
$result = strftime('%#e', '20220306 13:02:03');
52+
$this->assertEquals('6', $result, '%#e: Day of the month, without leading space');
53+
54+
$result = strftime('%-e', '20220306 13:02:03');
55+
$this->assertEquals('6', $result, '%-e: Day of the month, without leading space');
56+
5157
$result = strftime('%j', '20220306 13:02:03');
5258
$this->assertEquals('065', $result, '%j: Day of the year, 3 digits with leading zeros');
5359

0 commit comments

Comments
 (0)