php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
dateformat_attr.c
Go to the documentation of this file.
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 "../php_intl.h"
19#include "dateformat_class.h"
20#include "../intl_convert.h"
21#include "dateformat_class.h"
22
23#include <unicode/ustring.h>
24#include <unicode/udat.h>
25
26/* {{{ Get formatter datetype. */
28{
30
31 /* Parse parameters. */
33 {
35 }
36
37 /* Fetch the object. */
39
40 INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter datetype." );
41
42 RETURN_LONG(dfo->date_type );
43}
44/* }}} */
45
46/* {{{ Get formatter timetype. */
48{
50
51 /* Parse parameters. */
53 {
55 }
56
57 /* Fetch the object. */
59
60 INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter timetype." );
61
62 RETURN_LONG(dfo->time_type );
63}
64/* }}} */
65
66/* {{{ Get formatter pattern. */
68{
69 UChar value_buf[64];
70 uint32_t length = USIZE( value_buf );
71 UChar* value = value_buf;
72 bool is_pattern_localized = false;
73
75
76 /* Parse parameters. */
78 {
80 }
81
82 /* Fetch the object. */
84
85 length = udat_toPattern(DATE_FORMAT_OBJECT(dfo), is_pattern_localized, value, length, &INTL_DATA_ERROR_CODE(dfo));
86 if(INTL_DATA_ERROR_CODE(dfo) == U_BUFFER_OVERFLOW_ERROR && length >= USIZE( value_buf )) {
87 ++length; /* to avoid U_STRING_NOT_TERMINATED_WARNING */
89 value = eumalloc(length);
90 length = udat_toPattern(DATE_FORMAT_OBJECT(dfo), is_pattern_localized, value, length, &INTL_DATA_ERROR_CODE(dfo) );
91 if(U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) {
92 efree(value);
93 value = value_buf;
94 }
95 }
96 INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter pattern" );
97
98 INTL_METHOD_RETVAL_UTF8( dfo, value, length, ( value != value_buf ) );
99}
100/* }}} */
101
102/* {{{ Set formatter pattern. */
104{
105 char* value = NULL;
106 size_t value_len = 0;
107 int32_t slength = 0;
108 UChar* svalue = NULL;
109 bool is_pattern_localized = false;
110
111
113
114 /* Parse parameters. */
116 &object, IntlDateFormatter_ce_ptr, &value, &value_len ) == FAILURE )
117 {
119 }
120
122
123 /* Convert given pattern to UTF-16. */
124 intl_convert_utf8_to_utf16(&svalue, &slength, value, value_len, &INTL_DATA_ERROR_CODE(dfo));
125 INTL_METHOD_CHECK_STATUS(dfo, "Error converting pattern to UTF-16" );
126
127 udat_applyPattern(DATE_FORMAT_OBJECT(dfo), (UBool)is_pattern_localized, svalue, slength);
128
129 if (svalue) {
130 efree(svalue);
131 }
132 INTL_METHOD_CHECK_STATUS(dfo, "Error setting symbol value");
133
135}
136/* }}} */
137
138/* {{{ Get formatter locale. */
140{
141 char *loc;
143
145
146 /* Parse parameters. */
148 &object, IntlDateFormatter_ce_ptr,&loc_type) == FAILURE )
149 {
150
152 }
153
154 /* Fetch the object. */
156
157 loc = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), loc_type,&INTL_DATA_ERROR_CODE(dfo));
158 INTL_METHOD_CHECK_STATUS(dfo, "Error getting locale");
159 RETURN_STRING(loc);
160}
161/* }}} */
162
163/* {{{ Get formatter isLenient. */
165{
166
168
169 /* Parse parameters. */
171 &object, IntlDateFormatter_ce_ptr ) == FAILURE )
172 {
173
175 }
176
177 /* Fetch the object. */
179
180 RETVAL_BOOL(udat_isLenient(DATE_FORMAT_OBJECT(dfo)));
181}
182/* }}} */
183
184/* {{{ Set formatter lenient. */
186{
187 bool isLenient = false;
188
190
191 /* Parse parameters. */
193 &object, IntlDateFormatter_ce_ptr,&isLenient ) == FAILURE )
194 {
196 }
197
198 /* Fetch the object. */
200
201 udat_setLenient(DATE_FORMAT_OBJECT(dfo), (UBool)isLenient );
202}
203/* }}} */
const ULOC_ACTUAL_LOCALE
const U_BUFFER_OVERFLOW_ERROR
const U_ZERO_ERROR
zend_class_entry * IntlDateFormatter_ce_ptr
#define DATE_FORMAT_METHOD_FETCH_OBJECT
#define DATE_FORMAT_OBJECT(dfo)
#define DATE_FORMAT_METHOD_INIT_VARS
#define NULL
Definition gdcache.h:45
#define USIZE(data)
Definition intl_common.h:38
#define eumalloc(size)
Definition intl_common.h:31
void intl_convert_utf8_to_utf16(UChar **target, int32_t *target_len, const char *src, size_t src_len, UErrorCode *status)
#define INTL_DATA_ERROR_CODE(obj)
Definition intl_data.h:40
#define INTL_METHOD_CHECK_STATUS(obj, msg)
Definition intl_data.h:66
#define INTL_METHOD_RETVAL_UTF8(obj, ustring, ulen, free_it)
Definition intl_data.h:103
#define svalue(o)
Definition minilua.c:281
#define PHP_FUNCTION
Definition php.h:364
datefmt_is_lenient(IntlDateFormatter $formatter)
datefmt_get_pattern(IntlDateFormatter $formatter)
datefmt_get_timetype(IntlDateFormatter $formatter)
datefmt_set_lenient(IntlDateFormatter $formatter, bool $lenient)
datefmt_get_datetype(IntlDateFormatter $formatter)
datefmt_get_locale(IntlDateFormatter $formatter, int $type=ULOC_ACTUAL_LOCALE)
datefmt_set_pattern(IntlDateFormatter $formatter, string $pattern)
ZEND_API zend_result zend_parse_method_parameters(uint32_t num_args, zval *this_ptr, const char *type_spec,...)
Definition zend_API.c:1314
#define ZEND_NUM_ARGS()
Definition zend_API.h:530
#define RETURN_STRING(s)
Definition zend_API.h:1043
#define RETURN_LONG(l)
Definition zend_API.h:1037
#define RETURN_THROWS()
Definition zend_API.h:1060
#define RETVAL_BOOL(b)
Definition zend_API.h:1009
#define getThis()
Definition zend_API.h:526
#define RETURN_TRUE
Definition zend_API.h:1059
#define efree(ptr)
Definition zend_alloc.h:155
int32_t zend_long
Definition zend_long.h:42
@ FAILURE
Definition zend_types.h:61
value