diff options
Diffstat (limited to 'php/ext')
-rw-r--r-- | php/ext/google/protobuf/message.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 70080a3b..5b654a78 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -1133,12 +1133,24 @@ PHP_METHOD(Timestamp, fromDateTime) { return; } - php_date_obj* dateobj = UNBOX(php_date_obj, datetime); - if (!dateobj->time->sse_uptodate) { - timelib_update_ts(dateobj->time, NULL); + // Get timestamp from Datetime object. + zval* retval_ptr; + zval* function_name; + int64_t timestamp; + + MAKE_STD_ZVAL(retval_ptr); + MAKE_STD_ZVAL(function_name); + + ZVAL_STRING(function_name, "date_timestamp_get", 1); + + if (call_user_function(EG(function_table), NULL, + function_name, retval_ptr, 1, + &datetime TSRMLS_CC) == SUCCESS) { + protobuf_convert_to_int64(retval_ptr, ×tamp); } - int64_t timestamp = dateobj->time->sse; + zval_ptr_dtor(&retval_ptr); + zval_ptr_dtor(&function_name); // Set seconds MessageHeader* self = UNBOX(MessageHeader, getThis()); @@ -1146,13 +1158,15 @@ PHP_METHOD(Timestamp, fromDateTime) { upb_msgdef_ntofz(self->descriptor->msgdef, "seconds"); void* storage = message_data(self); void* memory = slot_memory(self->descriptor->layout, storage, field); - *(int64_t*)memory = dateobj->time->sse; + *(int64_t*)memory = timestamp; // Set nanos field = upb_msgdef_ntofz(self->descriptor->msgdef, "nanos"); storage = message_data(self); memory = slot_memory(self->descriptor->layout, storage, field); *(int32_t*)memory = 0; + + RETURN_NULL(); #else zend_error(E_USER_ERROR, "fromDateTime needs date extension."); #endif |