PluginProbe
User Access Manager / 2.3.7
User Access Manager v2.3.7
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
user-access-manager / src / Util / DateUtil.php

DateUtil.php in User Access Manager 2.3.7, at src/Util/DateUtil.php

55 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace UserAccessManager\Util;
6
7 use Exception;
8 use UserAccessManager\Wrapper\Wordpress;
9
10 class DateUtil
11 {
12 public function __construct(private Wordpress $wordpress)
13 {
14 }
15
16 public function formatDate(string $date): string
17 {
18 return $this->wordpress->formatDate($date);
19 }
20
21 /**
22 * @throws Exception
23 */
24 public function formatDateForDatetimeInput(?string $date): ?string
25 {
26 return ($date !== null) ? date('Y-m-d\TH:i:s', (int) strtotime($date)) : $date;
27 }
28
29 /**
30 * @throws Exception
31 */
32 public function formatDateForDateInput(?string $date): ?string
33 {
34 return ($date !== null) ? date('Y-m-d', (int) strtotime($date)) : $date;
35 }
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
45 public function getDateFromTime(?int $time): ?string
46 {
47 if ($time !== null && $time !== 0) {
48 $currentTime = $this->wordpress->currentTime('timestamp');
49 return gmdate('Y-m-d H:i:s', $time + $currentTime);
50 }
51
52 return null;
53 }
54 }
55