Skip to content

Fix date_create_from_format when using | char #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/date_override_008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $tests_args = array(
array("Y-m-d H:i:s T", "1970-01-01 19:00:00 EST"),
array("U", "86400"),
array("Y-m-d H:i:s", "2012-04-01 00:00:00", new DateTimezone("Asia/Tokyo")),
array("Y-m-d|", "2012-03-31"),
);

$dt0 = DateTime::createFromFormat("Y-m-d H:i:s.u", "2010-01-02 03:04:05.678000");
Expand Down Expand Up @@ -66,3 +67,4 @@ string\(32\) "1970-01-01 12:34:56\.000000-08:00"
string\(32\) "1970-01-01 19:00:00\.000000-05:00"
string\(32\) "1970-01-02 00:00:00\.000000\+00:00"
string\(32\) "2012-04-01 00:00:00\.000000\+09:00"
string\(32\) "2012-03-31 00:00:00\.000000\-07:00"
6 changes: 6 additions & 0 deletions timecop_php5.c
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,12 @@ static void _timecop_date_create_from_format(INTERNAL_FUNCTION_PARAMETERS, int i
RETURN_FALSE;
}

if (memchr(orig_format_str, '|', orig_format_len)) {
zval_ptr_dtor(&orig_format);
zval_ptr_dtor(&orig_time);
RETURN_ZVAL(dt, 1, 1);
}

get_mock_timeval(&now, NULL TSRMLS_CC);

INIT_ZVAL(now_timestamp);
Expand Down
6 changes: 6 additions & 0 deletions timecop_php7.c
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,12 @@ static void _timecop_date_create_from_format(INTERNAL_FUNCTION_PARAMETERS, int i
RETURN_FALSE;
}

if (memchr(orig_format_str, '|', orig_format_len)) {
zval_ptr_dtor(&orig_format);
zval_ptr_dtor(&orig_time);
RETURN_ZVAL(&dt, 1, 1);
}

get_mock_timeval(&now, NULL);

ZVAL_LONG(&now_timestamp, now.sec);
Expand Down