xref: /PHP-8.2/ext/date/tests/bug51096.phpt (revision f8d79582)
1--TEST--
2Bug #51096 (Test for "first day" vs "first day of")
3--FILE--
4<?php
5$tests = array(
6    'first day',
7    'last day',
8    'next month',
9    'first day next month',
10    'last day next month',
11    'first day of next month',
12    'last day of next month'
13);
14
15foreach ( $tests as $test )
16{
17    $result = date_parse( $test );
18    $rel = $result['relative'];
19    echo $test, "\n- month: ", $rel['month'], '; day: ', $rel['day'],
20         '; first-day-of: ', isset( $rel['first_day_of_month'] ) ? 'true' : 'false',
21         '; last-day-of: ', isset( $rel['last_day_of_month'] ) ? 'true' : 'false', "\n";
22    $date = new DateTime( '2010-03-06 15:21 UTC' );
23    echo '- ', $date->format( DateTime::ISO8601 );
24    $date->modify( $test );
25    echo ' -> ', $date->format( DateTime::ISO8601 ), "\n\n";
26}
27?>
28--EXPECT--
29first day
30- month: 0; day: 1; first-day-of: false; last-day-of: false
31- 2010-03-06T15:21:00+0000 -> 2010-03-07T15:21:00+0000
32
33last day
34- month: 0; day: -1; first-day-of: false; last-day-of: false
35- 2010-03-06T15:21:00+0000 -> 2010-03-05T15:21:00+0000
36
37next month
38- month: 1; day: 0; first-day-of: false; last-day-of: false
39- 2010-03-06T15:21:00+0000 -> 2010-04-06T15:21:00+0000
40
41first day next month
42- month: 1; day: 1; first-day-of: false; last-day-of: false
43- 2010-03-06T15:21:00+0000 -> 2010-04-07T15:21:00+0000
44
45last day next month
46- month: 1; day: -1; first-day-of: false; last-day-of: false
47- 2010-03-06T15:21:00+0000 -> 2010-04-05T15:21:00+0000
48
49first day of next month
50- month: 1; day: 0; first-day-of: true; last-day-of: false
51- 2010-03-06T15:21:00+0000 -> 2010-04-01T15:21:00+0000
52
53last day of next month
54- month: 1; day: 0; first-day-of: false; last-day-of: true
55- 2010-03-06T15:21:00+0000 -> 2010-04-30T15:21:00+0000
56