void php_mongo_date_init(zval *value, int64_t datetime TSRMLS_DC)
{
	long        sec, usec;

	usec = (long) ((((datetime * 1000) % 1000000) + 1000000) % 1000000);
	sec  = (long) ((datetime/1000) - (datetime < 0 && usec));

	php_mongo_mongodate_populate(value, sec, usec TSRMLS_CC);
}
Exemple #2
0
/* {{{ MongoDate::__construct
 */
PHP_METHOD(MongoDate, __construct)
{
	long sec = 0, usec = 0;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &sec, &usec) == FAILURE) {
		return;
	}

	if (ZEND_NUM_ARGS() == 0) {
		php_mongo_mongodate_make_now(&sec, &usec);
	}

	php_mongo_mongodate_populate(getThis(), sec, usec TSRMLS_CC);
}
/* {{{ MongoDate::__set_state()
 */
PHP_METHOD(MongoDate, __set_state)
{
	zval *state, **sec, **usec;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &state) == FAILURE) {
		return;
	}

	if (zend_hash_find(HASH_P(state), "sec", strlen("sec") + 1, (void**) &sec) == FAILURE) {
		return;
	}

	if (zend_hash_find(HASH_P(state), "usec", strlen("usec") + 1, (void**) &usec) == FAILURE) {
		return;
	}

	convert_to_long(*sec);
	convert_to_long(*usec);
	object_init_ex(return_value, mongo_ce_Date);
	php_mongo_mongodate_populate(return_value, Z_LVAL_PP(sec), Z_LVAL_PP(usec) TSRMLS_CC);
}