php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #52015
Patch php_bug52015.diff revision 2010-06-07 14:03 UTC by degeberg@php.net

Patch php_bug52015.diff for Date/time related Bug #52015

Patch version 2010-06-07 14:03 UTC

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

Developer: degeberg@php.net

Index: tests/date_period_include_end.phpt
===================================================================
--- tests/date_period_include_end.phpt	(revision 0)
+++ tests/date_period_include_end.phpt	(revision 0)
@@ -0,0 +1,19 @@
+--TEST--
+DatePeriod::INCLUDE_END_DATE
+--FILE--
+<?php
+date_default_timezone_set('UTC');
+$start = new DateTime('2010-06-07');
+$end = new DateTime('2010-06-10');
+$interval = new DateInterval('P1D');
+
+foreach (new DatePeriod($start, $interval, $end, DatePeriod::INCLUDE_END_DATE) as $day) {
+    echo $day->format('Y-m-d') . "\n";
+}
+?>
+--EXPECT--
+2010-06-07
+2010-06-08
+2010-06-09
+2010-06-10
+
Index: php_date.c
===================================================================
--- php_date.c	(revision 300254)
+++ php_date.c	(working copy)
@@ -1778,6 +1778,7 @@
 #define PHP_DATE_TIMEZONE_PER_COUNTRY      0x1000
 
 #define PHP_DATE_PERIOD_EXCLUDE_START_DATE 0x0001
+#define PHP_DATE_PERIOD_INCLUDE_END_DATE   0x0002
 
 
 /* define an overloaded iterator structure */
@@ -1833,7 +1834,12 @@
 	}
 
 	if (object->end) {
-		return object->start->sse < object->end->sse ? SUCCESS : FAILURE;
+		if (object->include_end_date) {
+			return object->start->sse <= object->end->sse ? SUCCESS : FAILURE;
+		}
+		else {
+			return object->start->sse < object->end->sse ? SUCCESS : FAILURE;
+		}
 	} else {
 		return (iterator->current_index < object->recurrences) ? SUCCESS : FAILURE;
 	}
@@ -2005,6 +2011,7 @@
 	zend_declare_class_constant_long(date_ce_period, const_name, sizeof(const_name)-1, value TSRMLS_CC);
 
 	REGISTER_PERIOD_CLASS_CONST_STRING("EXCLUDE_START_DATE", PHP_DATE_PERIOD_EXCLUDE_START_DATE);
+	REGISTER_PERIOD_CLASS_CONST_STRING("INCLUDE_END_DATE", PHP_DATE_PERIOD_INCLUDE_END_DATE);
 }
 
 static inline zend_object_value date_object_new_date_ex(zend_class_entry *class_type, php_date_obj **ptr TSRMLS_DC)
@@ -3763,9 +3770,10 @@
 
 	/* options */
 	dpobj->include_start_date = !(options & PHP_DATE_PERIOD_EXCLUDE_START_DATE);
+	dpobj->include_end_date = options & PHP_DATE_PERIOD_INCLUDE_END_DATE;
 
 	/* recurrrences */
-	dpobj->recurrences = recurrences + dpobj->include_start_date;
+	dpobj->recurrences = recurrences + dpobj->include_start_date + dpobj->include_end_date;
 
 	dpobj->initialized = 1;
 
Index: php_date.h
===================================================================
--- php_date.h	(revision 300254)
+++ php_date.h	(working copy)
@@ -144,6 +144,7 @@
 	int               recurrences;
 	int               initialized;
 	int               include_start_date;
+	int               include_end_date;
 };
 
 ZEND_BEGIN_MODULE_GLOBALS(date)
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Jun 27 03:01:25 2019 UTC