DateTimeZone   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 66
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromString() 0 4 1
A fromOffset() 0 12 3
A getLongName() 0 4 1
1
<?php
2
namespace SubjectivePHP\Util;
3
4
use SubjectivePHP\DateTime\Utilities\DateTimeZoneUtil;
5
6
/**
7
 * @deprecated Will be removed in version 4
8
 */
9
abstract class DateTimeZone
10
{
11
    /**
12
     * Array of edge case timezones
13
     *
14
     * @var array
15
     */
16
    private static $outliers = [
17
        'WIB' => 'Asia/Jakarta',  //Western Indonesian Time
18
        'FET' => 'Europe/Helsinki', //Further-eastern European Time
19
        'AEST' => 'Australia/Tasmania', //Australia Eastern Standard Time
20
        'AWST' => 'Australia/West', //Australia Western Standard Time
21
        'WITA' => 'Asia/Makassar',
22
        'AEDT' => 'Australia/Sydney', //Australia Eastern Daylight Time
23
        'ACDT' => 'Australia/Adelaide', //Australia Central Daylight Time
24
    ];
25
26
    /**
27
     * Returns a \DateTimeZone instance for the give nameOrAbbreviation.
28
     *
29
     * @param string        $nameOrAbbreviation The timezone nameOrAbbreviation.
30
     * @param \DateTimeZone $default            The default timezone to return if none can be created.
31
     *
32
     * @return \DateTimeZone
33
     */
34
    final public static function fromString($nameOrAbbreviation, \DateTimeZone $default = null)
35
    {
36
        return DateTimeZoneUtil::fromString($nameOrAbbreviation, $default);
37
    }
38
39
    /**
40
     * Returns a \DateTimeZone object based on gmt offset.
41
     *
42
     * @param integer $gmtOffset         Offset from GMT in seconds.
43
     * @param boolean $isDaylightSavings Daylight saving time indicator.
44
     *
45
     * @return \DateTimeZone
46
     *
47
     * @throws \InvalidArgumentException Thrown if $gmtOffset is not an integer.
48
     * @throws \InvalidArgumentException Thrown if $isDaylightSavings is not a boolean.
49
     */
50
    final public static function fromOffset($gmtOffset, $isDaylightSavings)
51
    {
52
        if (!is_int($gmtOffset)) {
53
            throw new \InvalidArgumentException('$gmtOffset must be an integer');
54
        }
55
56
        if (!is_bool($isDaylightSavings)) {
57
            throw new \InvalidArgumentException('$isDaylightSavings must be a boolean');
58
        }
59
60
        return DateTimeZoneUtil::fromString(timezone_name_from_abbr('', $gmtOffset, (int)$isDaylightSavings));
61
    }
62
63
    /**
64
     * Returns the long name of the given \DateTimeZone.
65
     *
66
     * @param \DateTimeZone $timezone The timezone object from which the long name should be obtained.
67
     *
68
     * @return string
69
     */
70
    final public static function getLongName(\DateTimeZone $timezone)
71
    {
72
        return DateTimeZoneUtil::getLongName($timezone);
73
    }
74
}
75