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:
MarkBaker
2023-02-18 17:46:23 +01:00
parent 3beef1f559
commit 431bd5178e
3 changed files with 22 additions and 5 deletions
+3 -3
View File
@@ -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 {
+15
View File
@@ -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)',
],
];