Skip to content

Commit ca506ba

Browse files
author
Christoph Ziegenberg
authored
Corrected date time detection (#1492)
* Corrected date time detection German and Swiss ZIP codes (special formats provided in German Excel versions) were detected as date time value, because the regular expression for date time formats falsely matched their formats ("\C\H\-00000" and "\D-00000").
1 parent acd2ba0 commit ca506ba

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/PhpSpreadsheet/Shared/Date.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ public static function isDateTimeFormatCode($pFormatCode)
387387
if ((substr($pFormatCode, 0, 1) == '_') || (substr($pFormatCode, 0, 2) == '0 ')) {
388388
return false;
389389
}
390+
// Some "special formats" provided in German Excel versions were detected as date time value,
391+
// so filter them out here - "\C\H\-00000" (Switzerland) and "\D-00000" (Germany).
392+
if (\strpos($pFormatCode, '-00000') !== false) {
393+
return false;
394+
}
390395
// Try checking for any of the date formatting characters that don't appear within square braces
391396
if (preg_match('/(^|\])[^\[]*[' . self::$possibleDateFormatCharacters . ']/i', $pFormatCode)) {
392397
// We might also have a format mask containing quoted strings...

tests/data/Shared/Date/FormatCodes.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,12 @@
150150
true,
151151
'"date " y-m-d',
152152
],
153+
[
154+
false,
155+
'\C\H\-00000',
156+
],
157+
[
158+
false,
159+
'\D-00000',
160+
],
153161
];

0 commit comments

Comments
 (0)