1--TEST--
2datefmt_set_timezone_id_code() icu >= 4.8
3--INI--
4date.timezone=Atlantic/Azores
5--EXTENSIONS--
6intl
7--SKIPIF--
8<?php if (version_compare(INTL_ICU_VERSION, '72.1') < 0) die('skip for ICU >= 72.1'); ?>
9--FILE--
10<?php
11
12ini_set("intl.error_level", E_WARNING);
13
14/*
15 * Test for the datefmt_set_timezone_id  function
16 */
17
18
19function ut_main()
20{
21    $timezone_id_arr = array (
22        'America/New_York',
23        'America/Los_Angeles',
24        'America/Chicago',
25        'CN'
26    );
27    $timestamp_entry = 0;
28
29    $res_str = '';
30
31    $fmt = ut_datefmt_create( "en_US",  IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'US/Pacific' , IntlDateFormatter::GREGORIAN  );
32    $timezone_id = ut_datefmt_get_timezone_id( $fmt );
33    $res_str .= "\nAfter creation of the dateformatter :  timezone_id= $timezone_id\n";
34
35    foreach( $timezone_id_arr as $timezone_id_entry )
36    {
37
38        $res_str .= "-----------";
39        $res_str .= "\nTrying to set timezone_id= $timezone_id_entry";
40        ut_datefmt_set_timezone_id( $fmt , $timezone_id_entry );
41        $timezone_id = ut_datefmt_get_timezone_id( $fmt );
42        $res_str .= "\nAfter call to set_timezone_id :  timezone_id= $timezone_id";
43        $formatted = ut_datefmt_format( $fmt, 0);
44        $res_str .= "\nFormatting timestamp=0 resulted in  $formatted";
45        $formatted = ut_datefmt_format( $fmt, 3600);
46        $res_str .= "\nFormatting timestamp=3600 resulted in  $formatted";
47        $res_str .= "\n";
48
49    }
50
51    return $res_str;
52
53}
54
55include_once( 'ut_common.inc' );
56
57// Run the test
58ut_run();
59?>
60--EXPECTF--
61Warning: IntlDateFormatter::setTimeZone(): datefmt_set_timezone: No such time zone: 'CN' in %sut_common.inc on line %d
62
63Warning: datefmt_set_timezone(): datefmt_set_timezone: No such time zone: 'CN' in %sut_common.inc on line %d
64
65After creation of the dateformatter :  timezone_id= US/Pacific
66-----------
67Trying to set timezone_id= America/New_York
68After call to set_timezone_id :  timezone_id= America/New_York
69Formatting timestamp=0 resulted in  Wednesday, December 31, 1969 at 7:00:00 PM Eastern Standard Time
70Formatting timestamp=3600 resulted in  Wednesday, December 31, 1969 at 8:00:00 PM Eastern Standard Time
71-----------
72Trying to set timezone_id= America/Los_Angeles
73After call to set_timezone_id :  timezone_id= America/Los_Angeles
74Formatting timestamp=0 resulted in  Wednesday, December 31, 1969 at 4:00:00 PM Pacific Standard Time
75Formatting timestamp=3600 resulted in  Wednesday, December 31, 1969 at 5:00:00 PM Pacific Standard Time
76-----------
77Trying to set timezone_id= America/Chicago
78After call to set_timezone_id :  timezone_id= America/Chicago
79Formatting timestamp=0 resulted in  Wednesday, December 31, 1969 at 6:00:00 PM Central Standard Time
80Formatting timestamp=3600 resulted in  Wednesday, December 31, 1969 at 7:00:00 PM Central Standard Time
81-----------
82Trying to set timezone_id= CN
83After call to set_timezone_id :  timezone_id= America/Chicago
84Formatting timestamp=0 resulted in  Wednesday, December 31, 1969 at 6:00:00 PM Central Standard Time
85Formatting timestamp=3600 resulted in  Wednesday, December 31, 1969 at 7:00:00 PM Central Standard Time
86