com php-src: Conflicts: ext/date/php_date.c: NEWS UPGRADING ext/date/php_date.c ext/date/php_date.h ext/date/tests/DatePeriod_getter.phpt
| From: | Stanislav Malyshev | Date: | Mon, 01 Dec 2014 04:49:18 +0000 |
| Subject: | com php-src: Conflicts: ext/date/php_date.c: NEWS UPGRADING ext/date/php_date.c ext/date/php_date.h ext/date/tests/DatePeriod_getter.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-83415@lists.php.net to get a copy of this message | ||
Commit: 4675b79e65e7eea3f3e6343236e1c5ed335d88bf
Author: m.bennewitz <marc.bennewitz@unister.de> Mon, 20 Oct 2014 08:27:56 +0000
Committer: Stanislav Malyshev <stas@php.net> Sun, 30 Nov 2014 20:49:18 -0800
Parents: de65eaa8c8faf6ae256aef3a2a074255b249a6f0
Branches: PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=4675b79e65e7eea3f3e6343236e1c5ed335d88bf
Log:
Conflicts:
ext/date/php_date.c
Changed paths:
M NEWS
M UPGRADING
M ext/date/php_date.c
M ext/date/php_date.h
A ext/date/tests/DatePeriod_getter.phpt
Diff:
diff --git a/NEWS b/NEWS
index fddedb5..492153b 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 7c5f8c0..bba4553 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 804b50d..489a50d 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 2b3ae4d..e25b4d6 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 0000000..22006d1
--- /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"