<?php
declare(strict_types=1);

namespace FreshCloud\Mail\BaseUtils;

use DateTimeImmutable;
use DateTimeInterface;
use DateTimeZone;

final class DateHelper
{
    public static function nowUtc(): DateTimeImmutable
    {
        return new DateTimeImmutable('now', new DateTimeZone('UTC'));
    }

    public static function toIso8601(DateTimeInterface $dt): string
    {
        return $dt->format('Y-m-d\TH:i:s\Z');
    }

    public static function fromIso8601(string $iso): DateTimeImmutable
    {
        return new DateTimeImmutable($iso, new DateTimeZone('UTC'));
    }

    public static function formatRfc2822(DateTimeInterface $dt): string
    {
        return $dt->format('r');
    }

    public static function parseRfc2822(string $rfc): DateTimeImmutable
    {
        return new DateTimeImmutable($rfc, new DateTimeZone('UTC'));
    }
}