]> granicus.if.org Git - php/commitdiff
- Fixed bug #43452 (strings containing a weekday, or a number plus weekday
authorDerick Rethans <derick@php.net>
Wed, 23 Jul 2008 18:49:37 +0000 (18:49 +0000)
committerDerick Rethans <derick@php.net>
Wed, 23 Jul 2008 18:49:37 +0000 (18:49 +0000)
  behaved incorrect of the current day-of-week was the same as the one in the
  phrase). (Derick)

ext/date/lib/parse_date.c
ext/date/lib/parse_date.re
ext/date/tests/bug43452.phpt [new file with mode: 0644]

index daa256a10fa5c66aaf9620365cd68741c5ec2f8a..7fc5542220895c2672bd1c70286a34b838218a25 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.13.5 on Wed Jul 16 17:39:20 2008 */
+/* Generated by re2c 0.13.5 on Wed Jul 23 20:47:26 2008 */
 #line 1 "ext/date/lib/parse_date.re"
 /*
    +----------------------------------------------------------------------+
@@ -2749,7 +2749,7 @@ yy70:
                while(*ptr) {
                        i = timelib_get_unsigned_nr((char **) &ptr, 24);
                        timelib_eat_spaces((char **) &ptr);
-                       timelib_set_relative((char **) &ptr, i, 0, s);
+                       timelib_set_relative((char **) &ptr, i, 1, s);
                }
                TIMELIB_DEINIT;
                return TIMELIB_RELATIVE;
index 2a66d51461cddbe1887e5e9df948025e487e1f85..d8ca59146ad406854dd13934ed19a4fc5d853ca0 100644 (file)
@@ -1680,7 +1680,7 @@ weekdayof        = (reltextnumber|reltexttext) space (dayfull|dayabbr) ' of';
                while(*ptr) {
                        i = timelib_get_unsigned_nr((char **) &ptr, 24);
                        timelib_eat_spaces((char **) &ptr);
-                       timelib_set_relative((char **) &ptr, i, 0, s);
+                       timelib_set_relative((char **) &ptr, i, 1, s);
                }
                TIMELIB_DEINIT;
                return TIMELIB_RELATIVE;
diff --git a/ext/date/tests/bug43452.phpt b/ext/date/tests/bug43452.phpt
new file mode 100644 (file)
index 0000000..8d312c4
--- /dev/null
@@ -0,0 +1,71 @@
+--TEST--
+Bug #43452 ("weekday" is not equivalent to "1 weekday" of the current weekday is "weekday")
+--INI--
+date.default_timezone=Europe/Oslo
+--FILE--
+<?php
+// <day> is equivalent to 1 <day> and will *not* forward if the current day
+// (November 1st) is the same day of week.
+$day = strtotime( "Thursday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n";
+$day = strtotime( "1 Thursday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n";
+$day = strtotime( "2 Thursday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n";
+$day = strtotime( "3 Thursday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n\n";
+
+// forward one week, then behaves like above for week days
+$day = strtotime( "Thursday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n";
+$day = strtotime( "+1 week Thursday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n";
+$day = strtotime( "+2 week Thursday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n";
+$day = strtotime( "+3 week Thursday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n\n";
+
+// First, second, etc skip to the first/second weekday *after* the current day.
+// This makes "first thursday" equivalent to "+1 week thursday" - but only
+// if the current day-of-week is the one mentioned in the phrase.
+$day = strtotime( "Thursday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n";
+$day = strtotime( "first Thursday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n";
+$day = strtotime( "second Thursday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n";
+$day = strtotime( "third Thursday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n\n";
+
+// Now the same where the current day-of-week does not match the one in the
+// phrase.
+$day = strtotime( "Friday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n";
+$day = strtotime( "first Friday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n";
+$day = strtotime( "second Friday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n";
+$day = strtotime( "third Friday Nov 2007" );
+echo date( DateTime::ISO8601, $day ), "\n\n";
+
+?>
+--EXPECT--
+2007-11-01T00:00:00+0100
+2007-11-01T00:00:00+0100
+2007-11-08T00:00:00+0100
+2007-11-15T00:00:00+0100
+
+2007-11-01T00:00:00+0100
+2007-11-08T00:00:00+0100
+2007-11-15T00:00:00+0100
+2007-11-22T00:00:00+0100
+
+2007-11-01T00:00:00+0100
+2007-11-08T00:00:00+0100
+2007-11-15T00:00:00+0100
+2007-11-22T00:00:00+0100
+
+2007-11-02T00:00:00+0100
+2007-11-02T00:00:00+0100
+2007-11-09T00:00:00+0100
+2007-11-16T00:00:00+0100