<?php

namespace Dipper\Foundation\Support;

use Carbon\Carbon;
use Carbon\Exceptions\InvalidDateException;

class Time
{
    /**
     * 格式化时间
     *
     * @param string|int $timestamp
     * @return void
     */
    public static function parse($timestamp = null)
    {
        if (is_numeric($timestamp)) {
            return Carbon::createFromTimestamp($timestamp);
        }

        if (!is_null($timestamp)) {
            try {
                return Carbon::parse($timestamp);
            } catch (\Exception $e) {
                throw new InvalidDateException('时间', $timestamp);
            }
        }
    }
}
