Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
Signed-off-by: azjezz <azjezz@protonmail.com>
  • Loading branch information
azjezz committed Mar 23, 2024
1 parent 2f0d41b commit e654e7b
Show file tree
Hide file tree
Showing 25 changed files with 368 additions and 251 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ compare-benchmark-to-reference:
./vendor/bin/phpbench run --config config/phpbench.json --ref=benchmark_reference

static-analysis: ## run static analysis checks
./vendor/bin/psalm -c config/psalm.xml --show-info=true --no-cache --threads=1
./vendor/bin/psalm -c config/psalm.xml tests/static-analysis --no-cache --threads=1
./vendor/bin/psalm -c config/psalm.xml --show-info=true --no-cache --threads=2
./vendor/bin/psalm -c config/psalm.xml tests/static-analysis --no-cache --threads=2

type-coverage: ## send static analysis type coverage metrics to https://shepherd.dev/
./vendor/bin/psalm -c config/psalm.xml --shepherd --stats --threads=1
Expand Down
6 changes: 3 additions & 3 deletions docs/component/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
#### `Classes`

- [Lock](./../../src/Psl/File/Lock.php#L9)
- [ReadHandle](./../../src/Psl/File/ReadHandle.php#L10)
- [ReadWriteHandle](./../../src/Psl/File/ReadWriteHandle.php#L11)
- [WriteHandle](./../../src/Psl/File/WriteHandle.php#L11)
- [ReadHandle](./../../src/Psl/File/ReadHandle.php#L11)
- [ReadWriteHandle](./../../src/Psl/File/ReadWriteHandle.php#L12)
- [WriteHandle](./../../src/Psl/File/WriteHandle.php#L12)

#### `Enums`

Expand Down
38 changes: 19 additions & 19 deletions docs/component/io.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- [input_handle](./../../src/Psl/IO/input_handle.php#L20)
- [output_handle](./../../src/Psl/IO/output_handle.php#L20)
- [pipe](./../../src/Psl/IO/pipe.php#L24)
- [streaming](./../../src/Psl/IO/streaming.php#L38)
- [streaming](./../../src/Psl/IO/streaming.php#L39)
- [write](./../../src/Psl/IO/write.php#L21)
- [write_error](./../../src/Psl/IO/write_error.php#L23)
- [write_error_line](./../../src/Psl/IO/write_error_line.php#L23)
Expand All @@ -41,7 +41,7 @@
- [CloseWriteHandleInterface](./../../src/Psl/IO/CloseWriteHandleInterface.php#L7)
- [CloseWriteStreamHandleInterface](./../../src/Psl/IO/CloseWriteStreamHandleInterface.php#L9)
- [HandleInterface](./../../src/Psl/IO/HandleInterface.php#L21)
- [ReadHandleInterface](./../../src/Psl/IO/ReadHandleInterface.php#L10)
- [ReadHandleInterface](./../../src/Psl/IO/ReadHandleInterface.php#L12)
- [ReadStreamHandleInterface](./../../src/Psl/IO/ReadStreamHandleInterface.php#L9)
- [ReadWriteHandleInterface](./../../src/Psl/IO/ReadWriteHandleInterface.php#L7)
- [ReadWriteStreamHandleInterface](./../../src/Psl/IO/ReadWriteStreamHandleInterface.php#L9)
Expand All @@ -54,32 +54,32 @@
- [SeekWriteHandleInterface](./../../src/Psl/IO/SeekWriteHandleInterface.php#L7)
- [SeekWriteStreamHandleInterface](./../../src/Psl/IO/SeekWriteStreamHandleInterface.php#L9)
- [StreamHandleInterface](./../../src/Psl/IO/StreamHandleInterface.php#L9)
- [WriteHandleInterface](./../../src/Psl/IO/WriteHandleInterface.php#L10)
- [WriteHandleInterface](./../../src/Psl/IO/WriteHandleInterface.php#L12)
- [WriteStreamHandleInterface](./../../src/Psl/IO/WriteStreamHandleInterface.php#L9)

#### `Classes`

- [CloseReadStreamHandle](./../../src/Psl/IO/CloseReadStreamHandle.php#L12)
- [CloseReadWriteStreamHandle](./../../src/Psl/IO/CloseReadWriteStreamHandle.php#L12)
- [CloseSeekReadStreamHandle](./../../src/Psl/IO/CloseSeekReadStreamHandle.php#L12)
- [CloseSeekReadWriteStreamHandle](./../../src/Psl/IO/CloseSeekReadWriteStreamHandle.php#L12)
- [CloseReadStreamHandle](./../../src/Psl/IO/CloseReadStreamHandle.php#L13)
- [CloseReadWriteStreamHandle](./../../src/Psl/IO/CloseReadWriteStreamHandle.php#L13)
- [CloseSeekReadStreamHandle](./../../src/Psl/IO/CloseSeekReadStreamHandle.php#L13)
- [CloseSeekReadWriteStreamHandle](./../../src/Psl/IO/CloseSeekReadWriteStreamHandle.php#L13)
- [CloseSeekStreamHandle](./../../src/Psl/IO/CloseSeekStreamHandle.php#L10)
- [CloseSeekWriteStreamHandle](./../../src/Psl/IO/CloseSeekWriteStreamHandle.php#L12)
- [CloseSeekWriteStreamHandle](./../../src/Psl/IO/CloseSeekWriteStreamHandle.php#L13)
- [CloseStreamHandle](./../../src/Psl/IO/CloseStreamHandle.php#L10)
- [CloseWriteStreamHandle](./../../src/Psl/IO/CloseWriteStreamHandle.php#L12)
- [MemoryHandle](./../../src/Psl/IO/MemoryHandle.php#L13)
- [ReadStreamHandle](./../../src/Psl/IO/ReadStreamHandle.php#L12)
- [ReadWriteStreamHandle](./../../src/Psl/IO/ReadWriteStreamHandle.php#L12)
- [Reader](./../../src/Psl/IO/Reader.php#L15)
- [SeekReadStreamHandle](./../../src/Psl/IO/SeekReadStreamHandle.php#L12)
- [SeekReadWriteStreamHandle](./../../src/Psl/IO/SeekReadWriteStreamHandle.php#L12)
- [CloseWriteStreamHandle](./../../src/Psl/IO/CloseWriteStreamHandle.php#L13)
- [MemoryHandle](./../../src/Psl/IO/MemoryHandle.php#L14)
- [ReadStreamHandle](./../../src/Psl/IO/ReadStreamHandle.php#L13)
- [ReadWriteStreamHandle](./../../src/Psl/IO/ReadWriteStreamHandle.php#L13)
- [Reader](./../../src/Psl/IO/Reader.php#L16)
- [SeekReadStreamHandle](./../../src/Psl/IO/SeekReadStreamHandle.php#L13)
- [SeekReadWriteStreamHandle](./../../src/Psl/IO/SeekReadWriteStreamHandle.php#L13)
- [SeekStreamHandle](./../../src/Psl/IO/SeekStreamHandle.php#L10)
- [SeekWriteStreamHandle](./../../src/Psl/IO/SeekWriteStreamHandle.php#L12)
- [WriteStreamHandle](./../../src/Psl/IO/WriteStreamHandle.php#L12)
- [SeekWriteStreamHandle](./../../src/Psl/IO/SeekWriteStreamHandle.php#L13)
- [WriteStreamHandle](./../../src/Psl/IO/WriteStreamHandle.php#L13)

#### `Traits`

- [ReadHandleConvenienceMethodsTrait](./../../src/Psl/IO/ReadHandleConvenienceMethodsTrait.php#L15)
- [WriteHandleConvenienceMethodsTrait](./../../src/Psl/IO/WriteHandleConvenienceMethodsTrait.php#L16)
- [ReadHandleConvenienceMethodsTrait](./../../src/Psl/IO/ReadHandleConvenienceMethodsTrait.php#L16)
- [WriteHandleConvenienceMethodsTrait](./../../src/Psl/IO/WriteHandleConvenienceMethodsTrait.php#L17)


2 changes: 1 addition & 1 deletion docs/component/shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#### `Functions`

- [execute](./../../src/Psl/Shell/execute.php#L41)
- [execute](./../../src/Psl/Shell/execute.php#L42)
- [stream_unpack](./../../src/Psl/Shell/stream_unpack.php#L30)
- [unpack](./../../src/Psl/Shell/unpack.php#L16)

Expand Down
2 changes: 1 addition & 1 deletion docs/component/tcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#### `Functions`

- [connect](./../../src/Psl/TCP/connect.php#L18)
- [connect](./../../src/Psl/TCP/connect.php#L19)

#### `Classes`

Expand Down
2 changes: 1 addition & 1 deletion docs/component/unix.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#### `Functions`

- [connect](./../../src/Psl/Unix/connect.php#L18)
- [connect](./../../src/Psl/Unix/connect.php#L19)

#### `Classes`

Expand Down
4 changes: 2 additions & 2 deletions examples/async/usleep.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
require __DIR__ . '/../../vendor/autoload.php';

Async\main(static function (): int {
$start = DateTime\Timestamp::now();
$start = DateTime\Timestamp::monotonic();

Async\concurrently([
static fn() => Async\sleep(DateTime\Duration::hours(0)),
Expand All @@ -23,7 +23,7 @@
static fn() => Async\sleep(DateTime\Duration::milliseconds(2000)),
]);

$duration = DateTime\Timestamp::now()->since($start);
$duration = DateTime\Timestamp::monotonic()->since($start);

IO\write_error_line("duration : %s.", $duration->toString(max_decimals: 5));

Expand Down
4 changes: 2 additions & 2 deletions examples/io/benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

Async\Scheduler::delay($seconds, static fn() => $input->close());

$start = DateTime\Timestamp::now();
$start = DateTime\Timestamp::monotonic();
$i = 0;
try {
while ($chunk = $input->read(65536)) {
Expand All @@ -53,7 +53,7 @@
} catch (IO\Exception\AlreadyClosedException) {
}

$duration = DateTime\Timestamp::now()->since($start);
$duration = DateTime\Timestamp::monotonic()->since($start);
$bytes = $i * 65536;
$bytes_formatted = Math\round($bytes / 1024 / 1024 / $duration->getTotalSeconds(), 1);

Expand Down
6 changes: 3 additions & 3 deletions examples/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
IO\write_error_line('- %s/%s -> started', $component, $script);

$awaitables[] = Async\run(static function() use($component, $script, $file): array {
$start = DateTime\Timestamp::now();
$start = DateTime\Timestamp::monotonic();
Shell\execute(PHP_BINARY, [$file]);
$duration = DateTime\Timestamp::now()->since($start);
$duration = DateTime\Timestamp::monotonic()->since($start);

return [$component, $script, $duration];
});
Expand All @@ -47,7 +47,7 @@
foreach (Async\Awaitable::iterate($awaitables) as $awaitable) {
[$component, $script, $duration] = $awaitable->await();

IO\write_error_line('+ %s/%s -> finished in %s', $component, $script, $duration);
IO\write_error_line('+ %s/%s -> finished in %s', $component, $script, $duration->toString(10));
}

return 0;
Expand Down
15 changes: 14 additions & 1 deletion sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,24 @@
require 'vendor/autoload.php';

Async\main(static function(): void {
$a = DateTime\Timestamp::now();
$b = DateTime\Timestamp::now();

var_dump($b->since($a)->toString(20));

$a = DateTime\Timestamp::monotonic();
$b = DateTime\Timestamp::monotonic();

var_dump($b->since($a)->toString(20));

$someday = DateTime\DateTime::fromTimestamp(
DateTime\Timestamp::fromRaw(1711846900),
DateTime\Timezone::EuropeLondon,
DateTime\Timestamp::fromRaw(1711846900),
);

var_dump($someday->format(DateTime\DatePattern::Http->value));
die();

IO\write_line('The offset of the timezone: %s', $someday->getTimezone()->getOffset($someday)->getTotalMinutes());
IO\write_line('The raw offset of the timezone: %s', $someday->getTimezone()->getRawOffset()->getTotalMinutes());
IO\write_line('The dst savings of the timezone: %s', $someday->getTimezone()->getDaylightSavingTimeSavings()->getTotalMinutes());
Expand Down
3 changes: 2 additions & 1 deletion src/Psl/DateTime/DatePattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ enum DatePattern: string
case Iso8601 = 'yyyy-MM-dd\'T\'HH:mm:ssXXX';
case Http = 'EEE, dd MMM yyyy HH:mm:ss zzz';
case Cookie = 'EEEE, dd-MMM-yyyy HH:mm:ss zzz';
case Sql = 'yyyy-MM-dd HH:mm:ss';
case SqlDate = 'yyyy-MM-dd';
case SqlDateTime = 'yyyy-MM-dd HH:mm:ss';
case XmlRpc = 'yyyyMMdd\'T\'HH:mm:ss';
case IsoWeekDate = 'Y-ww-E';
case IsoOrdinalDate = 'yyyy-DDD';
Expand Down
Loading

0 comments on commit e654e7b

Please sign in to comment.