complete story 1.3 with qa test (please not that the previous commit msg was wrong the previous commit was story 1.2
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DateTimeInterface;
|
||||
|
||||
class DateHelper
|
||||
{
|
||||
/**
|
||||
* Format a date according to the current locale.
|
||||
*
|
||||
* Arabic: DD/MM/YYYY
|
||||
* English: MM/DD/YYYY
|
||||
*/
|
||||
public static function formatDate(DateTimeInterface|string|null $date, ?string $locale = null): string
|
||||
{
|
||||
if ($date === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$locale = $locale ?? app()->getLocale();
|
||||
$format = $locale === 'ar' ? 'd/m/Y' : 'm/d/Y';
|
||||
|
||||
return Carbon::parse($date)->format($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a time in 12-hour format with AM/PM.
|
||||
*/
|
||||
public static function formatTime(DateTimeInterface|string|null $time, ?string $locale = null): string
|
||||
{
|
||||
if ($time === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return Carbon::parse($time)->format('g:i A');
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a datetime according to the current locale.
|
||||
*
|
||||
* Arabic: DD/MM/YYYY g:i A
|
||||
* English: MM/DD/YYYY g:i A
|
||||
*/
|
||||
public static function formatDateTime(DateTimeInterface|string|null $datetime, ?string $locale = null): string
|
||||
{
|
||||
if ($datetime === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$locale = $locale ?? app()->getLocale();
|
||||
$format = $locale === 'ar' ? 'd/m/Y g:i A' : 'm/d/Y g:i A';
|
||||
|
||||
return Carbon::parse($datetime)->format($format);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user