Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  specify next release
  bump minimum version of psalm
  add periods named constructor
  use high resolution time to compare the milliseconds elasped between 2 points in time
  use blackbox 5
  • Loading branch information
Baptouuuu committed Jul 8, 2023
2 parents a7110e5 + 4e5d2d7 commit 4a51122
Show file tree
Hide file tree
Showing 32 changed files with 195 additions and 52 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['8.1', '8.2']
php-version: ['8.2']
dependencies: ['lowest', 'highest']
name: 'PHPUnit'
steps:
Expand All @@ -33,7 +33,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.1', '8.2']
php-version: ['8.2']
dependencies: ['lowest', 'highest']
name: 'Psalm'
steps:
Expand All @@ -54,7 +54,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.1']
php-version: ['8.2']
name: 'CS'
steps:
- name: Checkout
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## 3.3.0 - 2023-07-08

### Added

- `Innmind\TimeContinuum\Earth\PointInTime\Now::elapsedSince()` now use the high resolution time api when comparing to another instance of `Now` (to avoid errors when time _goes back_ due to the system clock re-synchronisation)
- `Innmind\TimeContinuum\Earth\Period\Year::of()`
- `Innmind\TimeContinuum\Earth\Period\Second::of()`
- `Innmind\TimeContinuum\Earth\Period\Month::of()`
- `Innmind\TimeContinuum\Earth\Period\Minute::of()`
- `Innmind\TimeContinuum\Earth\Period\Millisecond::of()`
- `Innmind\TimeContinuum\Earth\Period\Hour::of()`
- `Innmind\TimeContinuum\Earth\Period\Day::of()`

### Changed

- Require `innmind/black-box` `5`

### Removed

- Support for PHP `8.1`

## 3.2.0 - 2023-02-11

### Added
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"issues": "http://github.com/Innmind/TimeContinuum/issues"
},
"require": {
"php": "~8.1",
"php": "~8.2",
"psr/log": "~3.0",
"innmind/immutable": "~4.0"
},
Expand All @@ -31,18 +31,18 @@
}
},
"require-dev": {
"phpunit/phpunit": "~9.0",
"vimeo/psalm": "~4.1",
"innmind/black-box": "^4.0",
"phpunit/phpunit": "~10.2",
"vimeo/psalm": "~5.13",
"innmind/black-box": "~5.0",
"innmind/coding-standard": "^2.0.1"
},
"conflict": {
"innmind/black-box": "<4.0|~5.0"
"innmind/black-box": "<5.0|~6.0"
},
"suggest": {
"innmind/black-box": "For property based testing"
},
"provide": {
"innmind/black-box-sets": "4.0"
"innmind/black-box-sets": "5.0"
}
}
21 changes: 13 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" printerClass="Innmind\BlackBox\PHPUnit\ResultPrinterV9">
<coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd">
<extensions>
<bootstrap class="Innmind\BlackBox\PHPUnit\Extension">
</bootstrap>
</extensions>
<coverage/>
<testsuites>
<testsuite name="Time continuum test suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>.</directory>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Time continuum test suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</source>
</phpunit>
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedBaselineEntry="true"
findUnusedCode="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down
8 changes: 8 additions & 0 deletions src/Earth/Period/Day.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public function __construct(int $day)
$this->day = $day;
}

/**
* @param 0|positive-int $day
*/
public static function of(int $day): self
{
return new self($day);
}

public function years(): int
{
return 0;
Expand Down
8 changes: 8 additions & 0 deletions src/Earth/Period/Hour.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public function __construct(int $hour)
$this->hour = $hour % 24;
}

/**
* @param 0|positive-int $hour
*/
public static function of(int $hour): self
{
return new self($hour);
}

public function years(): int
{
return 0;
Expand Down
8 changes: 8 additions & 0 deletions src/Earth/Period/Millisecond.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public function __construct(int $millisecond)
$this->millisecond = $millisecond % 1000;
}

/**
* @param 0|positive-int $millisecond
*/
public static function of(int $millisecond): self
{
return new self($millisecond);
}

public function years(): int
{
return 0;
Expand Down
8 changes: 8 additions & 0 deletions src/Earth/Period/Minute.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public function __construct(int $minute)
$this->minute = $minute % 60;
}

/**
* @param 0|positive-int $minute
*/
public static function of(int $minute): self
{
return new self($minute);
}

public function years(): int
{
return 0;
Expand Down
8 changes: 8 additions & 0 deletions src/Earth/Period/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public function __construct(int $month)
$this->month = $month % 12;
}

/**
* @param 0|positive-int $month
*/
public static function of(int $month): self
{
return new self($month);
}

public function years(): int
{
return $this->year;
Expand Down
8 changes: 8 additions & 0 deletions src/Earth/Period/Second.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public function __construct(int $second)
$this->second = $second % 60;
}

/**
* @param 0|positive-int $second
*/
public static function of(int $second): self
{
return new self($second);
}

public function years(): int
{
return 0;
Expand Down
8 changes: 8 additions & 0 deletions src/Earth/Period/Year.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public function __construct(int $year)
$this->year = $year;
}

/**
* @param 0|positive-int $year
*/
public static function of(int $year): self
{
return new self($year);
}

public function years(): int
{
return $this->year;
Expand Down
51 changes: 51 additions & 0 deletions src/Earth/PointInTime/HighResolution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
declare(strict_types = 1);

namespace Innmind\TimeContinuum\Earth\PointInTime;

use Innmind\TimeContinuum\Earth\ElapsedPeriod;

/**
* @psalm-immutable
*/
final class HighResolution
{
/** @var 0|positive-int */
private int $seconds;
/** @var 0|positive-int */
private int $nanoseconds;

/**
* @param 0|positive-int $seconds
* @param 0|positive-int $nanoseconds
*/
private function __construct(int $seconds, int $nanoseconds)
{
$this->seconds = $seconds;
$this->nanoseconds = $nanoseconds;
}

public static function now(): self
{
/**
* @var 0|positive-int $seconds
* @var 0|positive-int $nanoseconds
*/
[$seconds, $nanoseconds] = \hrtime();

return new self($seconds, $nanoseconds);
}

public function elapsedSince(self $time): ElapsedPeriod
{
$seconds = $this->seconds - $time->seconds;
$nanoseconds = match ($seconds) {
0 => $this->nanoseconds - $time->nanoseconds,
default => (1_000_000_000 + $this->nanoseconds) - $time->nanoseconds,
};

$milliseconds = ($seconds * 1_000) + (int) ($nanoseconds / 1_000_000);

return ElapsedPeriod::of($milliseconds);
}
}
8 changes: 8 additions & 0 deletions src/Earth/PointInTime/Now.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@
final class Now implements PointInTimeInterface
{
private PointInTimeInterface $point;
private HighResolution $highResolution;

public function __construct()
{
$date = (new \DateTimeImmutable('now'))->format('Y-m-d\TH:i:s.uP');
/** @psalm-suppress ImpureMethodCallAcceptable since only a clock should instantiate this class */
$highResolution = HighResolution::now();

$this->point = new PointInTime($date);
$this->highResolution = $highResolution;
}

public function milliseconds(): int
Expand Down Expand Up @@ -93,6 +97,10 @@ public function timezone(): Timezone

public function elapsedSince(PointInTimeInterface $point): ElapsedPeriodInterface
{
if ($point instanceof self) {
return $this->highResolution->elapsedSince($point->highResolution);
}

return new ElapsedPeriod($this->milliseconds() - $point->milliseconds());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Earth/Move/EndOfDayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function toString(): string
}));
}

public function cases(): array
public static function cases(): array
{
return [
['2016-02-29 13:12:11.675', '2016-02-29 23:59:59.999000'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Earth/Move/EndOfMonthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function toString(): string
}));
}

public function cases(): array
public static function cases(): array
{
return [
['2016-02-01 00:00:00.000', '2016-02-29 23:59:59.999000'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Earth/Move/EndOfYearTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function toString(): string
}));
}

public function cases(): array
public static function cases(): array
{
return [
['2016-02-29 13:12:11.675', '2016-12-31 23:59:59.999000'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Earth/Move/MonthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function toString(): string
$this->assertSame($expectedBackward, $point->format($format));
}

public function cases(): array
public static function cases(): array
{
return [
['2016-02-29 13:12:11.675', '2016-03-29 13:12:11.675000', '2016-01-29 13:12:11.675000'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Earth/Move/StartOfDayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function toString(): string
}));
}

public function cases(): array
public static function cases(): array
{
return [
['2016-02-29 13:12:11.675', '2016-02-29 00:00:00.000000'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Earth/Move/StartOfMonthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function toString(): string
}));
}

public function cases(): array
public static function cases(): array
{
return [
['2016-02-29 13:12:11.675', '2016-02-01 00:00:00.000000'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Earth/Move/StartOfYearTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function toString(): string
}));
}

public function cases(): array
public static function cases(): array
{
return [
['2016-02-29 13:12:11.675', '2016-01-01 00:00:00.000000'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Earth/Period/CompositeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testAsElapsedPeriod()
);
}

public function wrongData()
public static function wrongData()
{
return [
[-1, 0, 0, 0, 0, 0, 0],
Expand Down
2 changes: 1 addition & 1 deletion tests/Earth/Period/DayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DayTest extends TestCase
{
public function testInterface()
{
$period = new Day(1000);
$period = Day::of(1000);

$this->assertInstanceOf(Period::class, $period);
$this->assertSame(0, $period->years());
Expand Down
Loading

0 comments on commit 4a51122

Please sign in to comment.