diff --git a/CHANGELOG.md b/CHANGELOG.md index cefe1590..24ddedc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Changed - Updated the CONVERT() function to support all current MS Excel categories and Units of Measure. +- `formatAsDate` correctly matches language metadata, reverting c55272e ### Deprecated diff --git a/src/PhpSpreadsheet/Style/NumberFormat.php b/src/PhpSpreadsheet/Style/NumberFormat.php index 0b761bd3..9a0acb6f 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat.php +++ b/src/PhpSpreadsheet/Style/NumberFormat.php @@ -469,7 +469,7 @@ class NumberFormat extends Supervisor // general syntax: [$-] // language info is in hexadecimal // strip off chinese part like [DBNum1][$-804] - $format = preg_replace('/^(\[[0-9A-Za-z]*\])*(\[\$[A-Z]*-[0-9A-F]*\])/i', '', $format); + $format = preg_replace('/^(\[DBNum\d\])*(\[\$[^\]]*\])/i', '', $format); // OpenOffice.org uses upper-case number formats, e.g. 'YYYY', convert to lower-case; // but we don't want to change any quoted strings diff --git a/tests/data/Style/NumberFormatDates.php b/tests/data/Style/NumberFormatDates.php index 9e476042..331a080c 100644 --- a/tests/data/Style/NumberFormatDates.php +++ b/tests/data/Style/NumberFormatDates.php @@ -36,22 +36,6 @@ return [ 22269.0625, '"y-m-d "yyyy-mm-dd" h:m:s "hh:mm:ss', ], - // Chinese date format - [ - '1960年12月19日', - 22269.0625, - '[DBNum1][$-804]yyyy"年"m"月"d"日";@', - ], - [ - '1960年12月', - 22269.0625, - '[DBNum1][$-804]yyyy"年"m"月";@', - ], - [ - '12月19日', - 22269.0625, - '[DBNum1][$-804]m"月"d"日";@', - ], [ '07:35:00 AM', 43270.315972222, @@ -77,4 +61,15 @@ return [ 1.1354166666667, '[h]:mm', ], + [ + '19331018', + 12345.6789, + '[DBNum4][$-804]yyyymmdd;@', + ], + // Technically should be 19331018 + [ + '19331018', + 12345.6789, + '[DBNum3][$-zh-CN]yyyymmdd;@', + ], ];