Merge branch 'microseconds-modify' into PHP-7.1

This commit is contained in:
Derick Rethans 2016-10-07 13:49:00 -04:00
commit 61bf62a7c0
5 changed files with 15172 additions and 14184 deletions

2
NEWS
View File

@ -10,6 +10,8 @@ PHP NEWS
. Fixed bug #52519 (microseconds in DateInterval are missing). (Derick)
. Fixed bug #60089 (DateTime::createFromFormat() U after u nukes microtime).
(Derick)
. Fixed bug #64887 (Allow DateTime modification with subsecond items).
(Derick)
. Fixed bug #68506 (General DateTime improvments needed for microseconds to
become useful). (Derick)
. Fixed bug #73109 (timelib_meridian doesn't parse dots correctly). (Derick)

File diff suppressed because it is too large Load Diff

View File

@ -52,14 +52,15 @@
#define TIMELIB_UNSET -99999
#define TIMELIB_SECOND 1
#define TIMELIB_MINUTE 2
#define TIMELIB_HOUR 3
#define TIMELIB_DAY 4
#define TIMELIB_MONTH 5
#define TIMELIB_YEAR 6
#define TIMELIB_WEEKDAY 7
#define TIMELIB_SPECIAL 8
#define TIMELIB_SECOND 1
#define TIMELIB_MINUTE 2
#define TIMELIB_HOUR 3
#define TIMELIB_DAY 4
#define TIMELIB_MONTH 5
#define TIMELIB_YEAR 6
#define TIMELIB_WEEKDAY 7
#define TIMELIB_SPECIAL 8
#define TIMELIB_MICROSEC 9
#define EOI 257
#define TIME 258
@ -190,6 +191,18 @@ const static timelib_tz_lookup_table timelib_timezone_utc[] = {
};
static timelib_relunit const timelib_relunit_lookup[] = {
{ "ms", TIMELIB_MICROSEC, 1000 },
{ "msec", TIMELIB_MICROSEC, 1000 },
{ "msecs", TIMELIB_MICROSEC, 1000 },
{ "millisecond", TIMELIB_MICROSEC, 1000 },
{ "milliseconds", TIMELIB_MICROSEC, 1000 },
{ "µs", TIMELIB_MICROSEC, 1 },
{ "usec", TIMELIB_MICROSEC, 1 },
{ "usecs", TIMELIB_MICROSEC, 1 },
{ "µsec", TIMELIB_MICROSEC, 1 },
{ "µsecs", TIMELIB_MICROSEC, 1 },
{ "microsecond", TIMELIB_MICROSEC, 1 },
{ "microseconds", TIMELIB_MICROSEC, 1 },
{ "sec", TIMELIB_SECOND, 1 },
{ "secs", TIMELIB_SECOND, 1 },
{ "second", TIMELIB_SECOND, 1 },
@ -655,12 +668,13 @@ static void timelib_set_relative(char **ptr, timelib_sll amount, int behavior, S
}
switch (relunit->unit) {
case TIMELIB_SECOND: s->time->relative.s += amount * relunit->multiplier; break;
case TIMELIB_MINUTE: s->time->relative.i += amount * relunit->multiplier; break;
case TIMELIB_HOUR: s->time->relative.h += amount * relunit->multiplier; break;
case TIMELIB_DAY: s->time->relative.d += amount * relunit->multiplier; break;
case TIMELIB_MONTH: s->time->relative.m += amount * relunit->multiplier; break;
case TIMELIB_YEAR: s->time->relative.y += amount * relunit->multiplier; break;
case TIMELIB_MICROSEC: s->time->relative.f += (((double) amount * (double) relunit->multiplier) / 1000000); break;
case TIMELIB_SECOND: s->time->relative.s += amount * relunit->multiplier; break;
case TIMELIB_MINUTE: s->time->relative.i += amount * relunit->multiplier; break;
case TIMELIB_HOUR: s->time->relative.h += amount * relunit->multiplier; break;
case TIMELIB_DAY: s->time->relative.d += amount * relunit->multiplier; break;
case TIMELIB_MONTH: s->time->relative.m += amount * relunit->multiplier; break;
case TIMELIB_YEAR: s->time->relative.y += amount * relunit->multiplier; break;
case TIMELIB_WEEKDAY:
TIMELIB_HAVE_WEEKDAY_RELATIVE();
@ -939,7 +953,7 @@ dateshortwithtimelongtz = datenoyear iso8601normtz;
*/
reltextnumber = 'first'|'second'|'third'|'fourth'|'fifth'|'sixth'|'seventh'|'eight'|'eighth'|'ninth'|'tenth'|'eleventh'|'twelfth';
reltexttext = 'next'|'last'|'previous'|'this';
reltextunit = (('sec'|'second'|'min'|'minute'|'hour'|'day'|'fortnight'|'forthnight'|'month'|'year') 's'?) | 'weeks' | daytext;
reltextunit = 'ms' | 'µs' | (('msec'|'millisecond'|'µsec'|'microsecond'|'usec'|'sec'|'second'|'min'|'minute'|'hour'|'day'|'fortnight'|'forthnight'|'month'|'year') 's'?) | 'weeks' | daytext;
relnumber = ([+-]*[ \t]*[0-9]+);
relative = relnumber space? (reltextunit | 'week' );

View File

@ -38,8 +38,8 @@
# define timelib_free free
#endif
#define TIMELIB_VERSION 201604
#define TIMELIB_ASCII_VERSION "2016.04"
#define TIMELIB_VERSION 201605
#define TIMELIB_ASCII_VERSION "2016.05"
#define TIMELIB_NONE 0x00
#define TIMELIB_OVERRIDE_TIME 0x01

View File

@ -0,0 +1,46 @@
--TEST--
Bug #64887: Allow DateTime modification with subsecond items
--INI--
date.timezone=UTC
--FILE--
<?php
$tests = [
'+1 ms',
'-2 msec',
'+3 msecs',
'-4 millisecond',
'+5 milliseconds',
'-6 usec',
'+7 usecs',
'-8 microsecond',
'+9 microseconds',
'-10 µs',
'+11 µsec',
'-12 µsecs',
'+8 msec -2 µsec',
];
$datetime = new DateTimeImmutable( "2016-10-07 13:25:50" );
foreach ( $tests as $test )
{
echo $datetime->modify( $test )->format( 'Y-m-d H:i:s.u' ), "\n";
}
?>
--EXPECT--
2016-10-07 13:25:50.001000
2016-10-07 13:25:49.998000
2016-10-07 13:25:50.003000
2016-10-07 13:25:49.996000
2016-10-07 13:25:50.005000
2016-10-07 13:25:49.999994
2016-10-07 13:25:50.000007
2016-10-07 13:25:49.999992
2016-10-07 13:25:50.000009
2016-10-07 13:25:49.999990
2016-10-07 13:25:50.000011
2016-10-07 13:25:49.999988
2016-10-07 13:25:50.007998