|
3 | 3 | * Copyright © Magento, Inc. All rights reserved. |
4 | 4 | * See COPYING.txt for license details. |
5 | 5 | */ |
6 | | - |
7 | 6 | namespace Magento\Framework\View\Element\Html; |
8 | 7 |
|
9 | 8 | /** |
10 | 9 | * Date element block |
11 | 10 | */ |
12 | 11 | class Date extends \Magento\Framework\View\Element\Template |
13 | 12 | { |
14 | | - /** |
15 | | - * Date format not supported function date(). |
16 | | - */ |
17 | | - private const DATE_FORMAT_NOT_SUPPORTED = [ |
18 | | - '%a', '%A', '%d', '%e', '%u', '%w', '%W', '%b', '%h', '%B', '%m', '%y', '%Y', '%D', '%F', '%x', '%n', '%t', |
19 | | - '%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X', '%z', '%Z', '%c', '%s', '%g', '%G', '%%' |
20 | | - ]; |
21 | | - |
22 | | - /** |
23 | | - * Date format supported by function date(). |
24 | | - */ |
25 | | - private const DATE_FORMAT_SUPPORTED = [ |
26 | | - 'D', 'l', 'd', 'j', 'N', 'w', 'W', 'M', 'M', 'F', 'm', 'y', 'Y', 'm/d/y', 'Y-m-d', 'm/d/y',"\n","\t", 'H', 'G', |
27 | | - 'h', 'g', 'i', 'A', 'a', 'h:i:s A', 'H:i', 's', 'H:i:s', 'H:i:s', 'O', 'T', 'D M j H:i:s Y', 'U', 'y', 'Y', '%' |
28 | | - ]; |
29 | | - |
30 | 13 | /** |
31 | 14 | * Render block HTML |
32 | 15 | * |
@@ -93,48 +76,20 @@ protected function _toHtml() |
93 | 76 | public function getEscapedValue() |
94 | 77 | { |
95 | 78 | if ($this->getFormat() && $this->getValue()) { |
96 | | - return $this->getDateByFormat($this->getFormat(), strtotime($this->getValue())); |
| 79 | + return strftime($this->getFormat(), strtotime($this->getValue())); |
97 | 80 | } |
98 | 81 | return $this->escapeHtml($this->getValue()); |
99 | 82 | } |
100 | 83 |
|
101 | 84 | /** |
102 | 85 | * Produce and return block's html output |
103 | 86 | * |
| 87 | + * {@inheritdoc} |
| 88 | + * |
104 | 89 | * @return string |
105 | 90 | */ |
106 | 91 | public function getHtml() |
107 | 92 | { |
108 | 93 | return $this->toHtml(); |
109 | 94 | } |
110 | | - |
111 | | - /** |
112 | | - * Method to get date by format. |
113 | | - * |
114 | | - * @param string $format |
115 | | - * @param int $timestamp |
116 | | - * |
117 | | - * @return string |
118 | | - */ |
119 | | - private function getDateByFormat(string $format, int $timestamp): string |
120 | | - { |
121 | | - $format = str_replace(self::DATE_FORMAT_NOT_SUPPORTED, self::DATE_FORMAT_SUPPORTED, $format); |
122 | | - |
123 | | - if (strpos($format, '%') !== false) { |
124 | | - $unsupportedData = ['%U', '%V', '%C']; |
125 | | - |
126 | | - foreach ($unsupportedData as $unsupported) { |
127 | | - if (strpos($format, $unsupported) !== false) { |
128 | | - if ($unsupported === '%C') { |
129 | | - $format = str_replace($unsupported, round(date("Y", $timestamp) / 100), $format); |
130 | | - |
131 | | - continue; |
132 | | - } |
133 | | - $format = str_replace($unsupported, date("W", strtotime("-1 day", $timestamp)), $format); |
134 | | - } |
135 | | - } |
136 | | - } |
137 | | - |
138 | | - return date($format, $timestamp); |
139 | | - } |
140 | 95 | } |
0 commit comments