mirror of
https://github.com/php/php-src.git
synced 2025-01-22 11:44:09 +08:00
- MFH: Added DateInterval::createFromDateString() that creates an interval
from the relative parts of a date/time string. - MFH: Fixed an issue where special relative bits were not applied.
This commit is contained in:
parent
97b37f253c
commit
149848846d
@ -193,9 +193,6 @@ static void do_adjust_relative(timelib_time* time)
|
||||
break;
|
||||
}
|
||||
do_normalize(time);
|
||||
|
||||
memset(&(time->relative), 0, sizeof(time->relative));
|
||||
time->have_relative = 0;
|
||||
}
|
||||
|
||||
static void do_adjust_special_weekday(timelib_time* time)
|
||||
|
@ -196,6 +196,7 @@ const zend_function_entry date_functions[] = {
|
||||
PHP_FE(timezone_identifiers_list, NULL)
|
||||
PHP_FE(timezone_abbreviations_list, NULL)
|
||||
|
||||
PHP_FE(date_interval_create_from_date_string, NULL)
|
||||
PHP_FE(date_interval_format, NULL)
|
||||
|
||||
/* Options and Configuration */
|
||||
@ -244,6 +245,7 @@ const zend_function_entry date_funcs_timezone[] = {
|
||||
const zend_function_entry date_funcs_interval[] = {
|
||||
PHP_ME(DateInterval, __construct, NULL, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
|
||||
PHP_ME_MAPPING(format, date_interval_format, NULL, 0)
|
||||
PHP_ME_MAPPING(createFromDateString, date_interval_create_from_date_string, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
@ -1629,6 +1631,7 @@ static void date_period_it_current_data(zend_object_iterator *iter, zval ***data
|
||||
|
||||
/* apply modification if it's not the first iteration */
|
||||
if (!object->include_start_date || iterator->current_index > 0) {
|
||||
it_time->have_relative = 1;
|
||||
it_time->relative.y = object->interval->y;
|
||||
it_time->relative.m = object->interval->m;
|
||||
it_time->relative.d = object->interval->d;
|
||||
@ -1636,7 +1639,9 @@ static void date_period_it_current_data(zend_object_iterator *iter, zval ***data
|
||||
it_time->relative.i = object->interval->i;
|
||||
it_time->relative.s = object->interval->s;
|
||||
it_time->relative.weekday = object->interval->weekday;
|
||||
it_time->have_relative = 1;
|
||||
it_time->relative.special = object->interval->special;
|
||||
it_time->relative.have_weekday_relative = object->interval->have_weekday_relative;
|
||||
it_time->relative.have_special_relative = object->interval->have_special_relative;
|
||||
it_time->sse_uptodate = 0;
|
||||
timelib_update_ts(it_time, NULL);
|
||||
timelib_update_from_sse(it_time);
|
||||
@ -2246,8 +2251,8 @@ PHP_FUNCTION(date_create)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto DateTime date_create(string format, string time[, DateTimeZone object])
|
||||
Returns new DateTime object
|
||||
/* {{{ proto DateTime date_create_from_format(string format, string time[, DateTimeZone object])
|
||||
Returns new DateTime object formatted according to the specified format
|
||||
*/
|
||||
PHP_FUNCTION(date_create_from_format)
|
||||
{
|
||||
@ -3254,7 +3259,7 @@ PHP_METHOD(DateInterval, __construct)
|
||||
timelib_rel_time *reltime;
|
||||
|
||||
php_set_error_handling(EH_THROW, NULL TSRMLS_CC);
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &interval_string, &interval_string_length) == SUCCESS) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &interval_string, &interval_string_length) == SUCCESS) {
|
||||
if (date_interval_initialize(&reltime, interval_string, interval_string_length TSRMLS_CC) == SUCCESS) {
|
||||
diobj = zend_object_store_get_object(getThis() TSRMLS_CC);
|
||||
diobj->diff = reltime;
|
||||
@ -3267,6 +3272,31 @@ PHP_METHOD(DateInterval, __construct)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto DateInterval date_interval_create_from_date_string(string time)
|
||||
Uses the normal date parsers and sets up a DateInterval from the relative parts of the parsed string
|
||||
*/
|
||||
PHP_FUNCTION(date_interval_create_from_date_string)
|
||||
{
|
||||
char *time_str = NULL;
|
||||
int time_str_len = 0;
|
||||
timelib_time *time;
|
||||
timelib_error_container *err = NULL;
|
||||
php_interval_obj *diobj;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &time_str, &time_str_len) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
date_instantiate(date_ce_interval, return_value TSRMLS_CC);
|
||||
|
||||
time = timelib_strtotime(time_str, time_str_len, &err, DATE_TIMEZONEDB);
|
||||
diobj = (php_interval_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
|
||||
diobj->diff = timelib_rel_time_clone(&time->relative);
|
||||
timelib_time_dtor(time);
|
||||
timelib_error_container_dtor(err);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ date_interval_format - */
|
||||
static char *date_interval_format(char *format, int format_len, timelib_rel_time *t)
|
||||
{
|
||||
|
@ -81,6 +81,7 @@ PHP_FUNCTION(timezone_abbreviations_list);
|
||||
|
||||
PHP_METHOD(DateInterval, __construct);
|
||||
PHP_FUNCTION(date_interval_format);
|
||||
PHP_FUNCTION(date_interval_create_from_date_string);
|
||||
|
||||
PHP_METHOD(DatePeriod, __construct);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user