Skip to content

Commit

Permalink
fix: simplify hook_strtotime
Browse files Browse the repository at this point in the history
  • Loading branch information
t-matsuno-777 committed Sep 19, 2024
1 parent 0b9098a commit 9c0ab0f
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions ext/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,25 +699,12 @@ static void hook_strtotime(INTERNAL_FUNCTION_PARAMETERS)
return;
}

if (is_fixed_ret == 2) {
CALL_ORIGINAL_FUNCTION(strtotime);
} else {
/* Call original function with params. */
zval *params = NULL;
uint32_t param_count = 0;
zend_parse_parameters(ZEND_NUM_ARGS(), "+", &params, &param_count);
ZVAL_LONG(&params[1], get_shifted_time(NULL));
CALL_ORIGINAL_FUNCTION_WITH_PARAMS(strtotime, params, param_count);
}

/* Apply interval. */
timelib_time *t = timelib_time_ctor();
timelib_rel_time interval;
timelib_unixtime2gmt(t, Z_LVAL_P(return_value));
get_shift_interval(&interval);
apply_interval(&t, &interval);
RETVAL_LONG(timelib_date_to_int(t, NULL));
timelib_time_dtor(t);
/* Call original function based on shifted time */
zval *params = NULL;
uint32_t param_count = 0;
zend_parse_parameters(ZEND_NUM_ARGS(), "+", &params, &param_count);
ZVAL_LONG(&params[1], get_shifted_time(NULL));
CALL_ORIGINAL_FUNCTION_WITH_PARAMS(strtotime, params, param_count);
}

#if HAVE_GETTIMEOFDAY
Expand Down

0 comments on commit 9c0ab0f

Please sign in to comment.