mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-12 11:06:28 +00:00
Modify Date/Time check in the NumberFormatter so that masks with a decimal/fractional time aren't misinterpreted as number masks, while still ensuring that durations are interpreted as date/time masks, and locale currency masks are still treated as numbers
A date/time with a decimal time shouldn't have a digit placeholder __before__ the decimal point, only after
This commit is contained in:
@@ -170,10 +170,11 @@ class Formatter
|
||||
$format = (string) preg_replace('/_.?/ui', ' ', $format);
|
||||
|
||||
// Let's begin inspecting the format and converting the value to a formatted string
|
||||
// Check for date/time characters (not inside quotes)
|
||||
if (
|
||||
(preg_match('/(\[\$[A-Z]*-[0-9A-F]*\])*[hmsdy](?=(?:[^"]|"[^"]*")*$)/miu', $format)) &&
|
||||
(preg_match('/0(?![^\[]*\])/miu', $format) === 0)
|
||||
// Check for date/time characters (not inside quotes)
|
||||
(preg_match('/(\[\$[A-Z]*-[0-9A-F]*\])*[hmsdy](?=(?:[^"]|"[^"]*")*$)/miu', $format))
|
||||
// A date/time with a decimal time shouldn't have a digit placeholder before the decimal point
|
||||
&& (preg_match('/[0\?#]\.(?![^\[]*\])/miu', $format) === 0)
|
||||
) {
|
||||
// datetime format
|
||||
$value = DateFormatter::format($value, $format);
|
||||
@@ -194,8 +195,6 @@ class Formatter
|
||||
$value = $writerInstance->$function($value, $colors);
|
||||
}
|
||||
|
||||
$value = str_replace(chr(0x00), '.', $value);
|
||||
|
||||
return $value;
|
||||
return str_replace(chr(0x00), '.', $value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,17 @@ return [
|
||||
22269.0625,
|
||||
'"y-m-d "yyyy-mm-dd" h:m:s "hh:mm:ss',
|
||||
],
|
||||
// Date with fractional/decimal time
|
||||
[
|
||||
'2023/02/28 0:00:00.000',
|
||||
44985,
|
||||
'yyyy/mm/dd\ h:mm:ss.000',
|
||||
],
|
||||
[
|
||||
'2023/02/28 07:35:02.000',
|
||||
44985.316,
|
||||
'yyyy/mm/dd\ hh:mm:ss.000',
|
||||
],
|
||||
[
|
||||
'07:35:00 AM',
|
||||
43270.315972222,
|
||||
|
||||
Reference in New Issue
Block a user