aboutsummaryrefslogtreecommitdiffhomepage
path: root/php/ext
diff options
context:
space:
mode:
authorGravatar Bo Yang <teboring@google.com>2017-12-12 13:57:49 -0800
committerGravatar Bo Yang <teboring@google.com>2017-12-12 13:57:49 -0800
commit88102eae8f86045307e9d46ad900f91158227f2b (patch)
tree460f40dde0a53279d9722d6e712410e99e0f5e93 /php/ext
parent9f6aceaa8ce8250d9e36225180c218035bd49fe9 (diff)
Replace private timelib_update_ts with public date_timestamp_get
Diffstat (limited to 'php/ext')
-rw-r--r--php/ext/google/protobuf/message.c24
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, &timestamp);
}
- 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