1 | <?php |
||
2 | |||
3 | /** |
||
4 | * JPGraph v4.0.3 |
||
5 | */ |
||
6 | |||
7 | namespace Amenadiel\JpGraph\Util; |
||
8 | |||
9 | /** |
||
10 | * @class DateLocale |
||
11 | * // Description: Hold localized text used in dates |
||
12 | */ |
||
13 | class DateLocale |
||
14 | { |
||
15 | public $iLocale = 'C'; // environmental locale be used by default |
||
16 | private $iDayAbb; |
||
17 | private $iShortDay; |
||
18 | private $iShortMonth; |
||
19 | private $iMonthName; |
||
20 | |||
21 | 21 | public function __construct() |
|
22 | { |
||
23 | 21 | settype($this->iDayAbb, 'array'); |
|
24 | 21 | settype($this->iShortDay, 'array'); |
|
25 | 21 | settype($this->iShortMonth, 'array'); |
|
26 | 21 | settype($this->iMonthName, 'array'); |
|
27 | 21 | $this->Set('C'); |
|
28 | 21 | } |
|
29 | |||
30 | 21 | public function Set($aLocale) |
|
31 | { |
||
32 | 21 | if (in_array($aLocale, array_keys($this->iDayAbb), true)) { |
|
33 | $this->iLocale = $aLocale; |
||
34 | |||
35 | return true; // already cached nothing else to do! |
||
36 | } |
||
37 | |||
38 | 21 | $pLocale = setlocale(LC_TIME, 0); // get current locale for LC_TIME |
|
39 | |||
40 | 21 | if (is_array($aLocale)) { |
|
41 | foreach ($aLocale as $loc) { |
||
42 | $res = @setlocale(LC_TIME, $loc); |
||
43 | if ($res) { |
||
44 | $aLocale = $loc; |
||
45 | |||
46 | break; |
||
47 | } |
||
48 | } |
||
49 | } else { |
||
50 | 21 | $res = @setlocale(LC_TIME, $aLocale); |
|
51 | } |
||
52 | |||
53 | 21 | if (!$res) { |
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
54 | JpGraphError::RaiseL(25007, $aLocale); |
||
55 | //("You are trying to use the locale ($aLocale) which your PHP installation does not support. Hint: Use '' to indicate the default locale for this geographic region."); |
||
56 | return false; |
||
57 | } |
||
58 | |||
59 | 21 | $this->iLocale = $aLocale; |
|
60 | 21 | for ($i = 0, $ofs = 0 - strftime('%w'); $i < 7; $i++, $ofs++) { |
|
61 | 21 | $day = strftime('%a', strtotime("${ofs} day")); |
|
62 | 21 | $day[0] = strtoupper($day[0]); |
|
63 | 21 | $this->iDayAbb[$aLocale][] = $day[0]; |
|
64 | 21 | $this->iShortDay[$aLocale][] = $day; |
|
65 | } |
||
66 | |||
67 | 21 | for ($i = 1; $i <= 12; ++$i) { |
|
68 | 21 | list($short, $full) = explode('|', strftime('%b|%B', strtotime("2001-${i}-01"))); |
|
69 | 21 | $this->iShortMonth[$aLocale][] = ucfirst($short); |
|
70 | 21 | $this->iMonthName[$aLocale][] = ucfirst($full); |
|
71 | } |
||
72 | |||
73 | 21 | setlocale(LC_TIME, $pLocale); |
|
74 | |||
75 | 21 | return true; |
|
76 | } |
||
77 | |||
78 | public function GetDayAbb() |
||
79 | { |
||
80 | return $this->iDayAbb[$this->iLocale]; |
||
81 | } |
||
82 | |||
83 | public function GetShortDay() |
||
84 | { |
||
85 | return $this->iShortDay[$this->iLocale]; |
||
86 | } |
||
87 | |||
88 | 6 | public function GetShortMonth() |
|
89 | { |
||
90 | 6 | return $this->iShortMonth[$this->iLocale]; |
|
91 | } |
||
92 | |||
93 | public function GetShortMonthName($aNbr) |
||
94 | { |
||
95 | return $this->iShortMonth[$this->iLocale][$aNbr]; |
||
96 | } |
||
97 | |||
98 | public function GetLongMonthName($aNbr) |
||
99 | { |
||
100 | return $this->iMonthName[$this->iLocale][$aNbr]; |
||
101 | } |
||
102 | |||
103 | public function GetMonth() |
||
104 | { |
||
105 | return $this->iMonthName[$this->iLocale]; |
||
106 | } |
||
107 | } |
||
108 |