diff --git a/CHANGELOG.md b/CHANGELOG.md index 85f3e7d5..a3d0130c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +- Remove locale from formatting string - [#644](https://github.com/PHPOffice/PhpSpreadsheet/pull/644) + + ### Fixed - Allow iterators to go out of bounds with prev - [#587](https://github.com/PHPOffice/PhpSpreadsheet/issues/587) diff --git a/src/PhpSpreadsheet/Style/NumberFormat.php b/src/PhpSpreadsheet/Style/NumberFormat.php index 63ef20ae..dc52a841 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat.php +++ b/src/PhpSpreadsheet/Style/NumberFormat.php @@ -691,6 +691,9 @@ class NumberFormat extends Supervisor // Strip # $format = preg_replace('/\\#/', '0', $format); + // Remove locale code [$-###] + $format = preg_replace('/\[\$\-.*\]/', '', $format); + $n = '/\\[[^\\]]+\\]/'; $m = preg_replace($n, '', $format); $number_regex = '/(0+)(\\.?)(0*)/'; diff --git a/tests/data/Style/NumberFormat.php b/tests/data/Style/NumberFormat.php index 196fa2c6..a7584ee4 100644 --- a/tests/data/Style/NumberFormat.php +++ b/tests/data/Style/NumberFormat.php @@ -186,4 +186,24 @@ return [ -1234567.8899999999, '0000:00.00', ], + [ + '18.952', + 18.952, + '[$-409]General', + ], + [ + '9.98', + 9.98, + '[$-409]#,##0.00;-#,##0.00', + ], + [ + '18.952', + 18.952, + '[$-1010409]General', + ], + [ + '9.98', + 9.98, + '[$-1010409]#,##0.00;-#,##0.00', + ], ]; diff --git a/tests/data/Style/NumberFormatDates.php b/tests/data/Style/NumberFormatDates.php index 5b74fbed..be8dc966 100644 --- a/tests/data/Style/NumberFormatDates.php +++ b/tests/data/Style/NumberFormatDates.php @@ -62,4 +62,14 @@ return [ 43270.603472222, 'hh:mm:ss\ AM/PM', ], + [ + '8/20/2018', + 43332, + '[$-409]m/d/yyyy', + ], + [ + '8/20/2018', + 43332, + '[$-1010409]m/d/yyyy', + ], ];