/* {{{ Cassandra\Timestamp::toDateTime() */
PHP_METHOD(Timestamp, toDateTime)
{
  cassandra_timestamp *self;
  zval *datetime = NULL;
  php_date_obj *datetime_obj = NULL;
  char *str;
  int str_len;

  if (zend_parse_parameters_none() == FAILURE) {
    return;
  }

  self = PHP_CASSANDRA_GET_TIMESTAMP(getThis());

  PHP5TO7_ZVAL_MAYBE_MAKE(datetime);
  php_date_instantiate(php_date_get_date_ce(), datetime TSRMLS_CC);

#if PHP_MAJOR_VERSION >= 7
  datetime_obj = php_date_obj_from_obj(Z_OBJ_P(datetime));
#else
  datetime_obj = zend_object_store_get_object(datetime TSRMLS_CC);
#endif

  str_len      = spprintf(&str, 0, "@%ld", (long) (self->timestamp / 1000));
  php_date_initialize(datetime_obj, str, str_len, NULL, NULL, 0 TSRMLS_CC);
  efree(str);

  RETVAL_ZVAL(datetime, 0, 0);
}
예제 #2
0
/* {{{ MongoDate::toDateTime()
 * Returns a DateTime object with the same information as the MongoDate object */
PHP_METHOD(MongoDate, toDateTime)
{
	mongo_date *date;
	int64_t     sec;
	int64_t     usec;
	double      dusec;
	char       *str;
	int         str_len;
	zval        datetime_object;
	php_date_obj *datetime_obj;
	zval *datetime_object_ptr = &datetime_object;

	date = (mongo_date*) zend_object_store_get_object(getThis() TSRMLS_CC);

	php_date_instantiate(php_date_get_date_ce(), &datetime_object TSRMLS_CC);
	mongo_date_to_parts(date, &sec, &usec, &dusec);

#ifdef WIN32
	str_len = spprintf(&str, 0, "@%I64d", (int64_t) sec);
#else
	str_len = spprintf(&str, 0, "@%lld", (long long int) sec);
#endif

	datetime_obj = zend_object_store_get_object(&datetime_object TSRMLS_CC);
	php_date_initialize(datetime_obj, str, str_len, NULL, NULL, 0 TSRMLS_CC);
	efree(str);
	datetime_obj->time->f = dusec;

	RETVAL_ZVAL(datetime_object_ptr, 0, 0);
}
예제 #3
0
/* {{{ Cassandra\Date::toDateTime() */
PHP_METHOD(Date, toDateTime)
{
    cassandra_date *self;
    zval *ztime = NULL;
    cassandra_time* time_obj = NULL;
    php5to7_zval datetime;
    php_date_obj *datetime_obj = NULL;
    char *str;
    int str_len;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &ztime) == FAILURE) {
        return;
    }

    if (ztime != NULL) {
        time_obj = PHP_CASSANDRA_GET_TIME(ztime);
    }
    self = PHP_CASSANDRA_GET_DATE(getThis());

    PHP5TO7_ZVAL_MAYBE_MAKE(datetime);
    php_date_instantiate(php_date_get_date_ce(), PHP5TO7_ZVAL_MAYBE_P(datetime) TSRMLS_CC);

#if PHP_MAJOR_VERSION >= 7
    datetime_obj = php_date_obj_from_obj(Z_OBJ(datetime));
#else
    datetime_obj = zend_object_store_get_object(datetime TSRMLS_CC);
#endif

    str_len = spprintf(&str, 0, "%lld",
                       cass_date_time_to_epoch(self->date,
                               time_obj != NULL ? time_obj->time : 0));
    php_date_initialize(datetime_obj, str, str_len, "U", NULL, 0 TSRMLS_CC);
    efree(str);

    RETVAL_ZVAL(PHP5TO7_ZVAL_MAYBE_P(datetime), 0, 1);
}
예제 #4
0
/* {{{ Cassandra\Timeuuid::value() */
PHP_METHOD(Timeuuid, toDateTime)
{
  cassandra_uuid* uuid;
  zval* datetime;
  php_date_obj* datetime_obj;
  char* str;
  int str_len;

  if (zend_parse_parameters_none() == FAILURE) {
    return;
  }

  uuid = (cassandra_uuid*) zend_object_store_get_object(getThis() TSRMLS_CC);

  MAKE_STD_ZVAL(datetime);
  php_date_instantiate(php_date_get_date_ce(), datetime TSRMLS_CC);

  datetime_obj = zend_object_store_get_object(datetime TSRMLS_CC);
  str_len      = spprintf(&str, 0, "@%ld", (long) (cass_uuid_timestamp(uuid->uuid) / 1000));
  php_date_initialize(datetime_obj, str, str_len, NULL, NULL, 0 TSRMLS_CC);
  efree(str);

  RETVAL_ZVAL(datetime, 0, 0);
}