Annotation of embedaddon/php/ext/intl/tests/dateformat_format_parse.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: datefmt_format_code() and datefmt_parse_code()
3: --SKIPIF--
4: <?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5: --FILE--
6: <?php
7:
8: /*
9: * Test for the datefmt_format function
10: */
11:
12:
13: function ut_main()
14: {
15: $timezone = 'GMT+5';
16:
17: $locale_arr = array (
18: 'en_US'
19: );
20:
21: $datetype_arr = array (
22: IntlDateFormatter::FULL,
23: IntlDateFormatter::LONG,
24: IntlDateFormatter::MEDIUM
25: );
26:
27: $res_str = '';
28:
29:
30: $time_arr = array (
31: 0,
32: -1200000,
33: 1200000,
34: 2200000000,
35: -2200000000,
36: 90099999,
37: 3600,
38: -3600
39: );
40:
41: $localtime_arr1 = array (
42: 'tm_sec' => 24 ,
43: 'tm_min' => 3,
44: 'tm_hour' => 19,
45: 'tm_mday' => 3,
46: 'tm_mon' => 3,
47: 'tm_year' => 105,
48: );
49: $localtime_arr2 = array (
50: 'tm_sec' => 21,
51: 'tm_min' => 5,
52: 'tm_hour' => 7,
53: 'tm_mday' => 13,
54: 'tm_mon' => 7,
55: 'tm_year' => 205,
56: );
57: $localtime_arr3 = array (
58: 'tm_sec' => 11,
59: 'tm_min' => 13,
60: 'tm_hour' => 0,
61: 'tm_mday' => 17,
62: 'tm_mon' => 11,
63: 'tm_year' => -5
64: );
65:
66: $localtime_arr = array (
67: $localtime_arr1,
68: $localtime_arr2,
69: $localtime_arr3
70: );
71:
72: //Test format and parse with a timestamp : long
73: foreach( $time_arr as $timestamp_entry){
74: $res_str .= "\n------------\n";
75: $res_str .= "\nInput timestamp is : $timestamp_entry";
76: $res_str .= "\n------------\n";
77: foreach( $locale_arr as $locale_entry ){
78: foreach( $datetype_arr as $datetype_entry ) {
79: $res_str .= "\nIntlDateFormatter locale= $locale_entry ,datetype = $datetype_entry ,timetype =$datetype_entry ";
80: $fmt = ut_datefmt_create( $locale_entry , $datetype_entry ,$datetype_entry,$timezone);
81: $formatted = ut_datefmt_format( $fmt , $timestamp_entry);
82: $res_str .= "\nFormatted timestamp is : $formatted";
83: $parsed = ut_datefmt_parse( $fmt , $formatted);
84: if( intl_get_error_code() == U_ZERO_ERROR){
85: $res_str .= "\nParsed timestamp is : $parsed";
86: }else{
87: $res_str .= "\nError while parsing as: '".intl_get_error_message()."'";
88: }
89: }
90: }
91: }
92:
93: //Test format and parse with a localtime :array
94: foreach( $localtime_arr as $localtime_entry){
95: $res_str .= "\n------------\n";
96: $res_str .= "\nInput localtime is : ";
97: foreach( $localtime_entry as $key => $value){
98: $res_str .= "$key : '$value' , ";
99: }
100:
101: $res_str .= "\n------------\n";
102: foreach( $locale_arr as $locale_entry ){
103: foreach( $datetype_arr as $datetype_entry ) {
104: $res_str .= "\nIntlDateFormatter locale= $locale_entry ,datetype = $datetype_entry ,timetype =$datetype_entry ";
105: $fmt = ut_datefmt_create( $locale_entry , $datetype_entry ,$datetype_entry,$timezone);
106: $formatted1 = ut_datefmt_format( $fmt , $localtime_entry);
107: if( intl_get_error_code() == U_ZERO_ERROR){
108: $res_str .= "\nFormatted localtime_array is : $formatted1";
109: }else{
110: $res_str .= "\nError while formatting as: '".intl_get_error_message()."'";
111: }
112: //Parsing
113: $parsed_arr = ut_datefmt_localtime( $fmt, $formatted1 );
114:
115: if( $parsed_arr){
116: $res_str .= "\nParsed array is: ";
117: foreach( $parsed_arr as $key => $value){
118: $res_str .= "$key : '$value' , ";
119: }
120: }
121: /*
122: else{
123: //$res_str .= "No values found from LocaleTime parsing.";
124: $res_str .= "\tError : '".intl_get_error_message()."'";
125: }
126: */
127: }
128: }
129: }
130:
131: return $res_str;
132:
133: }
134:
135: include_once( 'ut_common.inc' );
136:
137: // Run the test
138: ut_run();
139: ?>
140: --EXPECT--
141: ------------
142:
143: Input timestamp is : 0
144: ------------
145:
146: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
147: Formatted timestamp is : Thursday, January 1, 1970 5:00:00 AM GMT+05:00
148: Parsed timestamp is : 0
149: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
150: Formatted timestamp is : January 1, 1970 5:00:00 AM GMT+05:00
151: Parsed timestamp is : 0
152: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
153: Formatted timestamp is : Jan 1, 1970 5:00:00 AM
154: Parsed timestamp is : 0
155: ------------
156:
157: Input timestamp is : -1200000
158: ------------
159:
160: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
161: Formatted timestamp is : Thursday, December 18, 1969 7:40:00 AM GMT+05:00
162: Parsed timestamp is : -1200000
163: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
164: Formatted timestamp is : December 18, 1969 7:40:00 AM GMT+05:00
165: Parsed timestamp is : -1200000
166: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
167: Formatted timestamp is : Dec 18, 1969 7:40:00 AM
168: Parsed timestamp is : -1200000
169: ------------
170:
171: Input timestamp is : 1200000
172: ------------
173:
174: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
175: Formatted timestamp is : Thursday, January 15, 1970 2:20:00 AM GMT+05:00
176: Parsed timestamp is : 1200000
177: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
178: Formatted timestamp is : January 15, 1970 2:20:00 AM GMT+05:00
179: Parsed timestamp is : 1200000
180: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
181: Formatted timestamp is : Jan 15, 1970 2:20:00 AM
182: Parsed timestamp is : 1200000
183: ------------
184:
185: Input timestamp is : 2200000000
186: ------------
187:
188: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
189: Formatted timestamp is : Monday, September 19, 2039 4:06:40 AM GMT+05:00
190: Parsed timestamp is : 2200000000
191: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
192: Formatted timestamp is : September 19, 2039 4:06:40 AM GMT+05:00
193: Parsed timestamp is : 2200000000
194: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
195: Formatted timestamp is : Sep 19, 2039 4:06:40 AM
196: Parsed timestamp is : 2200000000
197: ------------
198:
199: Input timestamp is : -2200000000
200: ------------
201:
202: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
203: Formatted timestamp is : Sunday, April 15, 1900 5:53:20 AM GMT+05:00
204: Parsed timestamp is : -2200000000
205: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
206: Formatted timestamp is : April 15, 1900 5:53:20 AM GMT+05:00
207: Parsed timestamp is : -2200000000
208: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
209: Formatted timestamp is : Apr 15, 1900 5:53:20 AM
210: Parsed timestamp is : -2200000000
211: ------------
212:
213: Input timestamp is : 90099999
214: ------------
215:
216: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
217: Formatted timestamp is : Thursday, November 9, 1972 12:46:39 AM GMT+05:00
218: Parsed timestamp is : 90099999
219: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
220: Formatted timestamp is : November 9, 1972 12:46:39 AM GMT+05:00
221: Parsed timestamp is : 90099999
222: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
223: Formatted timestamp is : Nov 9, 1972 12:46:39 AM
224: Parsed timestamp is : 90099999
225: ------------
226:
227: Input timestamp is : 3600
228: ------------
229:
230: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
231: Formatted timestamp is : Thursday, January 1, 1970 6:00:00 AM GMT+05:00
232: Parsed timestamp is : 3600
233: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
234: Formatted timestamp is : January 1, 1970 6:00:00 AM GMT+05:00
235: Parsed timestamp is : 3600
236: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
237: Formatted timestamp is : Jan 1, 1970 6:00:00 AM
238: Parsed timestamp is : 3600
239: ------------
240:
241: Input timestamp is : -3600
242: ------------
243:
244: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
245: Formatted timestamp is : Thursday, January 1, 1970 4:00:00 AM GMT+05:00
246: Parsed timestamp is : -3600
247: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
248: Formatted timestamp is : January 1, 1970 4:00:00 AM GMT+05:00
249: Parsed timestamp is : -3600
250: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
251: Formatted timestamp is : Jan 1, 1970 4:00:00 AM
252: Parsed timestamp is : -3600
253: ------------
254:
255: Input localtime is : tm_sec : '24' , tm_min : '3' , tm_hour : '19' , tm_mday : '3' , tm_mon : '3' , tm_year : '105' ,
256: ------------
257:
258: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
259: Formatted localtime_array is : Sunday, April 3, 2005 7:03:24 PM GMT+05:00
260: Parsed array is: tm_sec : '24' , tm_min : '3' , tm_hour : '19' , tm_year : '105' , tm_mday : '3' , tm_wday : '0' , tm_yday : '93' , tm_mon : '3' , tm_isdst : '0' ,
261: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
262: Formatted localtime_array is : April 3, 2005 7:03:24 PM GMT+05:00
263: Parsed array is: tm_sec : '24' , tm_min : '3' , tm_hour : '19' , tm_year : '105' , tm_mday : '3' , tm_wday : '0' , tm_yday : '93' , tm_mon : '3' , tm_isdst : '0' ,
264: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
265: Formatted localtime_array is : Apr 3, 2005 7:03:24 PM
266: Parsed array is: tm_sec : '24' , tm_min : '3' , tm_hour : '19' , tm_year : '105' , tm_mday : '3' , tm_wday : '0' , tm_yday : '93' , tm_mon : '3' , tm_isdst : '0' ,
267: ------------
268:
269: Input localtime is : tm_sec : '21' , tm_min : '5' , tm_hour : '7' , tm_mday : '13' , tm_mon : '7' , tm_year : '205' ,
270: ------------
271:
272: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
273: Formatted localtime_array is : Thursday, August 13, 2105 7:05:21 AM GMT+05:00
274: Parsed array is: tm_sec : '21' , tm_min : '5' , tm_hour : '7' , tm_year : '205' , tm_mday : '13' , tm_wday : '4' , tm_yday : '225' , tm_mon : '7' , tm_isdst : '0' ,
275: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
276: Formatted localtime_array is : August 13, 2105 7:05:21 AM GMT+05:00
277: Parsed array is: tm_sec : '21' , tm_min : '5' , tm_hour : '7' , tm_year : '205' , tm_mday : '13' , tm_wday : '4' , tm_yday : '225' , tm_mon : '7' , tm_isdst : '0' ,
278: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
279: Formatted localtime_array is : Aug 13, 2105 7:05:21 AM
280: Parsed array is: tm_sec : '21' , tm_min : '5' , tm_hour : '7' , tm_year : '205' , tm_mday : '13' , tm_wday : '4' , tm_yday : '225' , tm_mon : '7' , tm_isdst : '0' ,
281: ------------
282:
283: Input localtime is : tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_mday : '17' , tm_mon : '11' , tm_year : '-5' ,
284: ------------
285:
286: IntlDateFormatter locale= en_US ,datetype = 0 ,timetype =0
287: Formatted localtime_array is : Tuesday, December 17, 1895 12:13:11 AM GMT+05:00
288: Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' ,
289: IntlDateFormatter locale= en_US ,datetype = 1 ,timetype =1
290: Formatted localtime_array is : December 17, 1895 12:13:11 AM GMT+05:00
291: Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' ,
292: IntlDateFormatter locale= en_US ,datetype = 2 ,timetype =2
293: Formatted localtime_array is : Dec 17, 1895 12:13:11 AM
294: Parsed array is: tm_sec : '11' , tm_min : '13' , tm_hour : '0' , tm_year : '-5' , tm_mday : '17' , tm_wday : '2' , tm_yday : '351' , tm_mon : '11' , tm_isdst : '0' ,
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>