From 8c58385d6c103d23f6a5b3d1899a5e7cc8f66e92 Mon Sep 17 00:00:00 2001 From: Green Wang Date: Mon, 21 Nov 2016 11:56:10 +0800 Subject: [PATCH] Fix cant get right format chinese date format error modify preg expression in NumberFormat.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [DBNum1][$-804]yyyy"年"m"月"d"日";@ [DBNum1][$-804]yyyy"年"m"月";@ [DBNum1][$-804]m"月"d"日";@ FIX #44 --- src/PhpSpreadsheet/Style/NumberFormat.php | 3 ++- tests/data/Style/NumberFormatDates.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Style/NumberFormat.php b/src/PhpSpreadsheet/Style/NumberFormat.php index 6a3d03fa..1754200e 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat.php +++ b/src/PhpSpreadsheet/Style/NumberFormat.php @@ -464,7 +464,8 @@ class NumberFormat extends Supervisor implements \PhpOffice\PhpSpreadsheet\IComp // strip off first part containing e.g. [$-F800] or [$USD-409] // general syntax: [$-] // language info is in hexadecimal - $format = preg_replace('/^(\[\$[A-Z]*-[0-9A-F]*\])/i', '', $format); + // strip off chinese part like [DBNum1][$-804] + $format = preg_replace('/^(\[[0-9A-Za-z]*\])*(\[\$[A-Z]*-[0-9A-F]*\])/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 381a169a..bf6bdd3e 100644 --- a/tests/data/Style/NumberFormatDates.php +++ b/tests/data/Style/NumberFormatDates.php @@ -36,4 +36,20 @@ return [ '"y-m-d "yyyy-mm-dd" h:m:s "hh:mm:ss', 'y-m-d 1960-12-19 h:m:s 01:30:00', ], + // Chinese date format + [ + 22269.0625, + '[DBNum1][$-804]yyyy"年"m"月"d"日";@', + '1960年12月19日', + ], + [ + 22269.0625, + '[DBNum1][$-804]yyyy"年"m"月";@', + '1960年12月', + ], + [ + 22269.0625, + '[DBNum1][$-804]m"月"d"日";@', + '12月19日', + ], ];