From 3a50ebb01228ece4a99243b2403d4366a0502bb7 Mon Sep 17 00:00:00 2001 From: Derek Bonner Date: Wed, 20 Jun 2018 17:05:27 -0700 Subject: [PATCH] Fix issue where escaped spaces in cell format would cause incorrect date format leading to incorrect time conversions --- src/PhpSpreadsheet/Style/NumberFormat.php | 2 +- tests/data/Style/NumberFormatDates.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Style/NumberFormat.php b/src/PhpSpreadsheet/Style/NumberFormat.php index 8075af4814..63ef20aeb1 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat.php +++ b/src/PhpSpreadsheet/Style/NumberFormat.php @@ -589,7 +589,7 @@ public static function toFormattedString($value, $format, $callBack = null) } // Convert any other escaped characters to quoted strings, e.g. (\T to "T") - $format = preg_replace('/(\\\(.))(?=(?:[^"]|"[^"]*")*$)/u', '"${2}"', $format); + $format = preg_replace('/(\\\([^ ]))(?=(?:[^"]|"[^"]*")*$)/u', '"${2}"', $format); // Get the sections, there can be up to four sections, separated with a semi-colon (but only if not a quoted literal) $sections = preg_split('/(;)(?=(?:[^"]|"[^"]*")*$)/u', $format); diff --git a/tests/data/Style/NumberFormatDates.php b/tests/data/Style/NumberFormatDates.php index 6fb5cce732..5b74fbedca 100644 --- a/tests/data/Style/NumberFormatDates.php +++ b/tests/data/Style/NumberFormatDates.php @@ -52,4 +52,14 @@ 22269.0625, '[DBNum1][$-804]m"月"d"日";@', ], + [ + '07:35:00 AM', + 43270.315972222, + 'hh:mm:ss\ AM/PM', + ], + [ + '02:29:00 PM', + 43270.603472222, + 'hh:mm:ss\ AM/PM', + ], ];