148 lines
3.6 KiB
PHP
148 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Core;
|
|
|
|
use Illuminate\Support\Str;
|
|
use Carbon\Carbon;
|
|
use Jenssegers\Date\Date;
|
|
|
|
use App\Repositories\Languages;
|
|
|
|
class DateTime
|
|
{
|
|
public static function getMonthName($date, $short = true)
|
|
{
|
|
return $short ? self::getUltraShortMonthName($date) : $date->monthName;
|
|
}
|
|
|
|
public static function getShortMonthName($date)
|
|
{
|
|
return $date->shortMonthName;
|
|
}
|
|
|
|
public static function getUltraShortMonthName($date)
|
|
{
|
|
return strtoupper(Str::ascii(mb_substr($date->shortMonthName, 0, 3)));
|
|
}
|
|
|
|
public static function getDayName($date, $short = true)
|
|
{
|
|
return $short ? $date->shortDayName : $date->dayName;
|
|
}
|
|
|
|
public static function DatetoLocale($date = null)
|
|
{
|
|
$format = self::getLocaleFormatDate();
|
|
if (!is_null($date) && !empty($date)) {
|
|
$date = Carbon::parse($date)->format($format);
|
|
} elseif ($date == 'now') {
|
|
$date = Carbon::now()->format($format);
|
|
}
|
|
return $date;
|
|
}
|
|
|
|
public static function DatetimeToLocale($date = null)
|
|
{
|
|
$format = self::getLocaleFormatDatetime();
|
|
if (!is_null($date) && !empty($date)) {
|
|
$date = Carbon::parse($date)->format($format);
|
|
} elseif ($date == 'now') {
|
|
$date = Carbon::now()->format($format);
|
|
}
|
|
return $date;
|
|
}
|
|
|
|
public static function getDateTime()
|
|
{
|
|
return self::DatetimeToLocale(date('Y-m-d H:i:s'));
|
|
}
|
|
|
|
public static function getDate()
|
|
{
|
|
return self::DateToLocale(date('Y-m-d'));
|
|
}
|
|
|
|
public static function getLang()
|
|
{
|
|
return session('locale') ? session('locale') : 'fr';
|
|
}
|
|
|
|
public static function convert($date)
|
|
{
|
|
$format = self::getLocaleFormatDate();
|
|
return !empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD') : null;
|
|
}
|
|
|
|
public static function convertTime($date)
|
|
{
|
|
$format = self::getLocaleFormatDatetime();
|
|
return !empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
|
}
|
|
|
|
public static function toFr($date)
|
|
{
|
|
return !empty($date) ? Carbon::parse($date)->isoFormat('DD/MM/Y') : null;
|
|
}
|
|
|
|
public static function toFrTime($date)
|
|
{
|
|
return !empty($date) ? Carbon::parse($date)->isoFormat('DD/MM/Y HH:mm:ss') : null;
|
|
}
|
|
|
|
public static function getYearFromDate($date)
|
|
{
|
|
// return date_format(DateTime::convert($signature_date), 'Y');
|
|
$date = DateTime::convert($date);
|
|
$date = date_create($date);
|
|
return date_format($date, 'Y');
|
|
}
|
|
|
|
|
|
public static function getLocaleFormatDate()
|
|
{
|
|
$locale = self::getLang();
|
|
switch ($locale) {
|
|
case 'fr':
|
|
case 'en':
|
|
$format = 'd/m/Y';
|
|
break;
|
|
default:
|
|
$format = 'Y-m-d';
|
|
}
|
|
return $format;
|
|
}
|
|
|
|
public static function getLocaleFormatDatetime()
|
|
{
|
|
$locale = self::getLang();
|
|
switch ($locale) {
|
|
case 'fr':
|
|
case 'en':
|
|
$format = 'd/m/Y H:i:s';
|
|
break;
|
|
default:
|
|
$format = 'Y-m-d H:i:s';
|
|
}
|
|
return $format;
|
|
}
|
|
|
|
public static function getLocaleDateFull($date)
|
|
{
|
|
return Carbon::parse($date)->isoFormat('LLLL');
|
|
}
|
|
|
|
public static function getLocaleDateFullShort($date)
|
|
{
|
|
return Carbon::parse($date)->isoFormat('lll');
|
|
}
|
|
|
|
public static function getLocaleHour($date)
|
|
{
|
|
return Carbon::parse($date)->isoFormat('');
|
|
}
|
|
|
|
public static function relativeTime()
|
|
{
|
|
}
|
|
}
|