<?php

namespace App\v2\Utils;

use DateTime;
use Exception;

class DateUtils
{
    public static function castStringToDateTime(?string $date): ?DateTime
    {
        if (!$date) {
            return null;
        }
        try {
            return new DateTime($date);
        } catch (Exception $exception) {
            return null;
        }
    }

    public static function formatDateIso8601(DateTime $dateTime): string
    {
        return $dateTime->format('Y-m-d H:i:s');
    }
}

