summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerick Rethans <derick@php.net>2010-12-15 21:45:25 +0000
committerDerick Rethans <derick@php.net>2010-12-15 21:45:25 +0000
commit3a03c53dbd5d3526448ee7708d9cfe534a595ce1 (patch)
tree0bc26281d31c39981123bcd468931b23002034ce
parent69894eaf80962471c0e91b833f06de5181752844 (diff)
downloadphp-git-3a03c53dbd5d3526448ee7708d9cfe534a595ce1.tar.gz
- Fixed a bug in DateTime->modify() where absolute date/time statements had no
effect.
-rw-r--r--ext/date/php_date.c25
-rw-r--r--ext/date/tests/DateTime_modify_variation1.phpt4
-rw-r--r--ext/date/tests/date-time-modify-times.phpt47
-rw-r--r--ext/date/tests/date_modify_variation2.phpt4
4 files changed, 76 insertions, 4 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 8a35f9586b..b30e8431c6 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -2792,6 +2792,31 @@ PHP_FUNCTION(date_modify)
memcpy(&dateobj->time->relative, &tmp_time->relative, sizeof(struct timelib_rel_time));
dateobj->time->have_relative = tmp_time->have_relative;
dateobj->time->sse_uptodate = 0;
+
+ if (tmp_time->y != -99999) {
+ dateobj->time->y = tmp_time->y;
+ }
+ if (tmp_time->m != -99999) {
+ dateobj->time->m = tmp_time->m;
+ }
+ if (tmp_time->d != -99999) {
+ dateobj->time->d = tmp_time->d;
+ }
+
+ if (tmp_time->h != -99999) {
+ dateobj->time->h = tmp_time->h;
+ if (tmp_time->i != -99999) {
+ dateobj->time->i = tmp_time->i;
+ if (tmp_time->s != -99999) {
+ dateobj->time->s = tmp_time->s;
+ } else {
+ dateobj->time->s = 0;
+ }
+ } else {
+ dateobj->time->i = 0;
+ dateobj->time->s = 0;
+ }
+ }
timelib_time_dtor(tmp_time);
timelib_update_ts(dateobj->time, NULL);
diff --git a/ext/date/tests/DateTime_modify_variation1.phpt b/ext/date/tests/DateTime_modify_variation1.phpt
index 4d27071d04..faeb70cbd9 100644
--- a/ext/date/tests/DateTime_modify_variation1.phpt
+++ b/ext/date/tests/DateTime_modify_variation1.phpt
@@ -133,7 +133,7 @@ bool(false)
-- float 10.5 --
object(DateTime)#3 (3) {
["date"]=>
- string(19) "2009-01-31 14:28:41"
+ string(19) "2009-01-31 10:05:00"
["timezone_type"]=>
int(3)
["timezone"]=>
@@ -148,7 +148,7 @@ bool(false)
-- float .5 --
object(DateTime)#3 (3) {
["date"]=>
- string(19) "2009-01-31 14:28:41"
+ string(19) "2009-01-31 00:05:00"
["timezone_type"]=>
int(3)
["timezone"]=>
diff --git a/ext/date/tests/date-time-modify-times.phpt b/ext/date/tests/date-time-modify-times.phpt
new file mode 100644
index 0000000000..258ddbd420
--- /dev/null
+++ b/ext/date/tests/date-time-modify-times.phpt
@@ -0,0 +1,47 @@
+--TEST--
+Test for DateTime::modify() with absolute time statements
+--INI--
+date.timezone=Europe/London
+--FILE--
+<?php
+$tests = array(
+ '2010-12-15 19:42:45 UTC' => array(
+ 'october 23:00', // October 23rd, with a broken time
+ 'back of 4pm',
+ 'next week monday',
+ 'next week monday 10am',
+ 'tuesday noon',
+ 'first monday of January 2011',
+ 'first monday of January 2011 09:00',
+ ),
+ '2010-12-15 19:42:45' => array(
+ 'october 23:00', // October 23rd, with a broken time
+ 'march 28, 00:15',
+ 'march 28, 01:15', // doesn't exist bcause of DST
+ 'march 28, 02:15',
+ ),
+);
+
+foreach ( $tests as $start => $data )
+{
+ foreach ( $data as $test )
+ {
+ echo date_create( $start )
+ ->modify( $test )
+ ->format( DateTime::RFC2822 ), "\n";
+ }
+}
+echo "\n";
+?>
+--EXPECT--
+Sat, 23 Oct 2010 00:00:00 +0000
+Wed, 15 Dec 2010 16:15:00 +0000
+Mon, 20 Dec 2010 00:00:00 +0000
+Mon, 20 Dec 2010 10:00:00 +0000
+Tue, 21 Dec 2010 12:00:00 +0000
+Mon, 03 Jan 2011 00:00:00 +0000
+Mon, 03 Jan 2011 09:00:00 +0000
+Sat, 23 Oct 2010 00:00:00 +0100
+Sun, 28 Mar 2010 00:15:00 +0000
+Sun, 28 Mar 2010 02:15:00 +0100
+Sun, 28 Mar 2010 02:15:00 +0100
diff --git a/ext/date/tests/date_modify_variation2.phpt b/ext/date/tests/date_modify_variation2.phpt
index 08db14cf89..fe6afb16dd 100644
--- a/ext/date/tests/date_modify_variation2.phpt
+++ b/ext/date/tests/date_modify_variation2.phpt
@@ -133,7 +133,7 @@ bool(false)
-- float 10.5 --
object(DateTime)#%d (3) {
["date"]=>
- string(19) "2009-01-31 14:28:41"
+ string(19) "2009-01-31 10:05:00"
["timezone_type"]=>
int(3)
["timezone"]=>
@@ -148,7 +148,7 @@ bool(false)
-- float .5 --
object(DateTime)#%d (3) {
["date"]=>
- string(19) "2009-01-31 14:28:41"
+ string(19) "2009-01-31 00:05:00"
["timezone_type"]=>
int(3)
["timezone"]=>