mirror of
https://github.com/php/php-src.git
synced 2026-03-24 16:22:37 +01:00
Fixed bug #35624 (strtotime() does not handle 3 character weekdays).
Improved fix for bug #35414.
This commit is contained in:
1
NEWS
1
NEWS
@@ -26,6 +26,7 @@ PHP NEWS
|
||||
- Fixed many bugs in OCI8. (Tony)
|
||||
- Fixed crash and leak in mysqli when using 4.1.x client libraries and
|
||||
connecting to 5.x server. (Andrey)
|
||||
- Fixed bug #35624 (strtotime() does not handle 3 character weekdays). (Ilia)
|
||||
- Fixed bug #35612 (iis6 Access Violation crash). (Dmitry, alacn.uhahaa)
|
||||
- Fixed bug #35594 (Multiple calls to getopt() may result in a crash).
|
||||
(rabbitt at gmail dot com, Ilia)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -196,12 +196,19 @@ static timelib_relunit const timelib_relunit_lookup[] = {
|
||||
{ "years", TIMELIB_YEAR, 1 },
|
||||
|
||||
{ "monday", TIMELIB_WEEKDAY, 1 },
|
||||
{ "mon", TIMELIB_WEEKDAY, 1 },
|
||||
{ "tuesday", TIMELIB_WEEKDAY, 2 },
|
||||
{ "tue", TIMELIB_WEEKDAY, 2 },
|
||||
{ "wednesday", TIMELIB_WEEKDAY, 3 },
|
||||
{ "wed", TIMELIB_WEEKDAY, 3 },
|
||||
{ "thursday", TIMELIB_WEEKDAY, 4 },
|
||||
{ "thu", TIMELIB_WEEKDAY, 4 },
|
||||
{ "friday", TIMELIB_WEEKDAY, 5 },
|
||||
{ "fri", TIMELIB_WEEKDAY, 5 },
|
||||
{ "saturday", TIMELIB_WEEKDAY, 6 },
|
||||
{ "sat", TIMELIB_WEEKDAY, 6 },
|
||||
{ "sunday", TIMELIB_WEEKDAY, 0 },
|
||||
{ "sun", TIMELIB_WEEKDAY, 0 },
|
||||
|
||||
{ NULL, 0, 0 }
|
||||
};
|
||||
@@ -370,6 +377,16 @@ static timelib_sll timelib_get_nr(char **ptr, int max_length)
|
||||
return tmp_nr;
|
||||
}
|
||||
|
||||
static void timelib_skip_day_suffix(char **ptr)
|
||||
{
|
||||
if (isspace(**ptr)) {
|
||||
return;
|
||||
}
|
||||
if (!strncasecmp(*ptr, "nd", 2) || !strncasecmp(*ptr, "rd", 2) ||!strncasecmp(*ptr, "st", 2) || !strncasecmp(*ptr, "th", 2)) {
|
||||
*ptr += 2;
|
||||
}
|
||||
}
|
||||
|
||||
static double timelib_get_frac_nr(char **ptr, int max_length)
|
||||
{
|
||||
char *begin, *end, *str;
|
||||
@@ -719,8 +736,10 @@ meridian = [AaPp] "."? [Mm] "."?;
|
||||
tz = "("? [A-Za-z]{1,4} ")"? | [A-Z][a-z]+([_/][A-Z][a-z]+)+;
|
||||
tzcorrection = [+-] hour24 ":"? minutelz?;
|
||||
|
||||
daysuf = 'st' | 'nd' | 'rd' | 'th';
|
||||
|
||||
month = "0"? [0-9] | "1"[0-2];
|
||||
day = ([0-2]?[0-9] | "3"[01])([a-z][a-z])?;
|
||||
day = ([0-2]?[0-9] | "3"[01]) daysuf?;
|
||||
year = [0-9]{1,4};
|
||||
year2 = [0-9]{2};
|
||||
year4 = [0-9]{4};
|
||||
@@ -769,7 +788,7 @@ pointeddate = day "." month "." year;
|
||||
datefull = day ([ -.])* monthtext ([ -.])* year;
|
||||
datenoday = monthtext ([ -.])* year4;
|
||||
datenodayrev = year4 ([ -.])* monthtext;
|
||||
datetextual = monthtext ([ -.])* day [,.stndrh ]* year;
|
||||
datetextual = monthtext ([ -.])* day [,.stndrh ]* year;
|
||||
datenoyear = monthtext ([ -.])* day [,.stndrh ]*;
|
||||
datenoyearrev = day ([ -.])* monthtext;
|
||||
datenocolon = year4 monthlz daylz;
|
||||
@@ -800,7 +819,7 @@ dateshortwithtimelongtz = datenoyear iso8601normtz;
|
||||
* Relative regexps
|
||||
*/
|
||||
reltextnumber = 'first'|'next'|'second'|'third'|'fourth'|'fifth'|'sixth'|'seventh'|'eight'|'ninth'|'tenth'|'eleventh'|'twelfth'|'last'|'previous'|'this';
|
||||
reltextunit = (('sec'|'second'|'min'|'minute'|'hour'|'day'|'week'|'fortnight'|'forthnight'|'month'|'year') 's'?) | dayfull;
|
||||
reltextunit = (('sec'|'second'|'min'|'minute'|'hour'|'day'|'week'|'fortnight'|'forthnight'|'month'|'year') 's'?) | daytext;
|
||||
|
||||
relnumber = ([+-]?[ ]*[0-9]+);
|
||||
relative = (relnumber space? reltextunit)+;
|
||||
@@ -1039,6 +1058,7 @@ relativetext = (reltextnumber space? reltextunit)+;
|
||||
TIMELIB_INIT;
|
||||
TIMELIB_HAVE_DATE();
|
||||
s->time->d = timelib_get_nr((char **) &ptr, 2);
|
||||
timelib_skip_day_suffix((char **) &ptr);
|
||||
s->time->m = timelib_get_month((char **) &ptr);
|
||||
s->time->y = timelib_get_nr((char **) &ptr, 4);
|
||||
TIMELIB_PROCESS_YEAR(s->time->y);
|
||||
@@ -1104,6 +1124,7 @@ relativetext = (reltextnumber space? reltextunit)+;
|
||||
TIMELIB_INIT;
|
||||
TIMELIB_HAVE_DATE();
|
||||
s->time->d = timelib_get_nr((char **) &ptr, 2);
|
||||
timelib_skip_day_suffix((char **) &ptr);
|
||||
s->time->m = timelib_get_month((char **) &ptr);
|
||||
TIMELIB_DEINIT;
|
||||
return TIMELIB_DATE_TEXT;
|
||||
@@ -1263,6 +1284,22 @@ relativetext = (reltextnumber space? reltextunit)+;
|
||||
return TIMELIB_AGO;
|
||||
}
|
||||
|
||||
daytext
|
||||
{
|
||||
const timelib_relunit* relunit;
|
||||
DEBUG_OUTPUT("daytext");
|
||||
TIMELIB_INIT;
|
||||
TIMELIB_HAVE_RELATIVE();
|
||||
TIMELIB_HAVE_WEEKDAY_RELATIVE();
|
||||
TIMELIB_UNHAVE_TIME();
|
||||
relunit = timelib_lookup_relunit((char**) &ptr);
|
||||
s->time->relative.weekday = relunit->multiplier;
|
||||
s->time->relative.weekday_behavior = 1;
|
||||
|
||||
TIMELIB_DEINIT;
|
||||
return TIMELIB_WEEKDAY;
|
||||
}
|
||||
|
||||
relativetext
|
||||
{
|
||||
timelib_sll i;
|
||||
@@ -1280,29 +1317,6 @@ relativetext = (reltextnumber space? reltextunit)+;
|
||||
return TIMELIB_RELATIVE;
|
||||
}
|
||||
|
||||
dayfull
|
||||
{
|
||||
const timelib_relunit* relunit;
|
||||
DEBUG_OUTPUT("dayfull");
|
||||
TIMELIB_INIT;
|
||||
TIMELIB_HAVE_RELATIVE();
|
||||
TIMELIB_HAVE_WEEKDAY_RELATIVE();
|
||||
TIMELIB_UNHAVE_TIME();
|
||||
|
||||
relunit = timelib_lookup_relunit((char**) &ptr);
|
||||
s->time->relative.weekday = relunit->multiplier;
|
||||
s->time->relative.weekday_behavior = 1;
|
||||
|
||||
TIMELIB_DEINIT;
|
||||
return TIMELIB_RELATIVE;
|
||||
}
|
||||
|
||||
dayabbr
|
||||
{
|
||||
DEBUG_OUTPUT("dayabbr");
|
||||
goto std;
|
||||
}
|
||||
|
||||
tzcorrection | tz
|
||||
{
|
||||
int tz_not_found;
|
||||
|
||||
@@ -5,10 +5,12 @@ Bug #35414 (strtotime() no longer works with ordinal suffix)
|
||||
date_default_timezone_set("UTC");
|
||||
|
||||
echo date(DATE_ISO8601, strtotime("Sat 26th Nov 2005 18:18")) . "\n";
|
||||
echo date(DATE_ISO8601, strtotime("26th Nov", 1134340285)) . "\n";
|
||||
echo date(DATE_ISO8601, strtotime("Dec. 4th, 2005")) . "\n";
|
||||
echo date(DATE_ISO8601, strtotime("December 4th, 2005")) . "\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
2004-12-26T18:18:00+0000
|
||||
2005-11-26T18:18:00+0000
|
||||
2005-11-26T00:00:00+0000
|
||||
2005-12-04T00:00:00+0000
|
||||
2005-12-04T00:00:00+0000
|
||||
|
||||
29
ext/date/tests/bug35624.phpt
Normal file
29
ext/date/tests/bug35624.phpt
Normal file
@@ -0,0 +1,29 @@
|
||||
--TEST--
|
||||
Bug #35624 (strtotime() does not handle 3 character weekdays)
|
||||
--FILE--
|
||||
<?php
|
||||
date_default_timezone_set("UTC");
|
||||
|
||||
$days = array("monday","mon","tuesday","tue","wednesday","wed","thursday","thu","friday","fri","saturday","sat","sunday","sun");
|
||||
|
||||
foreach ($days as $day) {
|
||||
echo date("D", strtotime($day));
|
||||
echo date("D", strtotime(ucfirst($day)));
|
||||
echo "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
MonMon
|
||||
MonMon
|
||||
TueTue
|
||||
TueTue
|
||||
WedWed
|
||||
WedWed
|
||||
ThuThu
|
||||
ThuThu
|
||||
FriFri
|
||||
FriFri
|
||||
SatSat
|
||||
SatSat
|
||||
SunSun
|
||||
SunSun
|
||||
Reference in New Issue
Block a user