Skip to content

Commit

Permalink
Allow for trailing 's' in day names such as 'sundays'
Browse files Browse the repository at this point in the history
Fixes PHP Bug #51934: strtotime plurals / incorrect time
  • Loading branch information
derickr committed May 13, 2022
1 parent 7fef442 commit cb26187
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions parse_date.re
Expand Up @@ -211,18 +211,25 @@ static timelib_relunit const timelib_relunit_lookup[] = {
{ "year", TIMELIB_YEAR, 1 },
{ "years", TIMELIB_YEAR, 1 },

{ "mondays", TIMELIB_WEEKDAY, 1 },
{ "monday", TIMELIB_WEEKDAY, 1 },
{ "mon", TIMELIB_WEEKDAY, 1 },
{ "tuesdays", TIMELIB_WEEKDAY, 2 },
{ "tuesday", TIMELIB_WEEKDAY, 2 },
{ "tue", TIMELIB_WEEKDAY, 2 },
{ "wednesdays", TIMELIB_WEEKDAY, 3 },
{ "wednesday", TIMELIB_WEEKDAY, 3 },
{ "wed", TIMELIB_WEEKDAY, 3 },
{ "thursdays", TIMELIB_WEEKDAY, 4 },
{ "thursday", TIMELIB_WEEKDAY, 4 },
{ "thu", TIMELIB_WEEKDAY, 4 },
{ "fridays", TIMELIB_WEEKDAY, 5 },
{ "friday", TIMELIB_WEEKDAY, 5 },
{ "fri", TIMELIB_WEEKDAY, 5 },
{ "saturdays", TIMELIB_WEEKDAY, 6 },
{ "saturday", TIMELIB_WEEKDAY, 6 },
{ "sat", TIMELIB_WEEKDAY, 6 },
{ "sundays", TIMELIB_WEEKDAY, 0 },
{ "sunday", TIMELIB_WEEKDAY, 0 },
{ "sun", TIMELIB_WEEKDAY, 0 },

Expand Down Expand Up @@ -963,10 +970,11 @@ weekofyear = "0"[1-9] | [1-4][0-9] | "5"[0-3];
monthlz = "0" [0-9] | "1" [0-2];
daylz = "0" [0-9] | [1-2][0-9] | "3" [01];
dayfulls = 'sundays' | 'mondays' | 'tuesdays' | 'wednesdays' | 'thursdays' | 'fridays' | 'saturdays';
dayfull = 'sunday' | 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday';
dayabbr = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun';
dayspecial = 'weekday' | 'weekdays';
daytext = dayfull | dayabbr | dayspecial;
daytext = dayfulls | dayfull | dayabbr | dayspecial;
monthfull = 'january' | 'february' | 'march' | 'april' | 'may' | 'june' | 'july' | 'august' | 'september' | 'october' | 'november' | 'december';
monthabbr = 'jan' | 'feb' | 'mar' | 'apr' | 'may' | 'jun' | 'jul' | 'aug' | 'sep' | 'sept' | 'oct' | 'nov' | 'dec';
Expand Down Expand Up @@ -1055,7 +1063,7 @@ relative = relnumber space? (reltextunit | 'week' );
relativetext = (reltextnumber|reltexttext) space reltextunit;
relativetextweek = reltexttext space 'week';

weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of';
weekdayof = (reltextnumber|reltexttext) space (dayfulls|dayfull|dayabbr) space 'of';

*/

Expand Down
4 changes: 4 additions & 0 deletions tests/c/create_ts_from_string.cpp
Expand Up @@ -206,6 +206,10 @@ TEST_CREATE_TS_FROM_STRINGS(bug41709_04, -62167305600, "00.01.0000", "00:00:00 G
TEST_CREATE_TS_FROM_STRINGS(bug41709_05, -62169984000, "00.00.0000", "00:00:00 GMT", "")


/* for bug51934 */
TEST_CREATE_TS_FROM_STRINGS(bug51934_00, 1272853080, "4 sundays ago", "2010-05-27 19:18", "America/Los_Angeles")


/* from bug63470.ts */
TEST_CREATE_TS_FROM_STRINGS(bug63470_00, 1435536000, "this week", "2015-07-04 00:00", "UTC")
TEST_CREATE_TS_FROM_STRINGS(bug63470_01, 1435536000, "this week", "2015-07-05 00:00", "UTC") // Sunday
Expand Down

0 comments on commit cb26187

Please sign in to comment.