Skip to content

Move php_phongo_new_datetime_from_utcdatetime() into UTCDateTime.c #339

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
Jun 27, 2016
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
19 changes: 0 additions & 19 deletions php_phongo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2068,25 +2068,6 @@ void php_phongo_new_utcdatetime_from_epoch(zval *object, int64_t msec_since_epoc
intern->milliseconds = msec_since_epoch;
} /* }}} */

void php_phongo_new_datetime_from_utcdatetime(zval *object, int64_t milliseconds TSRMLS_DC) /* {{{ */
{
php_date_obj *datetime_obj;
char *sec;
int sec_len;

object_init_ex(object, php_date_get_date_ce());

#ifdef WIN32
sec_len = spprintf(&sec, 0, "@%I64d", (int64_t) milliseconds / 1000);
#else
sec_len = spprintf(&sec, 0, "@%lld", (long long int) milliseconds / 1000);
#endif

datetime_obj = Z_PHPDATE_P(object);
php_date_initialize(datetime_obj, sec, sec_len, NULL, NULL, 0 TSRMLS_CC);
efree(sec);
datetime_obj->time->f = (double) (milliseconds % 1000) / 1000;
} /* }}} */
void php_phongo_new_timestamp_from_increment_and_timestamp(zval *object, uint32_t increment, uint32_t timestamp TSRMLS_DC) /* {{{ */
{
php_phongo_timestamp_t *intern;
Expand Down
1 change: 0 additions & 1 deletion php_phongo.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ bool phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
void php_phongo_objectid_new_from_oid(zval *object, const bson_oid_t *oid TSRMLS_DC);
void php_phongo_cursor_id_new_from_id(zval *object, int64_t cursorid TSRMLS_DC);
void php_phongo_new_utcdatetime_from_epoch(zval *object, int64_t msec_since_epoch TSRMLS_DC);
void php_phongo_new_datetime_from_utcdatetime(zval *object, int64_t milliseconds TSRMLS_DC);
void php_phongo_new_timestamp_from_increment_and_timestamp(zval *object, uint32_t increment, uint32_t timestamp TSRMLS_DC);
void php_phongo_new_javascript_from_javascript(int init, zval *object, const char *code, size_t code_len TSRMLS_DC);
void php_phongo_new_javascript_from_javascript_and_scope(int init, zval *object, const char *code, size_t code_len, const bson_t *scope TSRMLS_DC);
Expand Down
15 changes: 13 additions & 2 deletions src/BSON/UTCDateTime.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <ext/standard/info.h>
#include <Zend/zend_interfaces.h>
#include <ext/spl/spl_iterators.h>
#include <ext/date/php_date.h>
/* Our Compatability header */
#include "phongo_compat.h"

Expand Down Expand Up @@ -112,7 +113,10 @@ PHP_METHOD(UTCDateTime, __toString)
Returns DateTime object representing this UTCDateTime */
PHP_METHOD(UTCDateTime, toDateTime)
{
php_phongo_utcdatetime_t *intern;
php_phongo_utcdatetime_t *intern;
php_date_obj *datetime_obj;
char *sec;
size_t sec_len;


intern = Z_UTCDATETIME_OBJ_P(getThis());
Expand All @@ -121,7 +125,14 @@ PHP_METHOD(UTCDateTime, toDateTime)
return;
}

php_phongo_new_datetime_from_utcdatetime(return_value, intern->milliseconds TSRMLS_CC);
object_init_ex(return_value, php_date_get_date_ce());
datetime_obj = Z_PHPDATE_P(return_value);

sec_len = spprintf(&sec, 0, "@%" PRId64, intern->milliseconds / 1000);
php_date_initialize(datetime_obj, sec, sec_len, NULL, NULL, 0 TSRMLS_CC);
efree(sec);

datetime_obj->time->f = (double) (intern->milliseconds % 1000) / 1000;
}
/* }}} */

Expand Down