fix(helpers): menghapus return type, menambahkan method baru getAge dan replaceCurrency

This commit is contained in:
Yoga Pangestu 2025-09-24 19:27:19 +07:00
parent 8211f819b0
commit 80c0a7a67f
2 changed files with 24 additions and 4 deletions

View File

@ -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();
}

View File

@ -1,6 +1,7 @@
<?php
use Illuminate\Support\Number;
use Illuminate\Support\Str;
if (! function_exists('formatCurrency')) {
function formatCurrency(string $value, ?string $format = 'IDR', ?string $locale = 'id_ID', int $precision = 0): string
@ -8,3 +9,10 @@ function formatCurrency(string $value, ?string $format = 'IDR', ?string $locale
return Number::currency($value, $format, $locale, $precision);
}
}
if (! function_exists('replaceCurrency')) {
function replaceCurrency(string $value)
{
return (int) Str::replace('.', '', $value);
}
}