mirror of
https://github.com/php/php-src.git
synced 2024-12-11 10:54:47 +08:00
Merge branch 'PHP-7.1'
This commit is contained in:
commit
5dc825889d
@ -166,7 +166,7 @@ static void do_adjust_for_weekday(timelib_time* time)
|
||||
{
|
||||
/* To make "this week" work, where the current DOW is a "sunday" */
|
||||
if (current_dow == 0 && time->relative.weekday != 0) {
|
||||
time->relative.weekday = -6;
|
||||
time->relative.weekday -= 7;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
return res;
|
||||
}
|
||||
|
||||
static timelib_sll do_months(timelib_ull month, timelib_ull year)
|
||||
static timelib_sll do_months(timelib_ull month, timelib_sll year)
|
||||
{
|
||||
if (timelib_is_leap(year)) {
|
||||
return ((month_tab_leap[month - 1] + 1) * SECS_PER_DAY);
|
||||
@ -478,7 +478,7 @@ void timelib_update_ts(timelib_time* time, timelib_tzinfo* tzi)
|
||||
time->sse = res;
|
||||
|
||||
time->sse_uptodate = 1;
|
||||
time->have_relative = time->relative.have_weekday_relative = time->relative.have_special_relative = 0;
|
||||
time->have_relative = time->relative.have_weekday_relative = time->relative.have_special_relative = time->relative.first_last_day_of = 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -189,6 +189,7 @@ void timelib_unixtime2local(timelib_time *tm, timelib_sll ts)
|
||||
|
||||
timelib_unixtime2gmt(tm, ts - (tm->z * 60) + (tm->dst * 3600));
|
||||
|
||||
tm->sse = ts;
|
||||
tm->z = z;
|
||||
tm->dst = dst;
|
||||
break;
|
||||
|
20
ext/date/tests/bug72719.phpt
Normal file
20
ext/date/tests/bug72719.phpt
Normal file
@ -0,0 +1,20 @@
|
||||
--TEST--
|
||||
Bug #72719: Relative datetime format ignores weekday on sundays only
|
||||
--FILE--
|
||||
<?php
|
||||
echo (new DateTimeImmutable('Monday next week 13:00'))->format('l'), "\n";
|
||||
echo (new DateTimeImmutable('Tuesday next week 14:00'))->format('l'), "\n";
|
||||
echo (new DateTimeImmutable('Wednesday next week 14:00'))->format('l'), "\n";
|
||||
echo (new DateTimeImmutable('Thursday next week 15:00'))->format('l'), "\n";
|
||||
echo (new DateTimeImmutable('Friday next week 16:00'))->format('l'), "\n";
|
||||
echo (new DateTimeImmutable('Saturday next week 17:00'))->format('l'), "\n";
|
||||
echo (new DateTimeImmutable('Sunday next week 18:00'))->format('l'), "\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
Monday
|
||||
Tuesday
|
||||
Wednesday
|
||||
Thursday
|
||||
Friday
|
||||
Saturday
|
||||
Sunday
|
22
ext/date/tests/bug73294.phpt
Normal file
22
ext/date/tests/bug73294.phpt
Normal file
@ -0,0 +1,22 @@
|
||||
--TEST--
|
||||
Bug #73294: DateTime wrong when date string is negative
|
||||
--FILE--
|
||||
<?php
|
||||
for ( $i = -1050; $i <= -1000; $i++ )
|
||||
{
|
||||
$M = "06";
|
||||
$D = "22";
|
||||
|
||||
$dt = new DateTime("{$i}-{$M}-{$D} 00:00:00");
|
||||
$expected = "{$i}-{$M}-{$D} 00:00:00";
|
||||
$result = $dt->format('Y-m-d H:i:s');
|
||||
|
||||
if ( $expected != $result )
|
||||
{
|
||||
echo "Wrong: Should have been {$expected}, was {$result}\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
==DONE==
|
||||
--EXPECT--
|
||||
==DONE==
|
24
ext/date/tests/bug73489.phpt
Normal file
24
ext/date/tests/bug73489.phpt
Normal file
@ -0,0 +1,24 @@
|
||||
--TEST--
|
||||
Bug #73489: wrong timestamp when call setTimeZone multi times with UTC offset
|
||||
--FILE--
|
||||
<?php
|
||||
// example 1 - Timestamp is changing
|
||||
$datetime = new DateTime('2016-11-09 20:00:00', new DateTimeZone('UTC'));
|
||||
var_dump($datetime->getTimestamp());
|
||||
$datetime->setTimeZone(new DateTimeZone('-03:00'));
|
||||
$datetime->setTimeZone(new DateTimeZone('-03:00'));
|
||||
var_dump($datetime->getTimestamp());
|
||||
|
||||
// example 2 - Timestamp keeps if you use getTimestamp() before second setTimeZone() calls
|
||||
$datetime = new DateTime('2016-11-09 20:00:00', new DateTimeZone('UTC'));
|
||||
var_dump($datetime->getTimestamp());
|
||||
$datetime->setTimeZone(new DateTimeZone('-03:00'));
|
||||
$datetime->getTimestamp();
|
||||
$datetime->setTimeZone(new DateTimeZone('-03:00'));
|
||||
var_dump($datetime->getTimestamp());
|
||||
?>
|
||||
--EXPECT--
|
||||
int(1478721600)
|
||||
int(1478721600)
|
||||
int(1478721600)
|
||||
int(1478721600)
|
63
ext/date/tests/bug73858.phpt
Normal file
63
ext/date/tests/bug73858.phpt
Normal file
@ -0,0 +1,63 @@
|
||||
--TEST--
|
||||
Bug #73858: diff() of two relative/described DateTimes is wrong
|
||||
--FILE--
|
||||
<?php
|
||||
/*
|
||||
In the "verbose setup method" I'm trying setup the DateTime object myself
|
||||
to see if it's the format string which is parsed in correctly or if it's the DateTime
|
||||
object which is breaking stuff. From the testing it appears DateTime is broken somehow.
|
||||
*/
|
||||
$ss = 'first day of last month midnight';
|
||||
$es = 'first day of this month midnight - 1 second';
|
||||
|
||||
$s = new DateTime($ss);
|
||||
$e = new DateTime($es);
|
||||
$d= $e->diff($s);
|
||||
var_dump($d->days); // 0 ... but should be 30
|
||||
|
||||
$s = (new DateTime(null))->setTimestamp(strtotime($ss)); // verbose setup method
|
||||
$e = (new DateTime(null))->setTimestamp(strtotime($es)); // verbose setup method
|
||||
$d = $e->diff($s);
|
||||
var_dump($d->days); // 30 ... and should be 30
|
||||
|
||||
/*
|
||||
Next we will try mix/match the code to see what happens, surprisingly it seems that the end date ($e)
|
||||
is the important one, if it uses the verbose method it returns the correct values.
|
||||
*/
|
||||
$s = (new DateTime(null))->setTimestamp(strtotime($ss)); // verbose setup method
|
||||
$e = new DateTime($es);
|
||||
$d= $e->diff($s);
|
||||
var_dump($d->days); // 0 ... but should be 30
|
||||
|
||||
$s = new DateTime($ss);
|
||||
$e = (new DateTime(null))->setTimestamp(strtotime($es)); // verbose setup method
|
||||
$d= $e->diff($s);
|
||||
var_dump($d->days); // 30 ... and should be 30
|
||||
|
||||
/*
|
||||
This test just proves that the $e date is important BUT NOT because it's the one we call the diff() method
|
||||
on, that's just coincidental that seems to imply that the "- 1 second" in the date string is the problem.
|
||||
*/
|
||||
$s = new DateTime($ss);
|
||||
$e = (new DateTime(null))->setTimestamp(strtotime($es)); // verbose setup method
|
||||
$d= $s->diff($e);
|
||||
var_dump($d->days); // 30 ... and should be 30
|
||||
|
||||
/*
|
||||
[Workaround]
|
||||
This final test seems to prove that the input string is important and that the "- 1 secord" has a negative knock-on
|
||||
effect on the results of the diff. By modifying the datetime with ->modify everything works as expected ...
|
||||
it just means you have to be careful of how we work with DateTimes .
|
||||
*/
|
||||
$s = new DateTime($ss);
|
||||
$e = new DateTime('first day of this month midnight');
|
||||
$e->modify('- 1 second');
|
||||
var_dump($e->diff($s)->days); // 30 ... and should be 30
|
||||
?>
|
||||
--EXPECT--
|
||||
int(30)
|
||||
int(30)
|
||||
int(30)
|
||||
int(30)
|
||||
int(30)
|
||||
int(30)
|
12
ext/date/tests/bug73942.phpt
Normal file
12
ext/date/tests/bug73942.phpt
Normal file
@ -0,0 +1,12 @@
|
||||
--TEST--
|
||||
Bug #73942: $date->modify('Friday this week') doesn't return a Friday if $date is a Sunday
|
||||
--FILE--
|
||||
<?php
|
||||
$date1 = "2017-01-08"; // this is a Sunday
|
||||
$date = new \DateTime($date1);
|
||||
$date->modify('Friday this week');
|
||||
$dateFormat = $date->format('Y-m-d');
|
||||
echo $dateFormat, "\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
2017-01-06
|
24
ext/date/tests/bug74057.phpt
Normal file
24
ext/date/tests/bug74057.phpt
Normal file
@ -0,0 +1,24 @@
|
||||
--TEST--
|
||||
Bug #74057: wrong day when using "this week" in strtotime
|
||||
--FILE--
|
||||
<?php
|
||||
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Sun 2017-01-01")))."\n";
|
||||
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Mon 2017-01-02")))."\n";
|
||||
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Tue 2017-01-03")))."\n";
|
||||
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Wed 2017-01-04")))."\n";
|
||||
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Thu 2017-01-05")))."\n";
|
||||
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Fri 2017-01-06")))."\n";
|
||||
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Sat 2017-01-07")))."\n";
|
||||
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Sun 2017-01-08")))."\n";
|
||||
echo date("D Y-m-d", strtotime("saturday this week", strtotime("Mon 2017-01-09")))."\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
Sat 2016-12-31
|
||||
Sat 2017-01-07
|
||||
Sat 2017-01-07
|
||||
Sat 2017-01-07
|
||||
Sat 2017-01-07
|
||||
Sat 2017-01-07
|
||||
Sat 2017-01-07
|
||||
Sat 2017-01-07
|
||||
Sat 2017-01-14
|
Loading…
Reference in New Issue
Block a user