Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Clock/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CHANGELOG
7.1
---

* Add `DatePoint::get/setMicroseconds()`
* Add `DatePoint::get/setMicrosecond()`

6.4
---
Expand Down
14 changes: 7 additions & 7 deletions src/Symfony/Component/Clock/DatePoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ public function getTimezone(): \DateTimeZone
return parent::getTimezone() ?: throw new \DateInvalidTimeZoneException('The DatePoint object has no timezone.');
}

public function setMicroseconds(int $microseconds): static
public function setMicrosecond(int $microsecond): static
{
if ($microseconds < 0 || $microseconds > 999999) {
throw new \DateRangeError('DatePoint::setMicroseconds(): Argument #1 ($microseconds) must be between 0 and 999999, '.$microseconds.' given');
if ($microsecond < 0 || $microsecond > 999999) {
throw new \DateRangeError('DatePoint::setMicrosecond(): Argument #1 ($microsecond) must be between 0 and 999999, '.$microsecond.' given');
}

if (\PHP_VERSION_ID < 80400) {
return $this->setTime(...explode('.', $this->format('H.i.s.'.$microseconds)));
return $this->setTime(...explode('.', $this->format('H.i.s.'.$microsecond)));
}

return parent::setMicroseconds($microseconds);
return parent::setMicrosecond($microsecond);
}

public function getMicroseconds(): int
public function getMicrosecond(): int
{
if (\PHP_VERSION_ID >= 80400) {
return parent::getMicroseconds();
return parent::getMicrosecond();
}

return $this->format('u');
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Clock/Tests/DatePointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ public function testModify()
$date->modify('Bad Date');
}

public function testMicroseconds()
public function testMicrosecond()
{
$date = new DatePoint('2010-01-28 15:00:00.123456');

$this->assertSame('2010-01-28 15:00:00.123456', $date->format('Y-m-d H:i:s.u'));

$date = $date->setMicroseconds(789);
$date = $date->setMicrosecond(789);

$this->assertSame('2010-01-28 15:00:00.000789', $date->format('Y-m-d H:i:s.u'));
$this->assertSame(789, $date->getMicroseconds());
$this->assertSame(789, $date->getMicrosecond());

$this->expectException(\DateRangeError::class);
$this->expectExceptionMessage('DatePoint::setMicroseconds(): Argument #1 ($microseconds) must be between 0 and 999999, 1000000 given');
$date->setMicroseconds(1000000);
$this->expectExceptionMessage('DatePoint::setMicrosecond(): Argument #1 ($microsecond) must be between 0 and 999999, 1000000 given');
$date->setMicrosecond(1000000);
}
}