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