summaryrefslogtreecommitdiff
path: root/ext/date/php_date.c
diff options
context:
space:
mode:
authorm.bennewitz <marc.bennewitz@unister.de>2014-10-20 08:27:56 +0000
committerm.bennewitz <marc.bennewitz@unister.de>2014-10-20 08:27:56 +0000
commit846a72a73aa2b275861f95416ce46c0f1cb603af (patch)
tree5cee90dc4989985ce131d7479b0a5b9c11aeeee4 /ext/date/php_date.c
parent4b892439e61634b4bdcbf0bd54ef8577575875fd (diff)
downloadphp-git-846a72a73aa2b275861f95416ce46c0f1cb603af.tar.gz
#68268: DatePeriod: Getter for start date, end date and interval
Diffstat (limited to 'ext/date/php_date.c')
-rw-r--r--ext/date/php_date.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index f2ced7bd59..22b1163875 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
};
@@ -4414,6 +4417,81 @@ PHP_METHOD(DatePeriod, __construct)
}
/* }}} */
+/* {{{ 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 = Z_PHPPERIOD_P(getThis());
+
+ php_date_instantiate(dpobj->start_ce, return_value TSRMLS_CC);
+ dateobj = Z_PHPDATE_P(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 = Z_PHPPERIOD_P(getThis());
+
+ php_date_instantiate(dpobj->start_ce, return_value TSRMLS_CC);
+ dateobj = Z_PHPDATE_P(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 = Z_PHPPERIOD_P(getThis());
+
+ php_date_instantiate(date_ce_interval, return_value TSRMLS_CC);
+ diobj = Z_PHPINTERVAL_P(return_value);
+ diobj->diff = timelib_rel_time_clone(dpobj->interval);
+ diobj->initialized = 1;
+}
+/* }}} */
+
static int check_id_allowed(char *id, zend_long what) /* {{{ */
{
if (what & PHP_DATE_TIMEZONE_GROUP_AFRICA && strncasecmp(id, "Africa/", 7) == 0) return 1;