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 | http://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 /* {{{ dateformat_register_constants
25 * Register constants common for the both (OO and procedural)
26 * APIs.
27 */
dateformat_register_constants(INIT_FUNC_ARGS)28 void dateformat_register_constants( INIT_FUNC_ARGS )
29 {
30 if( IntlDateFormatter_ce_ptr == NULL) {
31 zend_error(E_ERROR, "DateFormat class not defined");
32 return;
33 }
34
35 #define DATEFORMATTER_EXPOSE_CONST(x) REGISTER_LONG_CONSTANT(#x, x, CONST_PERSISTENT | CONST_CS)
36 #define DATEFORMATTER_EXPOSE_CLASS_CONST(x) zend_declare_class_constant_long( IntlDateFormatter_ce_ptr, ZEND_STRS( #x ) - 1, UDAT_##x );
37 #define DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST(name, value) zend_declare_class_constant_long( IntlDateFormatter_ce_ptr, ZEND_STRS( name ) - 1, value );
38
39 #define DATEFORMATTER_EXPOSE_UCAL_CLASS_CONST(x) zend_declare_class_constant_long( IntlDateFormatter_ce_ptr, ZEND_STRS( #x ) - 1, UCAL_##x );
40
41 /* UDateFormatStyle constants */
42 DATEFORMATTER_EXPOSE_CLASS_CONST( FULL );
43 DATEFORMATTER_EXPOSE_CLASS_CONST( LONG );
44 DATEFORMATTER_EXPOSE_CLASS_CONST( MEDIUM );
45 DATEFORMATTER_EXPOSE_CLASS_CONST( SHORT );
46 DATEFORMATTER_EXPOSE_CLASS_CONST( NONE );
47 DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "RELATIVE_FULL", UDAT_FULL_RELATIVE );
48 DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "RELATIVE_LONG", UDAT_LONG_RELATIVE );
49 DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "RELATIVE_MEDIUM", UDAT_MEDIUM_RELATIVE );
50 DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "RELATIVE_SHORT", UDAT_SHORT_RELATIVE );
51
52 /*
53 DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "GREGORIAN", DATEF_GREGORIAN );
54 DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "CUSTOMARY", DATEF_CUSTOMARY );
55 DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "BUDDHIST", DATEF_BUDDHIST );
56 DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "JAPANESE_IMPERIAL", DATEF_JAPANESE_IMPERIAL );
57 */
58
59 DATEFORMATTER_EXPOSE_UCAL_CLASS_CONST( GREGORIAN );
60 DATEFORMATTER_EXPOSE_UCAL_CLASS_CONST( TRADITIONAL );
61
62 #undef DATEFORMATTER_EXPOSE_UCAL_CLASS_CONST
63 #undef DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST
64 #undef DATEFORMATTER_EXPOSE_CLASS_CONST
65 #undef DATEFORMATTER_EXPOSE_CONST
66 }
67 /* }}} */
68
69 /* {{{ Get formatter's last error code. */
PHP_FUNCTION(datefmt_get_error_code)70 PHP_FUNCTION( datefmt_get_error_code )
71 {
72 DATE_FORMAT_METHOD_INIT_VARS;
73
74 /* Parse parameters. */
75 if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",
76 &object, IntlDateFormatter_ce_ptr ) == FAILURE )
77 {
78 RETURN_THROWS();
79 }
80
81 dfo = Z_INTL_DATEFORMATTER_P( object );
82
83 /* Return formatter's last error code. */
84 RETURN_LONG( INTL_DATA_ERROR_CODE(dfo) );
85 }
86 /* }}} */
87
88 /* {{{ Get text description for formatter's last error code. */
PHP_FUNCTION(datefmt_get_error_message)89 PHP_FUNCTION( datefmt_get_error_message )
90 {
91 zend_string *message = NULL;
92 DATE_FORMAT_METHOD_INIT_VARS;
93
94 /* Parse parameters. */
95 if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "O",
96 &object, IntlDateFormatter_ce_ptr ) == FAILURE )
97 {
98 RETURN_THROWS();
99 }
100
101 dfo = Z_INTL_DATEFORMATTER_P( object );
102
103 /* Return last error message. */
104 message = intl_error_get_message( INTL_DATA_ERROR_P(dfo) );
105 RETURN_STR( message);
106 }
107 /* }}} */
108