| 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 |
|