<?php

namespace Daniv04\HaciendaPackage\Traits;

use Carbon\Carbon;

trait DateParserTrait
{
    /**
     * Parse date and return array with two-digit year
     * 
     * @param string $dateTime Date in ISO 8601 format (2024-01-15T10:30:00-06:00)
     * @return array ['day' => '15', 'month' => '01', 'year' => '24']
     */
    protected function parseDateToArray(string $dateTime): array
    {
        $date = Carbon::parse($dateTime);
        
        return [
            'day' => $date->format('d'),    
            'month' => $date->format('m'),   
            'year' => $date->format('y'),   
        ];
    }

    
    /**
     * Parse date and return Carbon object for manipulation
     * 
     * @param string $dateTime Date in ISO 8601 format
     * @return Carbon
     */
    protected function parseDate(string $dateTime): Carbon
    {
        return Carbon::parse($dateTime);
    }

    /**
     * Extract only the date without time (YYYY-MM-DD)
     * 
     * @param string $dateTime Date in ISO 8601 format
     * @return string '2024-01-15'
     */
    protected function extractDate(string $dateTime): string
    {
        return Carbon::parse($dateTime)->toDateString();
    }

}
