diff --git a/app/Helpers/DateTimeHelpers.php b/app/Helpers/DateTimeHelpers.php index 2f56937..f2e03d4 100644 --- a/app/Helpers/DateTimeHelpers.php +++ b/app/Helpers/DateTimeHelpers.php @@ -3,28 +3,40 @@ use Carbon\Carbon; if (! function_exists('formatDate')) { - function formatDate(?string $date = null, ?string $format = 'l, d M Y'): string + function formatDate(?string $date = null, ?string $format = 'l, d M Y') { return ! $date ? '-' : Carbon::parse($date)->translatedFormat($format); } } if (! function_exists('formatDateTime')) { - function formatDateTime(string $dateTime): string + function formatDateTime(string $dateTime) { return Carbon::parse($dateTime)->translatedFormat('l, d M Y H:i:s'); } } if (! function_exists('formatDateDash')) { - function formatDateDash(string $date): string + function formatDateDash(string $date) { return Carbon::parse($date)->translatedFormat('Y-m-d'); } } +if (! function_exists('getAge')) { + function getAge(string $birthdate) + { + $birth = Carbon::parse($birthdate); + $now = Carbon::now(); + + $diff = $birth->diff($now); + + return "{$diff->y} tahun {$diff->m} bulan"; + } +} + if (! function_exists('timeAgo')) { - function timeAgo(?string $date = null): string + function timeAgo(?string $date = null) { return ! $date ? '-' : Carbon::parse($date)->diffForHumans(); } diff --git a/app/Helpers/StringHelpers.php b/app/Helpers/StringHelpers.php index 674f299..cb12416 100644 --- a/app/Helpers/StringHelpers.php +++ b/app/Helpers/StringHelpers.php @@ -1,6 +1,7 @@