Cell formats with escaped spaces were causing incorrect date formatting

Fix issue where escaped spaces in cell format would cause incorrect
date format leading to incorrect time conversions

Fixes 
Closes 
This commit is contained in:
Derek Bonner 2018-06-24 03:35:45 -07:00 committed by Adrien Crivelli
parent a6bb491539
commit 7a4cbd4fd5
3 changed files with 13 additions and 1 deletions
CHANGELOG.md
src/PhpSpreadsheet/Style
tests/data/Style

View File

@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased] ## [Unreleased]
- Cell formats with escaped spaces were causing incorrect date formatting - [#557](https://github.com/PHPOffice/PhpSpreadsheet/issues/557)
### Fixed ### Fixed
- Xlsx reader crashed when reading a file with workbook protection - [#553](https://github.com/PHPOffice/PhpSpreadsheet/pull/553) - Xlsx reader crashed when reading a file with workbook protection - [#553](https://github.com/PHPOffice/PhpSpreadsheet/pull/553)

View File

@ -589,7 +589,7 @@ class NumberFormat extends Supervisor
} }
// Convert any other escaped characters to quoted strings, e.g. (\T to "T") // 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) // 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); $sections = preg_split('/(;)(?=(?:[^"]|"[^"]*")*$)/u', $format);

View File

@ -52,4 +52,14 @@ return [
22269.0625, 22269.0625,
'[DBNum1][$-804]m"月"d"日";@', '[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',
],
]; ];