From 9df739da65295ff83325c76069f724c4b312918f Mon Sep 17 00:00:00 2001 From: Sami Puro Date: Sat, 24 Oct 2026 18:01:00 +0300 Subject: [PATCH 1/2] Handle an escaped percent sign followed by a format specifier --- src/php-8.1-strftime.php | 8 ++++++-- tests/strftimeTest.php | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/php-8.1-strftime.php b/src/php-8.1-strftime.php index 14e8038..53104ad 100644 --- a/src/php-8.1-strftime.php +++ b/src/php-8.1-strftime.php @@ -179,7 +179,12 @@ function strftime (string $format, $timestamp = null, ?string $locale = null) : '%x' => $intl_formatter, ]; - $out = preg_replace_callback('/(?assertEquals('%', $result, '%%: A literal percentage character ("%")'); + + $result = strftime('%%Y', '20220306 13:02:03'); + $this->assertEquals('%Y', $result, '%%Y: A literal percentage character followed by "Y"'); + + $result = strftime('%%%Y', '20220306 13:02:03'); + $this->assertEquals('%2022', $result, '%%%Y: A literal percentage character followed by the year'); } /** From 587025c5d9dab5aebf57b42f4250c67897f6dcdd Mon Sep 17 00:00:00 2001 From: Sami Puro Date: Sat, 24 Oct 2026 18:10:03 +0300 Subject: [PATCH 2/2] Simplify the format pattern --- 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 53104ad..3f5cea4 100644 --- a/src/php-8.1-strftime.php +++ b/src/php-8.1-strftime.php @@ -180,7 +180,7 @@ function strftime (string $format, $timestamp = null, ?string $locale = null) : ]; // %% is matched as its own token, so that "%%%Y" becomes "%" followed by the year - $out = preg_replace_callback('/%(?:%|([_#-]?)([a-zA-Z]))/', function ($match) use ($translation_table, $timestamp) { + $out = preg_replace_callback('/%%|%([_#-]?)([a-zA-Z])/', function ($match) use ($translation_table, $timestamp) { if ($match[0] == '%%') { return '%'; }