Skip to content

Commit d28df11

Browse files
committed
Merge branch 'PHP-7.0' into PHP-7.1
2 parents b96c5b1 + f0519f4 commit d28df11

File tree

8 files changed

+169
-3
lines changed

8 files changed

+169
-3
lines changed

ext/date/lib/tm2unixtime.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static void do_adjust_for_weekday(timelib_time* time)
166166
{
167167
/* To make "this week" work, where the current DOW is a "sunday" */
168168
if (current_dow == 0 && time->relative.weekday != 0) {
169-
time->relative.weekday = -6;
169+
time->relative.weekday -= 7;
170170
}
171171

172172
/* To make "sunday this week" work, where the current DOW is not a
@@ -369,7 +369,7 @@ static timelib_sll do_years(timelib_sll year)
369369
return res;
370370
}
371371

372-
static timelib_sll do_months(timelib_ull month, timelib_ull year)
372+
static timelib_sll do_months(timelib_ull month, timelib_sll year)
373373
{
374374
if (timelib_is_leap(year)) {
375375
return ((month_tab_leap[month - 1] + 1) * SECS_PER_DAY);
@@ -478,7 +478,7 @@ void timelib_update_ts(timelib_time* time, timelib_tzinfo* tzi)
478478
time->sse = res;
479479

480480
time->sse_uptodate = 1;
481-
time->have_relative = time->relative.have_weekday_relative = time->relative.have_special_relative = 0;
481+
time->have_relative = time->relative.have_weekday_relative = time->relative.have_special_relative = time->relative.first_last_day_of = 0;
482482
}
483483

484484
#if 0

ext/date/lib/unixtime2tm.c

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ void timelib_unixtime2local(timelib_time *tm, timelib_sll ts)
189189

190190
timelib_unixtime2gmt(tm, ts - (tm->z * 60) + (tm->dst * 3600));
191191

192+
tm->sse = ts;
192193
tm->z = z;
193194
tm->dst = dst;
194195
break;

ext/date/tests/bug72719.phpt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #72719: Relative datetime format ignores weekday on sundays only
3+
--FILE--
4+
<?php
5+
echo (new DateTimeImmutable('Monday next week 13:00'))->format('l'), "\n";
6+
echo (new DateTimeImmutable('Tuesday next week 14:00'))->format('l'), "\n";
7+
echo (new DateTimeImmutable('Wednesday next week 14:00'))->format('l'), "\n";
8+
echo (new DateTimeImmutable('Thursday next week 15:00'))->format('l'), "\n";
9+
echo (new DateTimeImmutable('Friday next week 16:00'))->format('l'), "\n";
10+
echo (new DateTimeImmutable('Saturday next week 17:00'))->format('l'), "\n";
11+
echo (new DateTimeImmutable('Sunday next week 18:00'))->format('l'), "\n";
12+
?>
13+
--EXPECT--
14+
Monday
15+
Tuesday
16+
Wednesday
17+
Thursday
18+
Friday
19+
Saturday
20+
Sunday

ext/date/tests/bug73294.phpt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #73294: DateTime wrong when date string is negative
3+
--FILE--
4+
<?php
5+
for ( $i = -1050; $i <= -1000; $i++ )
6+
{
7+
$M = "06";
8+
$D = "22";
9+
10+
$dt = new DateTime("{$i}-{$M}-{$D} 00:00:00");
11+
$expected = "{$i}-{$M}-{$D} 00:00:00";
12+
$result = $dt->format('Y-m-d H:i:s');
13+
14+
if ( $expected != $result )
15+
{
16+
echo "Wrong: Should have been {$expected}, was {$result}\n";
17+
}
18+
}
19+
?>
20+
==DONE==
21+
--EXPECT--
22+
==DONE==

ext/date/tests/bug73489.phpt

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #73489: wrong timestamp when call setTimeZone multi times with UTC offset
3+
--FILE--
4+
<?php
5+
// example 1 - Timestamp is changing
6+
$datetime = new DateTime('2016-11-09 20:00:00', new DateTimeZone('UTC'));
7+
var_dump($datetime->getTimestamp());
8+
$datetime->setTimeZone(new DateTimeZone('-03:00'));
9+
$datetime->setTimeZone(new DateTimeZone('-03:00'));
10+
var_dump($datetime->getTimestamp());
11+
12+
// example 2 - Timestamp keeps if you use getTimestamp() before second setTimeZone() calls
13+
$datetime = new DateTime('2016-11-09 20:00:00', new DateTimeZone('UTC'));
14+
var_dump($datetime->getTimestamp());
15+
$datetime->setTimeZone(new DateTimeZone('-03:00'));
16+
$datetime->getTimestamp();
17+
$datetime->setTimeZone(new DateTimeZone('-03:00'));
18+
var_dump($datetime->getTimestamp());
19+
?>
20+
--EXPECT--
21+
int(1478721600)
22+
int(1478721600)
23+
int(1478721600)
24+
int(1478721600)

ext/date/tests/bug73858.phpt

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
--TEST--
2+
Bug #73858: diff() of two relative/described DateTimes is wrong
3+
--FILE--
4+
<?php
5+
/*
6+
In the "verbose setup method" I'm trying setup the DateTime object myself
7+
to see if it's the format string which is parsed in correctly or if it's the DateTime
8+
object which is breaking stuff. From the testing it appears DateTime is broken somehow.
9+
*/
10+
$ss = 'first day of last month midnight';
11+
$es = 'first day of this month midnight - 1 second';
12+
13+
$s = new DateTime($ss);
14+
$e = new DateTime($es);
15+
$d= $e->diff($s);
16+
var_dump($d->days); // 0 ... but should be 30
17+
18+
$s = (new DateTime(null))->setTimestamp(strtotime($ss)); // verbose setup method
19+
$e = (new DateTime(null))->setTimestamp(strtotime($es)); // verbose setup method
20+
$d = $e->diff($s);
21+
var_dump($d->days); // 30 ... and should be 30
22+
23+
/*
24+
Next we will try mix/match the code to see what happens, surprisingly it seems that the end date ($e)
25+
is the important one, if it uses the verbose method it returns the correct values.
26+
*/
27+
$s = (new DateTime(null))->setTimestamp(strtotime($ss)); // verbose setup method
28+
$e = new DateTime($es);
29+
$d= $e->diff($s);
30+
var_dump($d->days); // 0 ... but should be 30
31+
32+
$s = new DateTime($ss);
33+
$e = (new DateTime(null))->setTimestamp(strtotime($es)); // verbose setup method
34+
$d= $e->diff($s);
35+
var_dump($d->days); // 30 ... and should be 30
36+
37+
/*
38+
This test just proves that the $e date is important BUT NOT because it's the one we call the diff() method
39+
on, that's just coincidental that seems to imply that the "- 1 second" in the date string is the problem.
40+
*/
41+
$s = new DateTime($ss);
42+
$e = (new DateTime(null))->setTimestamp(strtotime($es)); // verbose setup method
43+
$d= $s->diff($e);
44+
var_dump($d->days); // 30 ... and should be 30
45+
46+
/*
47+
[Workaround]
48+
This final test seems to prove that the input string is important and that the "- 1 secord" has a negative knock-on
49+
effect on the results of the diff. By modifying the datetime with ->modify everything works as expected ...
50+
it just means you have to be careful of how we work with DateTimes .
51+
*/
52+
$s = new DateTime($ss);
53+
$e = new DateTime('first day of this month midnight');
54+
$e->modify('- 1 second');
55+
var_dump($e->diff($s)->days); // 30 ... and should be 30
56+
?>
57+
--EXPECT--
58+
int(30)
59+
int(30)
60+
int(30)
61+
int(30)
62+
int(30)
63+
int(30)

ext/date/tests/bug73942.phpt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #73942: $date->modify('Friday this week') doesn't return a Friday if $date is a Sunday
3+
--FILE--
4+
<?php
5+
$date1 = "2017-01-08"; // this is a Sunday
6+
$date = new \DateTime($date1);
7+
$date->modify('Friday this week');
8+
$dateFormat = $date->format('Y-m-d');
9+
echo $dateFormat, "\n";
10+
?>
11+
--EXPECT--
12+
2017-01-06

ext/date/tests/bug74057.phpt

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #74057: wrong day when using "this week" in strtotime
3+
--FILE--
4+
<?php
5+
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Sun 2017-01-01")))."\n";
6+
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Mon 2017-01-02")))."\n";
7+
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Tue 2017-01-03")))."\n";
8+
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Wed 2017-01-04")))."\n";
9+
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Thu 2017-01-05")))."\n";
10+
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Fri 2017-01-06")))."\n";
11+
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Sat 2017-01-07")))."\n";
12+
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Sun 2017-01-08")))."\n";
13+
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Mon 2017-01-09")))."\n";
14+
?>
15+
--EXPECT--
16+
Sat 2016-12-31
17+
Sat 2017-01-07
18+
Sat 2017-01-07
19+
Sat 2017-01-07
20+
Sat 2017-01-07
21+
Sat 2017-01-07
22+
Sat 2017-01-07
23+
Sat 2017-01-07
24+
Sat 2017-01-14

0 commit comments

Comments
 (0)