php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #63863
Patch test_and_fix_bug63863 revision 2013-03-01 19:27 UTC by jellofishi at gmail dot com

Patch test_and_fix_bug63863 for Date/time related Bug #63863

Patch version 2013-03-01 19:27 UTC

Return to Bug #63863 | Download this patch
Patch Revisions:

Developer: jellofishi@gmail.com

diff --git a/ext/date/lib/tm2unixtime.c b/ext/date/lib/tm2unixtime.c
index e15a381..ef28e93 100644
--- a/ext/date/lib/tm2unixtime.c
+++ b/ext/date/lib/tm2unixtime.c
@@ -205,15 +205,15 @@ static void do_adjust_relative(timelib_time* time)
 		time->d += time->relative.d;
 		time->m += time->relative.m;
 		time->y += time->relative.y;
-	}
-	switch (time->relative.first_last_day_of) {
-		case 1: /* first */
-			time->d = 1;
-			break;
-		case 2: /* last */
-			time->d = 0;
-			time->m++;
-			break;
+		switch (time->relative.first_last_day_of) {
+			case 1: /* first */
+				time->d = 1;
+				break;
+			case 2: /* last */
+				time->d = 0;
+				time->m++;
+				break;
+		}
 	}
 	timelib_do_normalize(time);
 }
diff --git a/ext/date/tests/bug63863.phpt b/ext/date/tests/bug63863.phpt
new file mode 100644
index 0000000..6f506fd
--- /dev/null
+++ b/ext/date/tests/bug63863.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Bug #63863 	DateTime:setDate() date not used after modify("last day of...")
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+$date = new DateTime('2012-03-30');
+
+$date->modify("last day of last month");
+var_dump($date->format('Y-m-d')); // correctly last day of Feb
+
+$date->setDate(2012, 1, 30);
+var_dump($date->format('Y-m-d')); // incorrect date
+
+$date->modify('2012-01-30');
+var_dump($date->format('Y-m-d')); // does set correct date
+--EXPECT--
+string(10) "2012-02-29"
+string(10) "2012-01-30"
+string(10) "2012-01-30"
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 03:01:27 2024 UTC