Skip to content

Commit 80b03df

Browse files
committed
Update documentation before release
1 parent 882577e commit 80b03df

5 files changed

Lines changed: 84 additions & 27 deletions

File tree

README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ Period
88
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/thephpleague/period.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/period/code-structure)
99
[![Total Downloads](https://img.shields.io/packagist/dt/league/period.svg?style=flat-square)](https://packagist.org/packages/league/period)
1010

11-
`Period` is PHP's missing time range API. It is based on [Resolving Feature Envy in the Domain](http://verraes.net/2014/08/resolving-feature-envy-in-the-domain/) by Mathias Verraes and extends the concept to cover all basic operations regarding time ranges.
11+
`Period` is PHP's missing time range API. Based on ideas from [Resolving Feature Envy in the Domain](http://verraes.net/2014/08/resolving-feature-envy-in-the-domain/) by Mathias Verraes, this package extends the concept to cover all basic operations regarding time ranges.
1212

1313
## Highlights
1414

15-
- Treats a time range as an immutable value object
16-
- Exposes many named constructors to ease time range creation
15+
- Represents Interval, Datepoint, Duration and Collection as value objects
16+
- Exposes named constructors to ease object creation
1717
- Covers all basic manipulations related to time range
18+
- Enables working with simple or complex time ranges logic
1819
- Fully documented
1920
- Framework-agnostic
20-
- Composer ready, [PSR-2], and [PSR-4] compliant
2121

2222
Documentation
2323
-------
@@ -38,6 +38,22 @@ Install `Period` using Composer.
3838
$ composer require league/period
3939
```
4040

41+
or download the library and:
42+
43+
- use any other [PSR-4](http://www.php-fig.org/psr/psr-4/) compatible autoloader.
44+
- use the bundle autoloader script as shown below:
45+
46+
~~~php
47+
require 'path/to/period/repo/autoload.php';
48+
49+
use League\Period\Datepoint;
50+
51+
Datepoint::create('2012-05-23')->getDay()->getDateInterval();
52+
//returns new DateInterval('P1D');
53+
~~~
54+
55+
where `path/to/period/repo` represents the path where the library was extracted.
56+
4157
Testing
4258
-------
4359

@@ -68,9 +84,6 @@ Credits
6884
- [Ignace Nyamagana Butera](https://github.com/nyamsprod)
6985
- [All Contributors](https://github.com/thephpleague/period/graphs/contributors)
7086

71-
[PSR-2]: http://www.php-fig.org/psr/psr-2/
72-
[PSR-4]: http://www.php-fig.org/psr/psr-4/
73-
7487
License
7588
-------
7689

docs/4.0/index.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ redirect_from: /examples/
1212
[![Build Status](//img.shields.io/travis/thephpleague/period/master.svg?style=flat-square)](//travis-ci.org/thephpleague/period)
1313
[![Total Downloads](//img.shields.io/packagist/dt/league/period.svg?style=flat-square)](//packagist.org/packages/league/period)
1414

15-
`Period` is PHP's missing time range API. It is based on [Resolving Feature Envy in the Domain](//verraes.net/2014/08/resolving-feature-envy-in-the-domain/) by Mathias Verraes and extends the concept to cover all basic operations regarding interval.
15+
`Period` is PHP's missing time range API. Based on ideas from [Resolving Feature Envy in the Domain](http://verraes.net/2014/08/resolving-feature-envy-in-the-domain/) by Mathias Verraes, this package extends the concept to cover all basic operations regarding time ranges.
1616

1717
<p class="message-info">In your code, you will always have to typehint against the <code>League\Period\Period</code> class directly because it is a immutable value object class marked as final and the library does not provide an interface.</p>
1818

1919
<p class="message-info">Since <code>version 4.1</code> a <code>League\Period\Sequence</code> class is added to improve manipulating a collection of <code>Period</code> objects.</p>
2020

21+
<p class="message-info">Since <code>version 4.4</code> the <code>Period</code> objects supports all types of boundary with the exception of unbounded interval.</p>
22+
2123
## Accessing the interval properties
2224

2325
~~~php
@@ -26,6 +28,7 @@ use League\Period\Period;
2628
$interval = new Period(
2729
new DateTime('2014-10-03 08:12:37'),
2830
new DateTimeImmutable('2014-10-03 08:12:37')
31+
Period::INCLUDE_START_EXCLUDE_END
2932
);
3033
$start = $interval->getStartDate(); //returns a DateTimeImmutable
3134
$end = $interval->getEndDate(); //returns a DateTimeImmutable
@@ -51,13 +54,19 @@ To help easily instantiate your time range and manipulating it, the package come
5154
## Comparing intervals
5255

5356
~~~php
54-
$interval = Period::after('2014-01-01', '1 WEEK');
55-
$alt_interval = Period::fromIsoWeek(2014, 1);
56-
$interval->durationEquals($alt_interval); //returns true
57-
$interval->equals($alt_interval); //returns false
57+
$period = Period::after('2014-01-01', '1 MONTH', Period::INCLUDE_ALL);
58+
$altPeriod = Period::after('2014-01-01', '1 MONTH', Period::EXCLUDE_ALL);
59+
$period->durationEquals($altPeriod), //returns true
60+
$period->equals($altPeriod), //returns false
61+
$period->contains($altPeriod), //returns true
62+
$altPeriod->contains($period), //return false
63+
$period->contains('2014-01-10'), //returns true
64+
Datepoint::create('2014-02-10')->isDuring($period) //returns false
5865
~~~
5966

60-
The class comes with other ways to [compare time ranges](/4.0/comparing/) based on their duration and/or their datepoints.
67+
The class comes with other ways to [compare time ranges](/4.0/comparing/) based on their duration and/or their datepoints.
68+
`Datepoint` extends `DateTimeImmutable` and offers more [methods](/4.0/datepoint/).
69+
6170

6271
## Modifying interval
6372

docs/4.0/upgrading.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,40 @@ The following methods were already marked as deprecated is the `3.x` line. They
4040

4141
### Named constructors
4242

43-
To reduce code and allow more flexibility all named constructors have been removed from the `Period` class. They are replaced by functions defined in the same namespace as the `Period` class.
43+
If you are migrating from `3.x` to `4.2+` version you should use the new named constructors
44+
45+
| old named constructors | new named constructors |
46+
| ------------------------------------- | ----------------------- |
47+
| `Period::createFromYear` | `Period::fromYear` |
48+
| `Period::createFromMonth` | `Period::fromMonth` |
49+
| `Period::createFromWeek` | `Period::fromIsoWeek` |
50+
| `Period::createFromDay` | `Period::fromDay` |
51+
| `Period::createFromSemester` | `Period::fromSemester` |
52+
| `Period::createFromQuarter` | `Period::fromQuarter` |
53+
| `Period::createFromDuration` | `Period::after` |
54+
| `Period::createFromDurationBeforeEnd` | `Period::before` |
55+
56+
The arguments are the same as in version 3 but the new named constructors accepts overflow like `DateTimeImmutable` objects.
57+
58+
Before:
59+
60+
~~~php
61+
use League\Period\Period;
62+
63+
$period = Period::createFromMonth(2013, 15);
64+
// throw LogicException
65+
~~~
66+
67+
After:
68+
69+
~~~php
70+
use League\Period\Period;
71+
72+
$period = Period::fromMonth(2013, 15);
73+
// returns new Period('2014-03-01', '2014-04-01')
74+
~~~
75+
76+
If you are using `4.2-` version you are required to use functions defined in the same namespace as the `Period` class.
4477

4578
| removed named constructors | new functions |
4679
| ------------------------------------- | ----------------- |

docs/_data/project.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ author:
2525
name: 'Ignace Nyamagana Butera'
2626
twitter_account: 'nyamsprod'
2727
highlights:
28-
description: "<code>Period</code> is PHP's Time Range class. It is based on <a href=\"http://verraes.net/2014/08/resolving-feature-envy-in-the-domain/\">Resolving Feature Envy in the Domain</a> by Mathias Verraes and extends the concept to cover all basic operations regarding time ranges."
28+
description: "<code>Period</code> is PHP's Time Range class. Based on ideas from <a href=\"http://verraes.net/2014/08/resolving-feature-envy-in-the-domain/\">Resolving Feature Envy in the Domain</a> by Mathias Verraes, this package extends the concept to cover all basic operations regarding time ranges."
2929
features:
30-
- Treats date and time range as immutable value objects
31-
- Exposes named constructors to ease time range creation
30+
- Uses Immutable Value Objects
31+
- Uses named constructors to ease object creation
3232
- Covers all basic manipulations related to time range
33-
- Framework-agnostic
33+
- Enables working with simple or complex time ranges logic
3434
composer: '$ composer require league/period'
3535
support: 'Once a new major version is released, the previous stable release remains supported for six more months through patches and security fixes.'

docs/index.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $endDate = $date->add($duration);
2121
$interval = new Period($startDate, $endDate);
2222
~~~
2323

24-
To help you start working with `Period` objects, the library comes bundled with many more named constructors to ease manipulating datetime intervals.
24+
To help you start working with `Period` objects, the library comes bundled with many more named constructors to ease datepoint, duration and intervals creation.
2525

2626
## iterating over the interval made simple
2727

@@ -47,15 +47,17 @@ The library also allow iterating backwards over the interval.
4747

4848
## compare intervals and datepoints
4949

50-
You can compare time ranges based on their duration and/or their datepoints.
50+
You can compare time ranges based on their duration, their datepoints and even their boundary types.
5151

5252
~~~php
53-
$period = Period::after('2014-01-01', '1 WEEK');
54-
$altPeriod = Period::fromIsoWeek(2014, 3);
55-
$period->durationEquals($altPeriod); //returns true
56-
$period->equals($altPeriod); //returns false
57-
$period->contains($altPeriod); //returns false
58-
$period->contains('2014-01-02'); //returns true
53+
$period = Period::after('2014-01-01', '1 MONTH', Period::INCLUDE_ALL);
54+
$altPeriod = Period::after('2014-01-01', '1 MONTH', Period::EXCLUDE_ALL);
55+
$period->durationEquals($altPeriod), //returns true
56+
$period->equals($altPeriod), //returns false
57+
$period->contains($altPeriod), //returns true
58+
$altPeriod->contains($period), //return false
59+
$period->contains('2014-01-10'), //returns true
60+
Datepoint::create('2014-02-10')->isDuring($period) //returns false
5961
~~~
6062

6163
## Modifying time ranges
@@ -74,7 +76,7 @@ $altPeriod->durationGreaterThan($period); //return true;
7476
Format and export your `Period` instance following standardized format.
7577

7678
~~~php
77-
$period = Period::after('2014-10-03 08:00:00', 3600);
79+
$period = Period::after('2014-10-03 08:00:00', 3600, Period::INCLUDE_START_EXCLUDE_END);
7880

7981
echo $period; // 2014-10-03T06:00:00.000000Z/2014-10-03T07:00:00.000000Z
8082
echo $period->format('Y-m-d H:i:s'); // [2014-10-03 08:00:00, 2014-10-03 09:00:00)

0 commit comments

Comments
 (0)