xref: /php-src/ext/intl/dateformat/dateformat.c (revision c1da9e79)
1 /*
2    +----------------------------------------------------------------------+
3    | This source file is subject to version 3.01 of the PHP license,      |
4    | that is bundled with this package in the file LICENSE, and is        |
5    | available through the world-wide-web at the following url:           |
6    | https://www.php.net/license/3_01.txt                                 |
7    | If you did not receive a copy of the PHP license and are unable to   |
8    | obtain it through the world-wide-web, please send a note to          |
9    | license@php.net so we can mail you a copy immediately.               |
10    +----------------------------------------------------------------------+
11    | Authors: Kirti Velankar <kirtig@yahoo-inc.com>                       |
12    +----------------------------------------------------------------------+
13 */
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17 
18 #include <unicode/udat.h>
19 
20 #include "php_intl.h"
21 #include "dateformat_class.h"
22 #include "dateformat.h"
23 
24 /* {{{ Get formatter's last error code. */
PHP_FUNCTION(datefmt_get_error_code)25 PHP_FUNCTION( datefmt_get_error_code )
26 {
27 	DATE_FORMAT_METHOD_INIT_VARS;
28 
29 	/* Parse parameters. */
30 	if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",
31 		&object, IntlDateFormatter_ce_ptr ) == FAILURE )
32 	{
33 		RETURN_THROWS();
34 	}
35 
36 	dfo = Z_INTL_DATEFORMATTER_P( object );
37 
38 	/* Return formatter's last error code. */
39 	RETURN_LONG( INTL_DATA_ERROR_CODE(dfo) );
40 }
41 /* }}} */
42 
43 /* {{{ Get text description for formatter's last error code. */
PHP_FUNCTION(datefmt_get_error_message)44 PHP_FUNCTION( datefmt_get_error_message )
45 {
46 	zend_string *message = NULL;
47 	DATE_FORMAT_METHOD_INIT_VARS;
48 
49 	/* Parse parameters. */
50 	if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",
51 		&object, IntlDateFormatter_ce_ptr ) == FAILURE )
52 	{
53 		RETURN_THROWS();
54 	}
55 
56 	dfo = Z_INTL_DATEFORMATTER_P( object );
57 
58 	/* Return last error message. */
59 	message = intl_error_get_message( INTL_DATA_ERROR_P(dfo) );
60 	RETURN_STR( message);
61 }
62 /* }}} */
63