Skip to content

Commit 1c19f44

Browse files
committed
Fixes issue where escaped spaces in date format would cause incorrect AM/PM conversion
1 parent a6bb491 commit 1c19f44

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/PhpSpreadsheet/Style/NumberFormat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ public static function toFormattedString($value, $format, $callBack = null)
589589
}
590590

591591
// Convert any other escaped characters to quoted strings, e.g. (\T to "T")
592-
$format = preg_replace('/(\\\(.))(?=(?:[^"]|"[^"]*")*$)/u', '"${2}"', $format);
592+
$format = preg_replace('/(\\\([^ ]))(?=(?:[^"]|"[^"]*")*$)/u', '"${2}"', $format);
593593

594594
// Get the sections, there can be up to four sections, separated with a semi-colon (but only if not a quoted literal)
595595
$sections = preg_split('/(;)(?=(?:[^"]|"[^"]*")*$)/u', $format);

tests/data/Style/NumberFormatDates.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,14 @@
5252
22269.0625,
5353
'[DBNum1][$-804]m"月"d"日";@',
5454
],
55+
[
56+
'07:35:00 AM',
57+
43270.315972222,
58+
'hh:mm:ss\ AM/PM',
59+
],
60+
[
61+
'02:29:00 PM',
62+
43270.603472222,
63+
'hh:mm:ss\ AM/PM',
64+
],
5565
];

0 commit comments

Comments
 (0)