Back to index

php5  5.3.10
Functions
dateformat_format.h File Reference
#include <php.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 PHP_FUNCTION (datefmt_format)

Function Documentation

Definition at line 125 of file dateformat_format.c.

{
       UDate         timestamp =0;
       UDate         p_timestamp =0;
       HashTable*      hash_arr        = NULL;
       zval*         zarg   = NULL;

       DATE_FORMAT_METHOD_INIT_VARS;

       /* Parse parameters. */
       if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oz", &object, IntlDateFormatter_ce_ptr,&zarg ) == FAILURE )
       {
              intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format: unable to parse input params", 0 TSRMLS_CC );
              RETURN_FALSE;
       }

       /* Fetch the object. */
       DATE_FORMAT_METHOD_FETCH_OBJECT;

       switch(Z_TYPE_P(zarg) ){
              case IS_LONG:
                     p_timestamp = Z_LVAL_P(zarg) ;
                     timestamp = p_timestamp * 1000;
                     break;
              case IS_DOUBLE:
                     /* timestamp*1000 since ICU expects it in milliseconds */
                     p_timestamp = Z_DVAL_P(zarg) ;
                     timestamp = p_timestamp * 1000;
                     break;
              case IS_ARRAY:
                     hash_arr = Z_ARRVAL_P(zarg);
                     if( !hash_arr || zend_hash_num_elements( hash_arr ) == 0 )
                            RETURN_FALSE;

                     timestamp = internal_get_timestamp(dfo, hash_arr TSRMLS_CC);
                     INTL_METHOD_CHECK_STATUS( dfo, "datefmt_format: Date formatting failed" )
                     break;
              case IS_OBJECT: {
                     zend_class_entry *date_ce = php_date_get_date_ce();
                     zval retval;
                     zval *zfuncname;
                     if(!instanceof_function(Z_OBJCE_P(zarg), date_ce TSRMLS_CC)) {
                            intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format: object must be an instance of DateTime", 0 TSRMLS_CC );
                            RETURN_FALSE;
                     }
                     INIT_ZVAL(retval);
                     MAKE_STD_ZVAL(zfuncname);
                     ZVAL_STRING(zfuncname, "getTimestamp", 1);
                     if(call_user_function(NULL, &zarg, zfuncname, &retval, 0, NULL TSRMLS_CC) != SUCCESS || Z_TYPE(retval) != IS_LONG) {
                            intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format: cannot get timestamp", 0 TSRMLS_CC );
                            zval_ptr_dtor(&zfuncname);
                            RETURN_FALSE;
                     }
                     zval_ptr_dtor(&zfuncname);
                     p_timestamp = Z_LVAL(retval);
                     timestamp = p_timestamp*1000;
              }
                     break;
              default:
                     intl_errors_set( INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR,
                            "datefmt_format: takes either an array or an integer timestamp value or a DateTime object", 0 TSRMLS_CC );
                     RETURN_FALSE;
       }

       internal_format( dfo, timestamp, return_value TSRMLS_CC);
       
}

Here is the call graph for this function: