Skip to content

Commit 1deff50

Browse files
committed
Regression in Date::stringToExcel
Fix PHPOffice#4448.
1 parent 1353714 commit 1deff50

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ and this project adheres to [Semantic Versioning](https://semver.org).
3131

3232
- Nothing yet.
3333

34+
## 2025-05-26 - 4.3.1
35+
36+
### Fixed
37+
38+
- Regression in Date::stringToExcel. [Issue #4448](https://github.com/PHPOffice/PhpSpreadsheet/issues/4448) [PR #4449](https://github.com/PHPOffice/PhpSpreadsheet/pull/4449)
39+
3440
## 2025-05-25 - 4.3.0
3541

3642
### Added

src/PhpSpreadsheet/Shared/Date.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ public static function stringToExcel(string $dateValue): bool|float
471471
if (strlen($dateValue) < 2) {
472472
return false;
473473
}
474-
if (!preg_match('/^(\d{1,4}[ \.\/\-][A-Z]{3,9}([ \.\/\-]\d{1,4})?|[A-Z]{3,9}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?|\d{1,4}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?)( \d{1,2}:\d{1,2}(:\d{1,2}([.]\d+))?)?$/iu', $dateValue)) {
474+
if (!preg_match('/^(\d{1,4}[ \.\/\-][A-Z]{3,9}([ \.\/\-]\d{1,4})?|[A-Z]{3,9}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?|\d{1,4}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?)( \d{1,2}:\d{1,2}(:\d{1,2}([.]\d+)?)?)?$/iu', $dateValue)) {
475475
return false;
476476
}
477477

tests/PhpSpreadsheetTests/Shared/DateTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ public function testVarious(): void
189189
self::assertTrue((bool) Date::stringToExcel('2019-02-28'));
190190
self::assertTrue((bool) Date::stringToExcel('2019-02-28 11:18'));
191191
self::assertFalse(Date::stringToExcel('2019-02-28 11:71'));
192+
$timestamp1 = Date::stringToExcel('26.05.2025 14:28:00');
193+
$timestamp2 = Date::stringToExcel('26.05.2025 14:28:00.00');
194+
self::assertNotFalse($timestamp1);
195+
self::assertNotFalse($timestamp2);
196+
self::assertEqualsWithDelta($timestamp1, 45803.60277777778, 1.0E-10);
197+
self::assertSame($timestamp1, $timestamp2);
192198

193199
$date = Date::PHPToExcel('2020-01-01');
194200
self::assertEquals(43831.0, $date);

0 commit comments

Comments
 (0)