]> granicus.if.org Git - php/commitdiff
Fixed bug #69336 (Issues with "last day of <monthname>").
authorDerick Rethans <github@derickrethans.nl>
Tue, 31 Mar 2015 15:35:03 +0000 (16:35 +0100)
committerDerick Rethans <github@derickrethans.nl>
Tue, 31 Mar 2015 15:35:03 +0000 (16:35 +0100)
NEWS
ext/date/lib/parse_date.c
ext/date/lib/parse_date.re
ext/date/lib/timelib.h
ext/date/lib/tm2unixtime.c
ext/date/php_date.c
ext/date/tests/bug69336.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 5cc74f8431f580d902f33bc946426f199e2b5f23..36f60ff03f8521713867601210a043325e433adf 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,7 @@ PHP                                                                        NEWS
 - Date:
   . Export date_get_immutable_ce so that it can be used by extensions. (Derick
     Rethans)
+  . Fixed bug #69336 (Issues with "last day of <monthname>"). (Derick Rethans)
 
 - Curl:
   . Implemented FR#69278 (HTTP2 support). (Masaki Kagaya)
index afa1425565e07f7cec70c449188fbbc437497181..2a10139b433c57ca3829c1f94404518b96597730 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.13.5 on Mon Aug 18 18:28:27 2014 */
+/* Generated by re2c 0.13.5 on Tue Mar 31 16:32:03 2015 */
 #line 1 "ext/date/lib/parse_date.re"
 /*
    +----------------------------------------------------------------------+
@@ -19864,9 +19864,9 @@ yy1315:
 
                /* skip "last day of" or "first day of" */
                if (*ptr == 'l' || *ptr == 'L') {
-                       s->time->relative.first_last_day_of = 2;
+                       s->time->relative.first_last_day_of = TIMELIB_SPECIAL_LAST_DAY_OF_MONTH;
                } else {
-                       s->time->relative.first_last_day_of = 1;
+                       s->time->relative.first_last_day_of = TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH;
                }
 
                TIMELIB_DEINIT;
index 4cdbc2a37c1bb475371a075f22964371d3aee40d..66d4f223889a653f5119e69e8e23d0821f42efd4 100644 (file)
@@ -1030,9 +1030,9 @@ weekdayof        = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
 
                /* skip "last day of" or "first day of" */
                if (*ptr == 'l' || *ptr == 'L') {
-                       s->time->relative.first_last_day_of = 2;
+                       s->time->relative.first_last_day_of = TIMELIB_SPECIAL_LAST_DAY_OF_MONTH;
                } else {
-                       s->time->relative.first_last_day_of = 1;
+                       s->time->relative.first_last_day_of = TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH;
                }
 
                TIMELIB_DEINIT;
index 797ed10b19688535d449449f83be6d63d4d210f7..28f3b8c924cc9503956b360bba847c63f4f91e0e 100644 (file)
@@ -38,6 +38,9 @@
 #define TIMELIB_SPECIAL_DAY_OF_WEEK_IN_MONTH      0x02
 #define TIMELIB_SPECIAL_LAST_DAY_OF_WEEK_IN_MONTH 0x03
 
+#define TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH        0x01
+#define TIMELIB_SPECIAL_LAST_DAY_OF_MONTH         0x02
+
 #ifndef LONG_MAX
 #define LONG_MAX 2147483647L
 #endif
index a3d48c59c42d37c9e985a6d6d58c323bf8a54e92..0f59d31516b02b09b6467ee6a8ef6ed60c313bb9 100644 (file)
@@ -205,15 +205,17 @@ static void do_adjust_relative(timelib_time* time)
                time->m += time->relative.m;
                time->y += time->relative.y;
        }
+
        switch (time->relative.first_last_day_of) {
-               case 1: /* first */
+               case TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH: /* first */
                        time->d = 1;
                        break;
-               case 2: /* last */
+               case TIMELIB_SPECIAL_LAST_DAY_OF_MONTH: /* last */
                        time->d = 0;
                        time->m++;
                        break;
        }
+
        timelib_do_normalize(time);
 }
 
@@ -296,6 +298,15 @@ static void do_adjust_special_early(timelib_time* time)
                                break;
                }
        }
+       switch (time->relative.first_last_day_of) {
+               case TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH: /* first */
+                       time->d = 1;
+                       break;
+               case TIMELIB_SPECIAL_LAST_DAY_OF_MONTH: /* last */
+                       time->d = 0;
+                       time->m++;
+                       break;
+       }
        timelib_do_normalize(time);
 }
 
index 0819b45df4ee4708da4bf1d4b978c29d68769225..7f05bab99e46e823acc0ae6291393f42dae5efc8 100644 (file)
@@ -2989,7 +2989,7 @@ void php_date_do_return_parsed_time(INTERNAL_FUNCTION_PARAMETERS, timelib_time *
                        add_assoc_long(element, "weekdays", parsed_time->relative.special.amount);
                }
                if (parsed_time->relative.first_last_day_of) {
-                       add_assoc_bool(element, parsed_time->relative.first_last_day_of == 1 ? "first_day_of_month" : "last_day_of_month", 1);
+                       add_assoc_bool(element, parsed_time->relative.first_last_day_of == TIMELIB_SPECIAL_FIRST_DAY_OF_MONTH ? "first_day_of_month" : "last_day_of_month", 1);
                }
                add_assoc_zval(return_value, "relative", element);
        }
diff --git a/ext/date/tests/bug69336.phpt b/ext/date/tests/bug69336.phpt
new file mode 100644 (file)
index 0000000..8444aa3
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Bug #69336 (Issues with "last day of <monthname>")
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+var_dump(date('d.m.Y',strtotime('last day of april')));
+var_dump(date('d.m.Y',strtotime('last tuesday of march 2015')));
+var_dump(date('d.m.Y',strtotime('last wednesday of march 2015')));
+var_dump(date('d.m.Y',strtotime('last wednesday of april 2015')));
+var_dump(date('d.m.Y',strtotime('last wednesday of march 2014')));
+var_dump(date('d.m.Y',strtotime('last wednesday of april 2014')));
+?>
+--EXPECTF--
+string(10) "30.04.%d"
+string(10) "31.03.2015"
+string(10) "25.03.2015"
+string(10) "29.04.2015"
+string(10) "26.03.2014"
+string(10) "30.04.2014"