Skip to content

Commit

Permalink
Merge pull request #305 from cakephp/set-microseconds
Browse files Browse the repository at this point in the history
Add microsecond() setter
  • Loading branch information
markstory authored Oct 17, 2021
2 parents 638b649 + 68762da commit 3ecd6e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Traits/ModifierTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,17 @@ public function second(int $value): ChronosInterface
return $this->setTime($this->hour, $this->minute, $value);
}

/**
* Set the instance's microsecond
*
* @param int $value The microsecond value.
* @return static
*/
public function microsecond(int $value): ChronosInterface
{
return $this->setTime($this->hour, $this->minute, $this->second, $value);
}

/**
* Add years to the instance. Positive $value travel forward while
* negative $value travel into the past.
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/DateTime/FluidSettersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ public function testFluidSecondSetterWithWrap($class)
$this->assertSame(2, $d->second);
}

/**
* @dataProvider classNameProvider
* @return void
*/
public function testFluidMicroecondSetter($class)
{
$d = $class::now();
$second = $d->second;
$d = $d->microsecond(2);
$this->assertTrue($d instanceof $class);
$this->assertSame(2, $d->microsecond);
$this->assertSame($second, $d->second);
}

/**
* @dataProvider classNameProvider
* @return void
Expand Down

0 comments on commit 3ecd6e7

Please sign in to comment.