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
24 changes: 12 additions & 12 deletions docs/getting-started/clocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,39 @@ This is the clock you should use in your programs. By default it's set to the [U
To access the current time you would do:

```php
use Innmind\TimeContinuum\{
use Innmind\Time\{
Clock,
PointInTime,
Point,
};

$clock = Clock::live();
$point = $clock->now(); // instance of PointInTime
$point = $clock->now(); // instance of Point
echo $point->toString(); // prints something like 2024-11-24T12:34:25+00:00
```

And to build a [`PointInTime`](points-in-time.md) back from a `string`:
And to build a [`Point`](points-in-time.md) back from a `string`:

```php
use Innmind\TimeContinuum\{
use Innmind\Time\{
Clock,
Format,
PointInTime,
Point,
};
use Innmind\Immutable\Attempt;

$time = '2024-11-24T12:34:25+00:00';

$clock = Clock::live();
$at = $clock->at($time, Format::iso8601()); // instance of Attempt<PointInTime>
$at = $clock->at($time, Format::iso8601()); // instance of Attempt<Point>
$point = $at->match(
static fn(PointInTime $point) => $point,
static fn(Point $point) => $point,
static fn() => null,
);
```

The `at` method returns an [`Attempt` monad](https://innmind.org/Immutable/structures/attempt/) that may contain a `PointInTime`. This is in case the `#!php $time` variable contains a value that doesn't correspond to the specified format (here `ISO8601`).
The `at` method returns an [`Attempt` monad](https://innmind.org/Immutable/structures/attempt/) that may contain a `Point`. This is in case the `#!php $time` variable contains a value that doesn't correspond to the specified format (here `ISO8601`).

This means that the `#!php $point` variable here is an instance of `PointInTime` because the `#!php $time` value is valid. If it's invalid then `#!php $point` is `#!php null`.
This means that the `#!php $point` variable here is an instance of `Point` because the `#!php $time` value is valid. If it's invalid then `#!php $point` is `#!php null`.

## Logger

Expand All @@ -51,7 +51,7 @@ This clock will create a log everytime you call `#!php ->now()` or `#!php ->at()
To build this clock you need another clock (typically a live one) and a [PSR logger](https://packagist.org/packages/psr/log):

```php
use Innmind\TimeContinuum\Clock;
use Innmind\Time\Clock;
use Psr\Log\LoggerInterface;

$clock = Clock::logger(
Expand All @@ -71,7 +71,7 @@ This clock is only useful when testing your program. It allows to specify the po
This way you can test your program for special scenarii like a leap year, daylight saving time and so on...

```php
use Innmind\TimeContinuum\{
use Innmind\Time\{
Clock,
Format,
};
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started/elapsed-period.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This is the number of microseconds between two [points in time](points-in-time.md).

```php
use Innmind\TimeContinuum\Clock;
use Innmind\Time\Clock;

$clock = Clock::live();
$start = $clock->now();
Expand All @@ -13,7 +13,7 @@ $end = $clock->now();
$elapsed = $end->elapsedSince($start);
```

`$elapsed` is an instance of `#!php Innmind\TimeContinuum\ElapsedPeriod`.
`$elapsed` is an instance of `#!php Innmind\Time\ElapsedPeriod`.

This is especially useful when working with network I/O to check for timeouts.

Expand Down
16 changes: 8 additions & 8 deletions docs/getting-started/formats.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Formats

A `Format` is a representation on how to convert a [`PointInTime`](points-in-time.md) to a `string`, or vice versa.
A `Format` is a representation on how to convert a [`Point`](points-in-time.md) to a `string`, or vice versa.

By default this library comes with these formats:

```php
use Innmind\TimeContinuum\Format;
use Innmind\Time\Format;

Format::cookie();
Format::iso8601();
Expand All @@ -22,7 +22,7 @@ Formats are wrapped in an object in order to give them a name. When used in your
## Convert to a string

```php
use Innmind\TimeContinuum\{
use Innmind\Time\{
Clock,
Format,
};
Expand All @@ -37,16 +37,16 @@ This would print something like `#!php '2024-11-24T14:50:00+00:00'`.
## Convert from a string

```php
use Innmind\TimeContinuum\{
use Innmind\Time\{
Clock,
Format,
PointInTime,
Point,
};

$point = Clock::live()
->at('some string', Format::iso8601())
->match(
static fn(PointInTime $point) => $point,
static fn(Point $point) => $point,
static fn() => null,
);
```
Expand All @@ -61,7 +61,7 @@ You're encouraged to statically define these formats somewhere in your program l

=== "Static method"
```php
use Innmind\TimeContinuum\Format;
use Innmind\Time\Format;

final class MyFormats
{
Expand All @@ -74,7 +74,7 @@ You're encouraged to statically define these formats somewhere in your program l

=== "Enum"
```php
use Innmind\TimeContinuum\Format;
use Innmind\Time\Format;

enum MyFormats: string implements Format\Custom
{
Expand Down
13 changes: 13 additions & 0 deletions docs/getting-started/halt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Halt process

```php
use Innmind\Time\{
Halt,
Period,
};

$halt = Halt::new();
$halt(Period::second(1))->unwrap();
```

This is the equivalent of `sleep(1)`.
2 changes: 1 addition & 1 deletion docs/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
## Installation

```sh
composer require innmind/time-continuum
composer require innmind/time
```
6 changes: 3 additions & 3 deletions docs/getting-started/periods.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Go forward in time

```php
use Innmind\TimeContinuum\{
use Innmind\Time\{
Clock,
Period,
};
Expand All @@ -21,7 +21,7 @@ $future = Clock::live()
## Go back in time

```php
use Innmind\TimeContinuum\{
use Innmind\Time\{
Clock,
Period,
};
Expand All @@ -39,7 +39,7 @@ $past = Clock::live()
## Compare to an elapsed period

```php
use Innmind\TimeContinuum\{
use Innmind\Time\{
Clock,
Period,
};
Expand Down
6 changes: 3 additions & 3 deletions docs/getting-started/points-in-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

See the [clocks](clocks.md) to learn to have access to these objects.

All examples below use the `#!php $point` variable that reference an instance of `#!php Innmind\TimeContinuum\PointInTime`.
All examples below use the `#!php $point` variable that reference an instance of `#!php Innmind\Time\Point`.

## Year

Expand All @@ -24,7 +24,7 @@ This returns `#!php 365` or `#!php 366` on leap years.
$point->month()->ofYear();
```

This returns a value from the enum `#!php Innmind\TimeContinuum\Calendar\Month`.
This returns a value from the enum `#!php Innmind\Time\Calendar\Month`.

```php
$point->month()->numberOfDays();
Expand All @@ -50,7 +50,7 @@ This returns an `int` between `#!php 1` and `#!php 31`.
$point->day()->ofWeek();
```

This returns a value from the enum `#!php Innmind\TimeContinuum\Calendar\Day`.
This returns a value from the enum `#!php Innmind\Time\Calendar\Day`.

## Hour

Expand Down
6 changes: 3 additions & 3 deletions docs/getting-started/time-offsets.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This is a value retrieved from a [point in time](points-in-time.md) and is expressed in a number of hours and minutes.

```php
use Innmind\TimeContinuum\Clock;
use Innmind\Time\Clock;

$offset = Clock::live()->now()->offset();
```
Expand All @@ -13,10 +13,10 @@ $offset = Clock::live()->now()->offset();

Via this object you cannot know in which [timezone](timezones.md) you're in. If you need to keep track of this you should model this in your program and not rely on this information.

When you have access to a `PointInTime` you can change its offset like this:
When you have access to a `Point` you can change its offset like this:

```php
use Innmind\TimeContinuum\{
use Innmind\Time\{
Clock,
Offset,
};
Expand Down
10 changes: 5 additions & 5 deletions docs/getting-started/timezones.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

A timezone is a [time offset](time-offsets.md) referenced by a city name.

As described in the [terminology](../preface/terminology.md#timezone) section the offset for a city may not always be the same depending when you are in time.
As described in the [terminology](../preface/terminology.md#zone) section the offset for a city may not always be the same depending when you are in time.

Because it can change, a timezone is handled at the [clock](clocks.md) level. By default the clock offset is `+00:00` but you can change it like this:

```php
use Innmind\TimeContinuum\{
use Innmind\Time\{
Clock,
Timezones,
Zones,
};

$utc = Clock::live();
$paris = $utc->switch(
static fn(Timezones $timezones) => $timezones
static fn(Zones $timezones) => $timezones
->europe()
->paris(),
);
Expand All @@ -29,7 +29,7 @@ We now have two clocks. `#!php $utc` is still at `+00:00` and `#!php $paris` wil

## Available timezones

`#!php $timezones` represents an intance of `Innmind\TimeContinuum\Timezones`.
`#!php $timezones` represents an intance of `Innmind\Time\Zones`.

=== "Africa"
```php
Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ hide:
- toc
---

# Welcome to TimeContinnum
# Welcome to Time

TimeContinuum is a time abstraction library.
This is a time abstraction library.

The goal is to provide a safe way to manipulate time in your programs.

Expand All @@ -17,7 +17,7 @@ It achieves this via:

??? example "Sneak peek"
```php
use Innmind\TimeContinuum\{
use Innmind\Time\{
Clock,
Format,
};
Expand Down
2 changes: 1 addition & 1 deletion docs/preface/philosophy.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Philosophy

TimeContinuum is designed around these objectives:
It is designed around these objectives:

- an expressive API through a clear naming
- to handle time with precision
Expand Down
10 changes: 7 additions & 3 deletions docs/preface/terminology.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

A `Clock` is the root object to access time. Like a real clock, each time you demand the time it will provide a new value. This is part of the world that can change.

Unlike real clocks, in a program we often have the use case to convert a `string` back to a [time](#point-in-time) representation (1). Clocks provide a method for this. You can think of it as a factory. Even though this is done by a clock this method is determinist, meaning that you'll always have the same result for the same inputs.
Unlike real clocks, in a program we often have the use case to convert a `string` back to a [time](#point) representation (1). Clocks provide a method for this. You can think of it as a factory. Even though this is done by a clock this method is determinist, meaning that you'll always have the same result for the same inputs.
{.annotate}

1. Such as reading a value from a database.

## Point in time
## Point

As its name suggest it represents a fixed point in time on Earth. It represents time down to the microsecond. It also stores the time offset from [UTC](https://en.wikipedia.org/wiki/UTC%2B00:00).

These objects are generated by clocks.

Once an object is created it can no longer change. But you can still create objects relative to it by specifying a [period](#period) and the direction.

## Timezone
## Zone

A timezone represents a time offset from [UTC](https://en.wikipedia.org/wiki/UTC%2B00:00) for a set of cities on Earth (1).
{.annotate}
Expand Down Expand Up @@ -70,3 +70,7 @@ This is an attempt to solve the problem (1) where the same format is duplicated
{.annotate}

1. We can see this practive in a lot of programs.

## Halt

It represents the way to pause the process for a given [period](#period).
Loading