<?php

namespace App\Models\Traits;

use Carbon\Carbon;

trait FormattedDateTrait
{
    /**
     * Return the created at datetime as mon D, year.
     *
     * @since 1.0.0
     *
     * @param string $dateTimeString
     *
     * @return string
     */
    public function getCreatedAtDateShortAttribute(): string
    {
        return $this->created_at->format('M j, Y');
    }

    /**
     * Return the created at datetime as month day, year.
     *
     * @since 1.0.0
     *
     * @param string $dateTimeString
     *
     * @return string
     */
    public function getCreatedAtDateFullAttribute(): string
    {
        return $this->created_at->format('F jS, Y');
    }

    /**
     * Return the created at datetime as month day, year hour:minute meridian.
     *
     * @since 1.0.0
     *
     * @param string $dateTimeString
     *
     * @return string
     */
    public function getCreatedAtFullAttribute(): string
    {
        return $this->created_at->format('F jS, Y g:i a');
    }

    /**
     * Return the updated at datetime as mon day, year.
     *
     * @since 1.0.0
     *
     * @param string $dateTimeString
     *
     * @return string
     */
    public function getUpdatedAtDateShortAttribute(): string
    {
        if (empty($this->updated_at)) {
            return '--';
        }
        return $this->updated_at->format('M j, Y');
    }

    /**
     * Return the updated at datetime as mon day, year.
     *
     * @since 1.0.0
     *
     * @param string $dateTimeString
     *
     * @return string
     */
    public function getUpdatedAtDateFullAttribute(): string
    {
        if (empty($this->updated_at)) {
            return '--';
        }
        return $this->updated_at->format('F jS, Y');
    }

    /**
     * Return the updated at datetime as mon day, year hour:minute meridian.
     *
     * @since 1.0.0
     *
     * @param string $dateTimeString
     *
     * @return string
     */
    public function getUpdatedAtFullAttribute(): string
    {
        if (empty($this->updated_at)) {
            return '--';
        }
        return $this->updated_at->format('F jS, Y g:i a');
    }

    /**
     * Return a datetime string as YYYY-MM-DD.
     *
     * @since 1.0.0
     *
     * @param string $dateTimeString
     *
     * @return string
     */
    public static function dateStr(string $dateTimeString): string
    {
        return Carbon::parse($dateTimeString)->format('Y-m-d');
    }

    /**
     * Return a datetime string as mon d, year.
     *
     * @since 1.0.0
     *
     * @param string $dateTimeString
     *
     * @return string
     */
    public static function dateShort(string $dateTimeString): string
    {
        return Carbon::parse($dateTimeString)->format('M j, Y');
    }

    /**
     * Return a datetime string as month day, year.
     *
     * @since 1.0.0
     *
     * @param string $dateTimeString
     *
     * @return string
     */
    public static function dateFull(string $dateTimeString): string
    {
        return Carbon::parse($dateTimeString)->format('F jS, Y');
    }

    /**
     * Return a datetime string as HH:MM (military time)
     *
     * @since 1.0.0
     *
     * @param string $dateTimeString
     *
     * @return string
     */
    public static function timeShort(string $dateTimeString): string
    {
        return Carbon::parse($dateTimeString)->format('H:i');
    }

    /**
     * Return a datetime string as hour:minute meridian
     *
     * @since 1.0.0
     *
     * @param string $dateTimeString
     *
     * @return string
     */
    public static function timeFull(string $dateTimeString): string
    {
        return Carbon::parse($dateTimeString)->format('g:i a');
    }
}
