Skip to content

Commit

Permalink
remove PointInTime::milliseconds()
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Nov 24, 2024
1 parent 828bb7c commit 583d97f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
- `Innmind\TimeContinuum\PointInTime\Year::toString()`
- `Innmind\TimeContinuum\ElapsedPeriod::maybe()`
- `Innmind\TimeContinuum\ElapsedPeriod::ofPeriod()`
- `Innmind\TimeContinuum\PointInTime::milliseconds()`

## 3.4.1 - 2023-09-17

Expand Down
13 changes: 4 additions & 9 deletions src/PointInTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ public static function now(): self
);
}

/**
* Since 1970-01-01T00:00:00+00:00
*/
public function milliseconds(): int
{
return (int) $this->date->format('Uv');
}

public function year(): Year
{
return Year::of((int) $this->date->format('Y'));
Expand Down Expand Up @@ -150,7 +142,10 @@ public function elapsedSince(self $point): ElapsedPeriod
return $this->highResolution->elapsedSince($point->highResolution);
}

$milliseconds = $this->milliseconds() - $point->milliseconds();
$seconds = ((int) $this->date->format('U')) - ((int) $point->date->format('U'));
$milliseconds = $seconds * 1_000;
$milliseconds += $this->millisecond()->toInt();
$milliseconds -= $point->millisecond()->toInt();
$microseconds = $milliseconds * 1_000;
$microseconds += $this->microsecond()->toInt();
$microseconds -= $point->microsecond()->toInt();
Expand Down
13 changes: 8 additions & 5 deletions tests/Fixtures/PointInTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
Set,
Random,
};
use Innmind\TimeContinuum\PointInTime as Model;
use Innmind\TimeContinuum\{
PointInTime as Model,
Format,
};
use Innmind\BlackBox\PHPUnit\Framework\TestCase;

class PointInTimeTest extends TestCase
Expand Down Expand Up @@ -37,8 +40,8 @@ public function testAfter()

foreach ($points->values(Random::default) as $point) {
$this->assertGreaterThanOrEqual(
$start->milliseconds(),
$point->unwrap()->milliseconds(),
(int) $start->format(Format::of('U')),
(int) $point->unwrap()->format(Format::of('U')),
);
}
}
Expand All @@ -53,8 +56,8 @@ public function testBefore()

foreach ($points->values(Random::default) as $point) {
$this->assertLessThanOrEqual(
$start->milliseconds(),
$point->unwrap()->milliseconds(),
(int) $start->format(Format::of('U')),
(int) $point->unwrap()->format(Format::of('U')),
);
}
}
Expand Down
3 changes: 0 additions & 3 deletions tests/NowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public function testInterface()
//and the one in Now::__construct
$this->assertTrue($point->millisecond()->toInt() >= $now - ($timestamp * 1000));
$this->assertTrue($point->millisecond()->toInt() <= $now - ($timestamp * 1000) + 50);
$this->assertTrue($point->milliseconds() >= $now);
$this->assertTrue($point->milliseconds() <= $now + 50);
$timezone = \date('P', $timestamp);
$timezone = $timezone === '+00:00' ? 'Z' : $timezone;
$this->assertSame($timezone, $point->offset()->toString());
Expand Down Expand Up @@ -80,7 +78,6 @@ public function testChangeOffset()
$this->assertNotSame($point->minute(), $point2->minute());
$this->assertNotSame($point->second(), $point2->second());
$this->assertNotSame($point->millisecond(), $point2->millisecond());
$this->assertSame($point->milliseconds(), $point2->milliseconds());
$this->assertSame((int) $now->format('Y'), $point2->year()->toInt());
$this->assertSame((int) $now->format('m'), $point2->month()->ofYear()->toInt());
$this->assertSame((int) $now->format('d'), $point2->day()->ofMonth());
Expand Down
5 changes: 0 additions & 5 deletions tests/PointInTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ public function testInterface()
$this->assertSame(1, $point->minute()->toInt());
$this->assertSame(30, $point->second()->toInt());
$this->assertSame(123, $point->millisecond()->toInt());
$this->assertSame(
(new \DateTimeImmutable('2016-10-05T08:01:30.123+02:00'))->getTimestamp() * 1000 + $point->millisecond()->toInt(),
$point->milliseconds(),
);
$this->assertSame('+02:00', $point->offset()->toString());
$this->assertSame('2016-10-05T08:01:30+02:00', $point->toString());
}
Expand Down Expand Up @@ -79,7 +75,6 @@ public function testChangeOffset()
$this->assertNotSame($point->minute(), $point2->minute());
$this->assertNotSame($point->second(), $point2->second());
$this->assertNotSame($point->millisecond(), $point2->millisecond());
$this->assertSame($point->milliseconds(), $point2->milliseconds());
$this->assertSame(2016, $point2->year()->toInt());
$this->assertSame(10, $point2->month()->ofYear()->toInt());
$this->assertSame(5, $point2->day()->ofMonth());
Expand Down

0 comments on commit 583d97f

Please sign in to comment.