xref: /PHP-8.0/ext/date/tests/bug43452.phpt (revision a9e5e222)
1--TEST--
2Bug #43452 ("weekday" is not equivalent to "1 weekday" of the current weekday is "weekday")
3--FILE--
4<?php
5date_default_timezone_set('Europe/Oslo');
6// <day> is equivalent to 1 <day> and will *not* forward if the current day
7// (November 1st) is the same day of week.
8$day = strtotime( "Thursday Nov 2007" );
9echo date( DateTime::ISO8601, $day ), "\n";
10$day = strtotime( "1 Thursday Nov 2007" );
11echo date( DateTime::ISO8601, $day ), "\n";
12$day = strtotime( "2 Thursday Nov 2007" );
13echo date( DateTime::ISO8601, $day ), "\n";
14$day = strtotime( "3 Thursday Nov 2007" );
15echo date( DateTime::ISO8601, $day ), "\n\n";
16
17// forward one week, then behaves like above for week days
18$day = strtotime( "Thursday Nov 2007" );
19echo date( DateTime::ISO8601, $day ), "\n";
20$day = strtotime( "+1 week Thursday Nov 2007" );
21echo date( DateTime::ISO8601, $day ), "\n";
22$day = strtotime( "+2 week Thursday Nov 2007" );
23echo date( DateTime::ISO8601, $day ), "\n";
24$day = strtotime( "+3 week Thursday Nov 2007" );
25echo date( DateTime::ISO8601, $day ), "\n\n";
26
27// First, second, etc skip to the first/second weekday *after* the current day.
28// This makes "first thursday" equivalent to "+1 week thursday" - but only
29// if the current day-of-week is the one mentioned in the phrase.
30$day = strtotime( "Thursday Nov 2007" );
31echo date( DateTime::ISO8601, $day ), "\n";
32$day = strtotime( "first Thursday Nov 2007" );
33echo date( DateTime::ISO8601, $day ), "\n";
34$day = strtotime( "second Thursday Nov 2007" );
35echo date( DateTime::ISO8601, $day ), "\n";
36$day = strtotime( "third Thursday Nov 2007" );
37echo date( DateTime::ISO8601, $day ), "\n\n";
38
39// Now the same where the current day-of-week does not match the one in the
40// phrase.
41$day = strtotime( "Friday Nov 2007" );
42echo date( DateTime::ISO8601, $day ), "\n";
43$day = strtotime( "first Friday Nov 2007" );
44echo date( DateTime::ISO8601, $day ), "\n";
45$day = strtotime( "second Friday Nov 2007" );
46echo date( DateTime::ISO8601, $day ), "\n";
47$day = strtotime( "third Friday Nov 2007" );
48echo date( DateTime::ISO8601, $day ), "\n\n";
49
50?>
51--EXPECT--
522007-11-01T00:00:00+0100
532007-11-01T00:00:00+0100
542007-11-08T00:00:00+0100
552007-11-15T00:00:00+0100
56
572007-11-01T00:00:00+0100
582007-11-08T00:00:00+0100
592007-11-15T00:00:00+0100
602007-11-22T00:00:00+0100
61
622007-11-01T00:00:00+0100
632007-11-08T00:00:00+0100
642007-11-15T00:00:00+0100
652007-11-22T00:00:00+0100
66
672007-11-02T00:00:00+0100
682007-11-02T00:00:00+0100
692007-11-09T00:00:00+0100
702007-11-16T00:00:00+0100
71