4
4
5
5
namespace PhpOffice \PhpSpreadsheetTests \Style ;
6
6
7
+ use PhpOffice \PhpSpreadsheet \Calculation \Functions ;
7
8
use PhpOffice \PhpSpreadsheet \Shared \StringHelper ;
8
9
use PhpOffice \PhpSpreadsheet \Style \NumberFormat ;
9
10
use PhpOffice \PhpSpreadsheet \Style \NumberFormat \NumberFormatter ;
11
+ use PHPUnit \Framework \Attributes \DataProvider ;
10
12
use PHPUnit \Framework \TestCase ;
11
13
12
14
class NumberFormatTest extends TestCase
13
15
{
16
+ private string $ compatibilityMode ;
17
+
14
18
protected function setUp (): void
15
19
{
16
20
StringHelper::setDecimalSeparator ('. ' );
17
21
StringHelper::setThousandsSeparator (', ' );
22
+ $ this ->compatibilityMode = Functions::getCompatibilityMode ();
18
23
}
19
24
20
25
protected function tearDown (): void
21
26
{
22
27
StringHelper::setCurrencyCode (null );
23
28
StringHelper::setDecimalSeparator (null );
24
29
StringHelper::setThousandsSeparator (null );
30
+ Functions::setCompatibilityMode ($ this ->compatibilityMode );
25
31
}
26
32
27
33
/**
28
34
* @param null|bool|float|int|string $args string to be formatted
29
35
*/
30
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerNumberFormat ' )]
36
+ #[DataProvider('providerNumberFormat ' )]
31
37
public function testFormatValueWithMask (mixed $ expectedResult , mixed ...$ args ): void
32
38
{
33
39
$ result = NumberFormat::toFormattedString (...$ args );
@@ -42,7 +48,7 @@ public static function providerNumberFormat(): array
42
48
/**
43
49
* @param null|bool|float|int|string $args string to be formatted
44
50
*/
45
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerNumberFormatFractions ' )]
51
+ #[DataProvider('providerNumberFormatFractions ' )]
46
52
public function testFormatValueWithMaskFraction (mixed $ expectedResult , mixed ...$ args ): void
47
53
{
48
54
$ result = NumberFormat::toFormattedString (...$ args );
@@ -57,7 +63,7 @@ public static function providerNumberFormatFractions(): array
57
63
/**
58
64
* @param null|bool|float|int|string $args string to be formatted
59
65
*/
60
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerNumberFormatDates ' )]
66
+ #[DataProvider('providerNumberFormatDates ' )]
61
67
public function testFormatValueWithMaskDate (mixed $ expectedResult , mixed ...$ args ): void
62
68
{
63
69
$ result = NumberFormat::toFormattedString (...$ args );
@@ -69,6 +75,23 @@ public static function providerNumberFormatDates(): array
69
75
return require 'tests/data/Style/NumberFormatDates.php ' ;
70
76
}
71
77
78
+ public function testDatesOpenOfficeGnumericNonPositive (): void
79
+ {
80
+ Functions::setCompatibilityMode (
81
+ Functions::COMPATIBILITY_OPENOFFICE
82
+ );
83
+ $ fmt1 = 'yyyy-mm-dd ' ;
84
+ $ rslt = NumberFormat::toFormattedString (0 , $ fmt1 );
85
+ self ::assertSame ('1899-12-30 ' , $ rslt );
86
+ $ rslt = NumberFormat::toFormattedString (-2 , $ fmt1 );
87
+ self ::assertSame ('1899-12-28 ' , $ rslt );
88
+ $ rslt = NumberFormat::toFormattedString (-2.4 , $ fmt1 );
89
+ self ::assertSame ('1899-12-27 ' , $ rslt );
90
+ $ fmt2 = 'yyyy-mm-dd hh:mm:ss AM/PM ' ;
91
+ $ rslt = NumberFormat::toFormattedString (-2.4 , $ fmt2 );
92
+ self ::assertSame ('1899-12-27 02:24:00 PM ' , $ rslt );
93
+ }
94
+
72
95
public function testCurrencyCode (): void
73
96
{
74
97
// "Currency symbol" replaces $ in some cases, not in others
@@ -83,7 +106,7 @@ public function testCurrencyCode(): void
83
106
StringHelper::setCurrencyCode ($ cur );
84
107
}
85
108
86
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerNoScientific ' )]
109
+ #[DataProvider('providerNoScientific ' )]
87
110
public function testNoScientific (string $ expectedResult , string $ numericString ): void
88
111
{
89
112
$ result = NumberFormatter::floatStringConvertScientific ($ numericString );
0 commit comments