Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  specify next release
  fix proofs name
  remove wip tags
  fix comparing 2 high resolution points in time when more than a second has elapsed
  do not allow to generate a diff lower than a millisecond
  use innmind/static-analysis
  • Loading branch information
Baptouuuu committed Feb 9, 2025
2 parents 1f13a85 + e6b75be commit 4f0683c
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 4.0.2 - 2025-02-09

### Fixed

- When comparing 2 high resolution points in time, if the elapsed time between the 2 is higher than a second it could return that the start point is ahead of the end one.

## 4.0.1 - 2025-01-19

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}
},
"require-dev": {
"vimeo/psalm": "~5.13|dev-master",
"innmind/static-analysis": "~1.1",
"innmind/black-box": "~5.8",
"innmind/coding-standard": "^2.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion proofs/elapsedPeriod.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static function(
given(
Set\Integers::between(0, 999_999_999),
Set\Integers::between(0, 999_999_999),
)->filter(static fn($start, $end) => $end > $start),
)->filter(static fn($start, $end) => $end > $start && ($end - $start) > 1_000),
static function(
$assert,
$startNanoseconds,
Expand Down
2 changes: 1 addition & 1 deletion proofs/move/endOfYear.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

return static function() {
yield proof(
'End of month',
'End of year',
given(Set\Either::any(
PointInTime::any(),
Set\Call::of(static fn() => Clock::live()->now()),
Expand Down
2 changes: 1 addition & 1 deletion proofs/move/startOfDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

return static function() {
yield proof(
'End of day',
'Start of day',
given(Set\Either::any(
PointInTime::any(),
Set\Call::of(static fn() => Clock::live()->now()),
Expand Down
2 changes: 1 addition & 1 deletion proofs/move/startOfMonth.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

return static function() {
yield proof(
'End of day',
'Start of month',
given(Set\Either::any(
PointInTime::any(),
Set\Call::of(static fn() => Clock::live()->now()),
Expand Down
2 changes: 1 addition & 1 deletion proofs/move/startOfYear.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

return static function() {
yield proof(
'End of day',
'Start of year',
given(Set\Either::any(
PointInTime::any(),
Set\Call::of(static fn() => Clock::live()->now()),
Expand Down
40 changes: 40 additions & 0 deletions proofs/pointInTime/highResolution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
declare(strict_types = 1);

use Innmind\TimeContinuum\PointInTime\HighResolution;
use Innmind\BlackBox\Set;

return static function() {
yield proof(
'HighResolution::aheadOf() on different seconds',
given(
Set\Integers::above(0),
Set\Integers::above(0),
Set\Integers::between(0, 999_999_999),
Set\Integers::between(0, 999_999_999),
)->filter(static fn($start, $end) => $start < $end),
static function($assert, $start, $end, $startNanoseconds, $endNanoseconds) {
$start = HighResolution::of($start, $startNanoseconds);
$end = HighResolution::of($end, $endNanoseconds);

$assert->true($end->aheadOf($start));
$assert->false($start->aheadOf($end));
},
);

yield proof(
'HighResolution::aheadOf() in same second',
given(
Set\Integers::above(0),
Set\Integers::between(0, 999_999_999),
Set\Integers::between(0, 999_999_999),
)->filter(static fn($_, $start, $end) => $start < $end),
static function($assert, $second, $start, $end) {
$start = HighResolution::of($second, $start);
$end = HighResolution::of($second, $end);

$assert->true($end->aheadOf($start));
$assert->false($start->aheadOf($end));
},
);
};
4 changes: 4 additions & 0 deletions src/PointInTime/HighResolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public function aheadOf(self $other): bool
return true;
}

if ($this->seconds < $other->seconds) {
return false;
}

return $this->nanoseconds > $other->nanoseconds;
}

Expand Down

0 comments on commit 4f0683c

Please sign in to comment.