PluginProbe
User Access Manager / 2.3.2
User Access Manager v2.3.2
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/Util/DateUtil.php +25 -9 trunk2.3.2 View file →
@@ -3,8 +3,9 @@
3 3 declare(strict_types=1);
4 4
5 5 namespace UserAccessManager\Util;
6 6
7 +use Exception;
7 8 use UserAccessManager\Wrapper\Wordpress;
8 9
9 10 class DateUtil
10 11 {
@@ -11,28 +12,43 @@
11 12 public function __construct(private Wordpress $wordpress)
12 13 {
13 14 }
14 15
15 - private function formatDateWith(?string $date, string $format): ?string
16 + public function formatDate(string $date): string
16 17 {
17 - return ($date !== null) ? date($format, (int) strtotime($date)) : null;
18 + return $this->wordpress->formatDate($date);
18 19 }
19 20
20 - public function formatDate(string $date): string
21 + /**
22 + * @throws Exception
23 + */
24 + public function formatDateForDatetimeInput(?string $date): ?string
21 25 {
22 - return $this->wordpress->formatDate($date);
26 + return ($date !== null) ? date('Y-m-d\TH:i:s', (int) strtotime($date)) : $date;
23 27 }
24 28
25 - public function formatDateForDatetimeInput(?string $date): ?string
29 + /**
30 + * @throws Exception
31 + */
32 + public function formatDateForDateInput(?string $date): ?string
26 33 {
27 - return $this->formatDateWith($date, 'Y-m-d\TH:i:s');
34 + return ($date !== null) ? date('Y-m-d', (int) strtotime($date)) : $date;
28 35 }
29 36
37 + /**
38 + * @throws Exception
39 + */
40 + public function formatDateForTimeInput(?string $date): ?string
41 + {
42 + return ($date !== null) ? date('H:i:s', (int) strtotime($date)) : $date;
43 + }
44 +
30 45 public function getDateFromTime(?int $time): ?string
31 46 {
32 - if ($time === null || $time === 0) {
33 - return null;
47 + if ($time !== null && $time !== 0) {
48 + $currentTime = $this->wordpress->currentTime('timestamp');
49 + return gmdate('Y-m-d H:i:s', $time + $currentTime);
34 50 }
35 51
36 - return gmdate('Y-m-d H:i:s', $time + $this->wordpress->currentTime('timestamp'));
52 + return null;
37 53 }
38 54 }