mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-30 03:59:11 +00:00
Adjust identifier for Date Format Masking to prevent it picking out currencies with locales containing the letters h, m, s, d and y as dates
This commit is contained in:
@@ -217,7 +217,7 @@ class NumberFormat extends Supervisor
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFormatCode($formatCode)
|
||||
public function setFormatCode(string $formatCode)
|
||||
{
|
||||
if ($formatCode == '') {
|
||||
$formatCode = self::FORMAT_GENERAL;
|
||||
@@ -251,11 +251,11 @@ class NumberFormat extends Supervisor
|
||||
/**
|
||||
* Set Built-In Format Code.
|
||||
*
|
||||
* @param int $formatCodeIndex
|
||||
* @param int $formatCodeIndex Id of the built-in format code to use
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBuiltInFormatCode($formatCodeIndex)
|
||||
public function setBuiltInFormatCode(int $formatCodeIndex)
|
||||
{
|
||||
if ($this->isSupervisor) {
|
||||
$styleArray = $this->getStyleArray(['formatCode' => self::builtInFormatCode($formatCodeIndex)]);
|
||||
|
||||
@@ -170,9 +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, $matches)) {
|
||||
if (
|
||||
(preg_match('/(\[\$[A-Z]*-[0-9A-F]*\])*[hmsdy](?=(?:[^"]|"[^"]*")*$)/miu', $format)) &&
|
||||
(preg_match('/0(?![^\[]*\])/miu', $format) === 0)
|
||||
) {
|
||||
// datetime format
|
||||
$value = DateFormatter::format($value, $format);
|
||||
} else {
|
||||
|
||||
@@ -1464,4 +1464,19 @@ return [
|
||||
'truncate to 1 decimal' => ['009 7.1', 97.13, '000 0.0'],
|
||||
'scientific many decimal positions truncated' => ['000 0.000 00', 1e-7, '000 0.000 00'],
|
||||
'scientific very many decimal positions truncated' => ['000 0.000 00', 1e-17, '000 0.000 00'],
|
||||
[
|
||||
'€ 1,111.12 ',
|
||||
'1111.119',
|
||||
'[$€-nl_NL]_(#,##0.00_);[$€-nl_NL] (#,##0.00)',
|
||||
],
|
||||
[
|
||||
'€ (1,111.12)',
|
||||
'-1111.119',
|
||||
'[$€-nl_NL]_(#,##0.00_);[$€-nl_NL] (#,##0.00)',
|
||||
],
|
||||
[
|
||||
'€ 1,111.12 ',
|
||||
'1111.119',
|
||||
'[$€-en_US]_(#,##0.00_);[$€-en_US] (#,##0.00)',
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user