File: dateformat_set_timezone_id2.phpt

package info (click to toggle)
php8.2 8.2.29-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 209,600 kB
  • sloc: ansic: 736,658; php: 33,046; sh: 11,432; cpp: 7,005; pascal: 4,448; javascript: 3,112; asm: 2,404; yacc: 2,222; xml: 1,784; makefile: 689; awk: 148
file content (85 lines) | stat: -rw-r--r-- 3,104 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
--TEST--
datefmt_set_timezone_id_code() icu >= 4.8
--INI--
date.timezone=Atlantic/Azores
--EXTENSIONS--
intl
--SKIPIF--
<?php if (version_compare(INTL_ICU_VERSION, '50.1.2') >=  0) die('skip for ICU < 50.1.2'); ?>
--FILE--
<?php

ini_set("intl.error_level", E_WARNING);

/*
 * Test for the datefmt_set_timezone_id  function
 */


function ut_main()
{
    $timezone_id_arr = array (
        'America/New_York',
        'America/Los_Angeles',
        'America/Chicago',
        'CN'
    );
    $timestamp_entry = 0;

    $res_str = '';

    $fmt = ut_datefmt_create( "en_US",  IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'US/Pacific' , IntlDateFormatter::GREGORIAN  );
    $timezone_id = ut_datefmt_get_timezone_id( $fmt );
    $res_str .= "\nAfter creation of the dateformatter :  timezone_id= $timezone_id\n";

    foreach( $timezone_id_arr as $timezone_id_entry )
    {

        $res_str .= "-----------";
        $res_str .= "\nTrying to set timezone_id= $timezone_id_entry";
        ut_datefmt_set_timezone_id( $fmt , $timezone_id_entry );
        $timezone_id = ut_datefmt_get_timezone_id( $fmt );
        $res_str .= "\nAfter call to set_timezone_id :  timezone_id= $timezone_id";
        $formatted = ut_datefmt_format( $fmt, 0);
        $res_str .= "\nFormatting timestamp=0 resulted in  $formatted";
        $formatted = ut_datefmt_format( $fmt, 3600);
        $res_str .= "\nFormatting timestamp=3600 resulted in  $formatted";
        $res_str .= "\n";

    }

    return $res_str;

}

include_once( 'ut_common.inc' );

// Run the test
ut_run();
?>
--EXPECTF--
Warning: IntlDateFormatter::setTimeZone(): datefmt_set_timezone: No such time zone: 'CN' in %s on line %d

Warning: datefmt_set_timezone(): datefmt_set_timezone: No such time zone: 'CN' in %s on line %d

After creation of the dateformatter :  timezone_id= US/Pacific
-----------
Trying to set timezone_id= America/New_York
After call to set_timezone_id :  timezone_id= America/New_York
Formatting timestamp=0 resulted in  Wednesday, December 31, 1969 7:00:00 PM Eastern Standard Time
Formatting timestamp=3600 resulted in  Wednesday, December 31, 1969 8:00:00 PM Eastern Standard Time
-----------
Trying to set timezone_id= America/Los_Angeles
After call to set_timezone_id :  timezone_id= America/Los_Angeles
Formatting timestamp=0 resulted in  Wednesday, December 31, 1969 4:00:00 PM Pacific Standard Time
Formatting timestamp=3600 resulted in  Wednesday, December 31, 1969 5:00:00 PM Pacific Standard Time
-----------
Trying to set timezone_id= America/Chicago
After call to set_timezone_id :  timezone_id= America/Chicago
Formatting timestamp=0 resulted in  Wednesday, December 31, 1969 6:00:00 PM Central Standard Time
Formatting timestamp=3600 resulted in  Wednesday, December 31, 1969 7:00:00 PM Central Standard Time
-----------
Trying to set timezone_id= CN
After call to set_timezone_id :  timezone_id= America/Chicago
Formatting timestamp=0 resulted in  Wednesday, December 31, 1969 6:00:00 PM Central Standard Time
Formatting timestamp=3600 resulted in  Wednesday, December 31, 1969 7:00:00 PM Central Standard Time