summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS4
-rw-r--r--UPGRADING3
-rw-r--r--ext/date/php_date.c80
-rw-r--r--ext/date/php_date.h3
-rw-r--r--ext/date/tests/DatePeriod_getter.phpt25
5 files changed, 114 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index fddedb5ab3..492153bfc8 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,10 @@ PHP NEWS
. Fixed bug #60704 (unlink() bug with some files path).
. Fixed bug #65419 (Inside trait, self::class != __CLASS__). (Julien)
+- Date:
+ . Implemented FR #68268 (DatePeriod: Getter for start date, end date and
+ interval). (Marc Bennewitz)
+
- mbstring:
. Fixed bug #68504 (--with-libmbfl configure option not present on Windows).
(Ashesh Vashi)
diff --git a/UPGRADING b/UPGRADING
index 7c5f8c060f..bba4553caa 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -266,6 +266,9 @@ PHP 5.6 UPGRADE NOTES
6. New Functions
========================================
+- Datetime:
+ Added DatePeriod::getStartDate(), DatePeriod::getEndDate(), DatePeriod::getDateInterval() in 5.6.5.
+
- GMP:
Added gmp_root($a, $nth) and gmp_rootrem($a, $nth) for calculating nth roots.
Added gmp_import($data, $word_size = 1, $options = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN) in PHP 5.6.1.
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 804b50d8ce..489a50dd3f 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -533,6 +533,9 @@ const zend_function_entry date_funcs_period[] = {
PHP_ME(DatePeriod, __construct, arginfo_date_period_construct, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
PHP_ME(DatePeriod, __wakeup, NULL, ZEND_ACC_PUBLIC)
PHP_ME(DatePeriod, __set_state, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(DatePeriod, getStartDate, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(DatePeriod, getEndDate, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(DatePeriod, getDateInterval, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
@@ -4475,7 +4478,82 @@ PHP_METHOD(DatePeriod, __construct)
}
/* }}} */
-static int check_id_allowed(char *id, long what)
+/* {{{ proto DatePeriod::getStartDate()
+ Get start date.
+*/
+PHP_METHOD(DatePeriod, getStartDate)
+{
+ php_period_obj *dpobj;
+ php_date_obj *dateobj;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ dpobj = (php_period_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ php_date_instantiate(dpobj->start_ce, return_value TSRMLS_CC);
+ dateobj = (php_date_obj *)zend_object_store_get_object(return_value);
+ dateobj->time = timelib_time_ctor();
+ *dateobj->time = *dpobj->start;
+ if (dpobj->start->tz_abbr) {
+ dateobj->time->tz_abbr = strdup(dpobj->start->tz_abbr);
+ }
+ if (dpobj->start->tz_info) {
+ dateobj->time->tz_info = dpobj->start->tz_info;
+ }
+}
+/* }}} */
+
+/* {{{ proto DatePeriod::getEndDate()
+ Get end date.
+*/
+PHP_METHOD(DatePeriod, getEndDate)
+{
+ php_period_obj *dpobj;
+ php_date_obj *dateobj;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ dpobj = (php_period_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ php_date_instantiate(dpobj->start_ce, return_value TSRMLS_CC);
+ dateobj = (php_date_obj *)zend_object_store_get_object(return_value);
+ dateobj->time = timelib_time_ctor();
+ *dateobj->time = *dpobj->end;
+ if (dpobj->end->tz_abbr) {
+ dateobj->time->tz_abbr = strdup(dpobj->end->tz_abbr);
+ }
+ if (dpobj->end->tz_info) {
+ dateobj->time->tz_info = dpobj->end->tz_info;
+ }
+}
+/* }}} */
+
+/* {{{ proto DatePeriod::getDateInterval()
+ Get date interval.
+*/
+PHP_METHOD(DatePeriod, getDateInterval)
+{
+ php_period_obj *dpobj;
+ php_interval_obj *diobj;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ dpobj = (php_period_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ php_date_instantiate(date_ce_interval, return_value TSRMLS_CC);
+ diobj = (php_interval_obj *)zend_object_store_get_object(return_value TSRMLS_CC);
+ diobj->diff = timelib_rel_time_clone(dpobj->interval);
+ diobj->initialized = 1;
+}
+/* }}} */
+
+static int check_id_allowed(char *id, long what) /* {{{ */
{
if (what & PHP_DATE_TIMEZONE_GROUP_AFRICA && strncasecmp(id, "Africa/", 7) == 0) return 1;
if (what & PHP_DATE_TIMEZONE_GROUP_AMERICA && strncasecmp(id, "America/", 8) == 0) return 1;
diff --git a/ext/date/php_date.h b/ext/date/php_date.h
index 2b3ae4dcc1..e25b4d63c2 100644
--- a/ext/date/php_date.h
+++ b/ext/date/php_date.h
@@ -106,6 +106,9 @@ PHP_FUNCTION(date_interval_create_from_date_string);
PHP_METHOD(DatePeriod, __construct);
PHP_METHOD(DatePeriod, __wakeup);
PHP_METHOD(DatePeriod, __set_state);
+PHP_METHOD(DatePeriod, getStartDate);
+PHP_METHOD(DatePeriod, getEndDate);
+PHP_METHOD(DatePeriod, getDateInterval);
/* Options and Configuration */
PHP_FUNCTION(date_default_timezone_set);
diff --git a/ext/date/tests/DatePeriod_getter.phpt b/ext/date/tests/DatePeriod_getter.phpt
new file mode 100644
index 0000000000..22006d1ae8
--- /dev/null
+++ b/ext/date/tests/DatePeriod_getter.phpt
@@ -0,0 +1,25 @@
+--TEST--
+DatePeriod: Test getter
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+$start = new DateTime('2000-01-01 00:00:00', new DateTimeZone('Europe/Berlin'));
+$end = new DateTime('2000-01-31 00:00:00', new DateTimeZone('UTC'));
+$interval = new DateInterval('P1D');
+$period = new DatePeriod($start, $interval, $end);
+
+var_dump($period->getStartDate()->format('Y-m-d H:i:s'));
+var_dump($period->getStartDate()->getTimeZone()->getName());
+
+var_dump($period->getEndDate()->format('Y-m-d H:i:s'));
+var_dump($period->getEndDate()->getTimeZone()->getName());
+
+var_dump($period->getDateInterval()->format('%R%y-%m-%d-%h-%i-%s'));
+?>
+--EXPECTF--
+string(19) "2000-01-01 00:00:00"
+string(13) "Europe/Berlin"
+string(19) "2000-01-31 00:00:00"
+string(3) "UTC"
+string(12) "+0-0-1-0-0-0"