feat(helper): add DateTimeHelper and regist in composer

This commit is contained in:
Yoga Pangestu 2025-09-19 13:23:36 +07:00
parent 0c0f2f2b92
commit 050e65aec7
2 changed files with 39 additions and 2 deletions

View File

@ -0,0 +1,31 @@
<?php
use Carbon\Carbon;
if (! function_exists('formatDate')) {
function formatDate(?string $date = null, ?string $format = 'l, d M Y'): string
{
return ! $date ? '-' : Carbon::parse($date)->translatedFormat($format);
}
}
if (! function_exists('formatDateTime')) {
function formatDateTime(string $dateTime): string
{
return Carbon::parse($dateTime)->translatedFormat('l, d M Y H:i:s');
}
}
if (! function_exists('formatDateDash')) {
function formatDateDash(string $date): string
{
return Carbon::parse($date)->translatedFormat('Y-m-d');
}
}
if (! function_exists('timeAgo')) {
function timeAgo(?string $date = null): string
{
return ! $date ? '-' : Carbon::parse($date)->diffForHumans();
}
}

View File

@ -3,7 +3,10 @@
"name": "laravel/laravel",
"type": "project",
"description": "The skeleton application for the Laravel framework.",
"keywords": ["laravel", "framework"],
"keywords": [
"laravel",
"framework"
],
"license": "MIT",
"require": {
"php": "^8.2",
@ -36,7 +39,10 @@
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"files": [
"app/Helpers/DateTimeHelpers.php"
]
},
"autoload-dev": {
"psr-4": {