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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"require": {
"php": "~8.4",
"psr/log": "~3.0",
"innmind/immutable": "~6.0"
"innmind/time": "~1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -32,7 +32,7 @@
},
"require-dev": {
"innmind/static-analysis": "~1.3",
"innmind/black-box": "~6.5",
"innmind/black-box": "~6.9",
"innmind/coding-standard": "^2.0.1"
},
"conflict": {
Expand Down
62 changes: 2 additions & 60 deletions fixtures/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,6 @@

namespace Fixtures\Innmind\TimeContinuum;

use Innmind\TimeContinuum\Period as Model;
use Innmind\BlackBox\Set;
use Fixtures\Innmind\Time;

final class Period
{
/**
* @return Set<Model>
*/
public static function any(): Set
{
return Set\Composite::immutable(
Model::of(...),
Set\Integers::between(0, 9999),
Set\Integers::between(0, 12),
Set\Integers::between(0, 31),
Set\Integers::between(0, 23),
Set\Integers::between(0, 59),
Set\Integers::between(0, 59),
Set\Integers::between(0, 999),
Set\Integers::between(0, 999),
)->take(100);
}

/**
* @return Set<Model>
*/
public static function anyNumberOfYear(): Set
{
return Set\Decorate::immutable(
Model::year(...),
Set\Integers::between(0, 9999),
)->take(100);
}

/**
* @return Set<Model>
*/
public static function lessThanAYear(): Set
{
return Set\Composite::immutable(
static function($day, $hour, $minute, $second, $millisecond, $microsecond): Model {
return Model::of(
0,
0,
$day,
$hour,
$minute,
$second,
$millisecond,
$microsecond,
);
},
Set\Integers::between(0, 364),
Set\Integers::between(0, 23),
Set\Integers::between(0, 59),
Set\Integers::between(0, 59),
Set\Integers::between(0, 999),
Set\Integers::between(0, 999),
)->take(100);
}
}
\class_alias(Time\Period::class, Period::class);
72 changes: 2 additions & 70 deletions fixtures/PointInTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,6 @@

namespace Fixtures\Innmind\TimeContinuum;

use Innmind\TimeContinuum\PointInTime as Model;
use Innmind\BlackBox\Set;
use Fixtures\Innmind\Time;

final class PointInTime
{
/**
* @return Set<Model>
*/
public static function any(): Set
{
return self::yearRange(0, 9999)->take(100);
}

/**
* @param string $point String representation of a date
* @return Set<Model>
*/
public static function after(string $point): Set
{
$lower = Model::at(new \DateTimeImmutable($point));

return self::yearRange($lower->year()->toInt(), 9999)
->filter(static function($point) use ($lower): bool {
return $point->aheadOf($lower);
})
->take(100);
}

/**
* @param string $point String representation of a date
* @return Set<Model>
*/
public static function before(string $point): Set
{
$upper = Model::at(new \DateTimeImmutable($point));

return self::yearRange(0, $upper->year()->toInt())
->filter(static function($point) use ($upper): bool {
return $upper->aheadOf($point);
})
->take(100);
}

/**
* @return Set<Model>
*/
private static function yearRange(int $lowerBound, int $upperBound): Set
{
return Set\Composite::immutable(
static function(
int|string ...$components,
): Model {
return Model::at(new \DateTimeImmutable(\sprintf(
'%02s-%02d-%02dT%02d:%02d:%02d.%03d%03d%s%02d:%s',
...$components,
)));
},
Set\Integers::between($lowerBound, $upperBound),
Set\Integers::between(1, 12),
Set\Integers::between(1, 31),
Set\Integers::between(0, 23),
Set\Integers::between(0, 59),
Set\Integers::between(0, 59),
Set\Integers::between(0, 999),
Set\Integers::between(0, 999),
Set\Elements::of('-', '+'),
Set\Integers::between(0, 12),
Set\Elements::of('00', '15', '30', '45'),
);
}
}
\class_alias(Time\Point::class, PointInTime::class);
36 changes: 2 additions & 34 deletions fixtures/Timezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,6 @@

namespace Fixtures\Innmind\TimeContinuum;

use Innmind\TimeContinuum\{
Timezone as Model,
Timezones,
Offset,
};
use Innmind\BlackBox\Set;
use Fixtures\Innmind\Time;

final class Timezone
{
/**
* @return Set\Provider<callable(Timezones): Model>
*/
public static function any(): Set\Provider
{
return Set::compose(
static fn($offset, $daylight) => static fn(Timezones $timezones) => Model::of(
$offset,
$daylight,
),
Set::either(
Set::compose(
Offset::plus(...),
Set::integers()->between(0, 14),
Set::of(0, 15, 30, 45),
),
Set::compose(
Offset::minus(...),
Set::integers()->between(0, 12),
Set::of(0, 15, 30, 45),
),
),
Set::of(true, false),
);
}
}
\class_alias(Time\Zone::class, Timezone::class);
91 changes: 0 additions & 91 deletions proofs/elapsedPeriod.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,13 @@
declare(strict_types = 1);

use Innmind\TimeContinuum\{
PointInTime\HighResolution,
Period,
ElapsedPeriod,
};
use Fixtures\Innmind\TimeContinuum as Fixtures;
use Innmind\BlackBox\Set;

return static function() {
yield proof(
'High resolution elapsed period',
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) => $end > $start),
static function(
$assert,
$startSeconds,
$endSeconds,
$startNanoseconds,
$endNanoseconds,
) {
$start = HighResolution::of($startSeconds, $startNanoseconds);
$end = HighResolution::of($endSeconds, $endNanoseconds);

$assert->true(
$start
->elapsedSince($start)
->equals(
Period::microsecond(0)->asElapsedPeriod(),
),
);
$assert->true(
$end
->elapsedSince($start)
->longerThan(
Period::microsecond(1)->asElapsedPeriod(),
),
);
},
);

yield proof(
'High resolution elapsed period within same second',
given(
Set::integers()->between(0, 999_999_999),
Set::integers()->between(0, 999_999_999),
)->filter(static fn($start, $end) => $end > $start && ($end - $start) > 1_000),
static function(
$assert,
$startNanoseconds,
$endNanoseconds,
) {
$start = HighResolution::of(0, $startNanoseconds);
$end = HighResolution::of(0, $endNanoseconds);

$assert->true(
$start
->elapsedSince($start)
->equals(
Period::microsecond(0)->asElapsedPeriod(),
),
);
$assert->true(
$end
->elapsedSince($start)
->longerThan(
Period::microsecond(1)->asElapsedPeriod(),
),
);
},
);

yield proof(
'Elapsed period',
given(
Expand Down Expand Up @@ -124,30 +57,6 @@ static function($assert, $start, $microsecond) {
},
);

yield proof(
'Negative high resolution elapsed periods throws',
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) => $end > $start),
static function(
$assert,
$startSeconds,
$endSeconds,
$startNanoseconds,
$endNanoseconds,
) {
$start = HighResolution::of($startSeconds, $startNanoseconds);
$end = HighResolution::of($endSeconds, $endNanoseconds);

$assert->throws(
static fn() => $start->elapsedSince($end),
);
},
);

yield test(
'Regression elapsed period',
static function($assert) {
Expand Down
40 changes: 0 additions & 40 deletions proofs/pointInTime/highResolution.php

This file was deleted.

Loading