Skip to content

Commit 188056c

Browse files
committed
Update upgrade documentation for v5 release
1 parent 096f14a commit 188056c

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

docs/5.0/period/properties.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Returns a `DatePeriod` using the `Period` datepoints with the given `$timeDelta`
142142

143143
#### Parameters
144144

145-
- `$startDatePresence` Can be set to **`InitialDatePresence::INCLUDED`** or **`InitialDatePresence::EXCLUDED`** to exclude the initial date from the set of recurring dates within the period.
145+
- `$startDatePresence` Can be set to **`InitialDatePresence::Included`** or **`InitialDatePresence::Excluded`** to exclude the initial date from the set of recurring dates within the period.
146146

147147
#### Examples
148148

@@ -186,7 +186,7 @@ Returns a `Generator` to allow iteration over the instance datepoints, recurring
186186

187187
#### Parameters
188188

189-
- `$endDatePresence` Can be set to **`InitialDatePresence::INCLUDED`** or **`InitialDatePresence::EXCLUDED`** to exclude the initial date from the set of recurring dates within the period.
189+
- `$endDatePresence` Can be set to **`InitialDatePresence::Included`** or **`InitialDatePresence::Excluded`** to exclude the initial date from the set of recurring dates within the period.
190190

191191
#### Examples
192192

@@ -203,7 +203,7 @@ Using the `$endDatePresence` parameter
203203

204204
~~~php
205205
$interval = Period::fromYear('2012-06-05');
206-
$dateRange = $interval->dateRangeBackwards(new DateInterval('P1M'), InitialDatePresence::EXCLUDED);
206+
$dateRange = $interval->dateRangeBackwards(new DateInterval('P1M'), InitialDatePresence::Excluded);
207207
foreach ($dateRange as $datetime) {
208208
echo $datetime->format('Y-m-d');
209209
}

docs/5.0/upgrading.md

+30-14
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,13 @@ Most notably:
188188

189189
to expose the boundaries properties of the `Period` object.
190190

191-
```diff
191+
```php
192192
echo json_encode(Period::fromMonth(2015, 4)), PHP_EOL;
193+
```
194+
195+
will now return the following JSON:
196+
197+
```diff
193198
{
194199
"startDate": "2015-04-01T00:00:00.000000Z",
195200
"endDate": "2015-05-01T00:00:00.000000Z",
@@ -218,15 +223,8 @@ if better or more complex conversion is needed, first convert it using a `DateTi
218223
or a `DatePoint` named constructor.
219224

220225
```diff
221-
use League\Period\Period;
222-
use Carbon\Carbon;
223-
224226
- Period::fromDatepoint('1635585868', '2021-05-24', Period::INCLUDE_ALL);
225-
+ Period::fromDate(
226-
+ Carbon::createFromTimestamp(1635585868),
227-
+ '2021-05-24',
228-
+ Bounds::IncludeAll
229-
+ );
227+
+ Period::fromDate(Carbon::createFromTimestamp(1635585868), '2021-05-24', Bounds::IncludeAll);
230228
```
231229

232230
In version `4.x` a method expecting a duration accepts the following types:
@@ -287,10 +285,15 @@ Creating a Duration out of some seconds as changed, the method only accepts inte
287285

288286
`Period::diff` now returns a `Sequence` object, before it was returning an `array`.
289287

290-
```diff
288+
The following example
289+
```php
291290
$period = Period::fromDate('2013-01-01', '2014-01-01');
292291
$alt = Period::fromDate('2013-01-01', '2014-01-01');
292+
```
293+
294+
will have its return value updated.
293295

296+
```diff
294297
- [] === $alt->diff($period); // return true
295298
+ $alt->diff($period)->isEmpty(); //return true
296299
```
@@ -307,7 +310,7 @@ or not of the initial date object in their returned values.
307310

308311
```diff
309312
- $res = $period->getDatePeriodBackwards('1 DAY', DatePeriod::EXCLUDE_START_DATE);
310-
+ $res = $period->dateRangeBackwards('1 DAY', InitialDatePresence::EXCLUDED);
313+
+ $res = $period->dateRangeBackwards('1 DAY', InitialDatePresence::Excluded);
311314
```
312315

313316
## Changes in bounds related methods
@@ -334,7 +337,9 @@ The array provided by the `Sequence::toList` method will always be a list. While
334337
may change using the `Sequence::sort` method, for instance, the return array indexes will always be re-arranged to
335338
return a proper list.
336339

337-
```diff
340+
The following code will work in both versions:
341+
342+
```php
338343
$day1 = Period::fromDay(2012, 6, 23);
339344
$day2 = Period::fromDay(2012, 6, 12);
340345
$sequence = new Sequence($day1, $day2);
@@ -343,6 +348,11 @@ foreach ($sequence as $offset => $period) {
343348
// first iteration $offset = 1 and $period === $day2
344349
// second iteration $offset = 0 and $period === $day1
345350
}
351+
```
352+
353+
But the returned value will be different:
354+
355+
```diff
346356
- $sequence->toArray(); // returns [1 => $day2, 0 => $day1];
347357
+ $sequence->toList(); // returns [0 => $day2, 1 => $day1];
348358
```
@@ -380,8 +390,14 @@ The `LatinLetter` label generator no longer fall back to using the `0` value. On
380390

381391
The `DecimalNumber` label generator allows negative integer and `O`. Previously they would be silently converted to `1`.
382392

383-
```diff
393+
For the following instance
394+
395+
```php
384396
$labelGenerator = new DecimalNumber(-3);
397+
```
398+
The returned object will behave as follow:
399+
400+
```diff
385401
- $labelGenerator->startingAt(); // returns '1'
386402
+ $labelGenerator->startLabel; // returns '-3'
387403
```
@@ -392,5 +408,5 @@ The `RomanNumber` label generator constructor will throw if the `DecimalNumber::
392408
- $labelGenerator = new RomanNumber(new DecimalNumber(-5), RomanNumber::LOWER);
393409
- $labelGenerator->startingAt(); //returns 'i'
394410
+ $labelGenerator = new RomanNumber(new DecimalNumber(-5), LetterCase::Lower);
395-
// will throw UnableToDrawChart exception
411+
+ //will throw UnableToDrawChart exception
396412
```

0 commit comments

Comments
 (0)