feat(helper): add DateTimeHelper and regist in composer
This commit is contained in:
parent
0c0f2f2b92
commit
050e65aec7
31
app/Helpers/DateTimeHelpers.php
Normal file
31
app/Helpers/DateTimeHelpers.php
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,7 +3,10 @@
|
|||||||
"name": "laravel/laravel",
|
"name": "laravel/laravel",
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"description": "The skeleton application for the Laravel framework.",
|
"description": "The skeleton application for the Laravel framework.",
|
||||||
"keywords": ["laravel", "framework"],
|
"keywords": [
|
||||||
|
"laravel",
|
||||||
|
"framework"
|
||||||
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.2",
|
"php": "^8.2",
|
||||||
@ -36,7 +39,10 @@
|
|||||||
"App\\": "app/",
|
"App\\": "app/",
|
||||||
"Database\\Factories\\": "database/factories/",
|
"Database\\Factories\\": "database/factories/",
|
||||||
"Database\\Seeders\\": "database/seeders/"
|
"Database\\Seeders\\": "database/seeders/"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"app/Helpers/DateTimeHelpers.php"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user