Repository: PHPOffice/PhpSpreadsheet (php)

Issue:
Regression in 4.3.0: `Date::stringToExcel` requires precision
With the PR #4479, the regex for a valid date/time value was adjusted.
Now it seems to be necessary to specify miliseconds, as the added match group `([.]\d+)` is not optional.

Example:
```php
var_dump(\PhpOffice\PhpSpreadsheet\Shared\Date::stringToExcel("26.05.2025 14:28:00"));
var_dump(\PhpOffice\PhpSpreadsheet\Shared\Date::stringToExcel("26.05.2025 14:28:00.00"));
```

Output 4.2.0: 
```
float(45803.60277777778)
bool(false)
```
Output 4.3.0: 
```
bool(false)
float(45803.60277777778)
```

I would expect the following:
```
float(45803.60277777778)
float(45803.60277777778)
```

Pull request description:
Regression in Date::stringToExcel
Fix #4488.

This is:

- [x] a bugfix
- [ ] a new feature
- [ ] refactoring
- [ ] additional unit tests

Checklist:

- [ ] Changes are covered by unit tests
  - [ ] Changes are covered by existing unit tests
  - [x] New unit tests have been added
- [x] Code style is respected
- [x] Commit message explains **why** the change is made (see https://github.com/erlang/otp/wiki/Writing-good-commit-messages)
- [ ] CHANGELOG.md contains a short summary of the change and a link to the pull request if applicable
- [ ] Documentation is updated as necessary

### Why this change is needed?

Provide an explanation of why this change is needed, with links to any Issues (if appropriate).
If this is a bugfix or a new feature, and there are no existing Issues, then please also create an issue that will make it easier to track progress with this PR.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3e44ed493..ddf885c68 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,12 @@ and this project adheres to [Semantic Versioning](https://semver.org).
 
 - Nothing yet.
 
+## 2025-05-26 - 4.3.1
+
+### Fixed
+
+- Regression in Date::stringToExcel. [Issue #4448](https://github.com/PHPOffice/PhpSpreadsheet/issues/4448) [PR #4449](https://github.com/PHPOffice/PhpSpreadsheet/pull/4449)
+
 ## 2025-05-25 - 4.3.0
 
 ### Added
diff --git a/src/PhpSpreadsheet/Shared/Date.php b/src/PhpSpreadsheet/Shared/Date.php
index 3767a6011..285bd839f 100644
--- a/src/PhpSpreadsheet/Shared/Date.php
+++ b/src/PhpSpreadsheet/Shared/Date.php
@@ -471,7 +471,7 @@ class Date
         if (strlen($dateValue) < 2) {
             return false;
         }
-        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)) {
+        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)) {
             return false;
         }
 


Test patch:
diff --git a/tests/PhpSpreadsheetTests/Shared/DateTest.php b/tests/PhpSpreadsheetTests/Shared/DateTest.php
index 3559b6a33..16f58f343 100644
--- a/tests/PhpSpreadsheetTests/Shared/DateTest.php
+++ b/tests/PhpSpreadsheetTests/Shared/DateTest.php
@@ -189,6 +189,12 @@ class DateTest extends TestCase
         self::assertTrue((bool) Date::stringToExcel('2019-02-28'));
         self::assertTrue((bool) Date::stringToExcel('2019-02-28 11:18'));
         self::assertFalse(Date::stringToExcel('2019-02-28 11:71'));
+        $timestamp1 = Date::stringToExcel('26.05.2025 14:28:00');
+        $timestamp2 = Date::stringToExcel('26.05.2025 14:28:00.00');
+        self::assertNotFalse($timestamp1);
+        self::assertNotFalse($timestamp2);
+        self::assertEqualsWithDelta($timestamp1, 45803.60277777778, 1.0E-10);
+        self::assertSame($timestamp1, $timestamp2);
 
         $date = Date::PHPToExcel('2020-01-01');
         self::assertEquals(43831.0, $date);