<?php

namespace Openguru\OpenCartFramework\Support;

use Carbon\Carbon;
use DateTimeZone;

class DateUtils
{
    public static function toUTC(?string $date = null): ?string
    {
        if (! $date) {
            return null;
        }

        return Carbon::parse($date)->setTimezone('UTC')->toJSON();
    }

    /**
     * @param string|null $date
     * @param DateTimeZone|string|null $tz
     * @return Carbon|null
     */
    public static function toSystemTimezone(?string $date = null, $tz = 'UTC'): ?Carbon
    {
        if (! $date) {
            return null;
        }

        $systemTimezone = date_default_timezone_get();

        return Carbon::parse($date, $tz)->timezone($systemTimezone);
    }
}
