Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aleswita committed Nov 20, 2024
1 parent 6a378dd commit 8cb13c2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DateTimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final public static function from(
\is_string($value) &&
\preg_match('#^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d(\.\d+)?\z#', $value, $matches) === 1
) {
if (($matches[1] ?? 0) > 0) {
if (\array_key_exists(1, $matches)) {
$value = \substr($value, 0, \strlen($value) - \strlen($matches[1])); // remove micro seconds
}

Expand Down
3 changes: 3 additions & 0 deletions tests/DateTimesTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ final class DateTimesTest extends TestCase

$d = DateTimes::from('2000-01-01 00:00:00.123456');
Assert::equal('2000-01-01 00:00:00', DateTimeFormatter::format($d));

$d = DateTimes::from('2020-01-01 08:35:21.000000');
Assert::equal('2020-01-01 08:35:21', DateTimeFormatter::format($d));
}

public function testExtract(): void
Expand Down

0 comments on commit 8cb13c2

Please sign in to comment.