Add preview from father, add new features
This commit is contained in:
@@ -2,58 +2,146 @@
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Carbon\Carbon;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
use App\Repositories\Languages;
|
||||
|
||||
class DateTime
|
||||
{
|
||||
public static function getLang()
|
||||
{
|
||||
return session('locale') ? session('locale') : 'fr';
|
||||
}
|
||||
public static function getMonthName($date, $short = true)
|
||||
{
|
||||
return $short ? self::getUltraShortMonthName($date) : $date->monthName;
|
||||
}
|
||||
|
||||
public static function convert($date)
|
||||
{
|
||||
return $date ? Carbon::createFromFormat('d/m/Y', $date)->isoFormat('Y-MM-DD') : null;
|
||||
}
|
||||
public static function getShortMonthName($date)
|
||||
{
|
||||
return $date->shortMonthName;
|
||||
}
|
||||
|
||||
public static function convertTime($date)
|
||||
{
|
||||
return $date ? Carbon::createFromFormat('d/m/Y H:i', $date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
}
|
||||
public static function getUltraShortMonthName($date)
|
||||
{
|
||||
return strtoupper(Str::ascii(mb_substr($date->shortMonthName,0,3)));
|
||||
}
|
||||
|
||||
public static function toFr($date)
|
||||
{
|
||||
return $date ? Carbon::parse($date)->isoFormat('DD/MM/Y') : null;
|
||||
}
|
||||
public static function getDayName($date, $short = true)
|
||||
{
|
||||
return $short ? $date->shortDayName : $date->dayName;
|
||||
}
|
||||
|
||||
public static function toFrTime($date)
|
||||
{
|
||||
return $date ? Carbon::parse($date)->isoFormat('DD/MM/Y HH:mm:ss') : null;
|
||||
}
|
||||
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 FromDatetimeFr($date)
|
||||
{
|
||||
return $date ? Carbon::createFromFormat('d/m/Y H:i:s', $date) : null;
|
||||
}
|
||||
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 DatetimeToStamp($date)
|
||||
{
|
||||
return $date ? self::FromDatetimeFr($date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
}
|
||||
public static function getDateTime()
|
||||
{
|
||||
return self::DatetimeToLocale(date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public static function DatetimeToDate($date)
|
||||
{
|
||||
return $date ? self::FromDatetimeFr($date)->isoFormat('DD/MM/Y') : null;
|
||||
}
|
||||
public static function getDate()
|
||||
{
|
||||
return self::DateToLocale(date('Y-m-d'));
|
||||
}
|
||||
|
||||
public static function DatetimeToTime($date)
|
||||
{
|
||||
return $date ? self::FromDatetimeFr($date)->isoFormat('HH:mm') : null;
|
||||
}
|
||||
public static function getLang()
|
||||
{
|
||||
return session('locale') ? session('locale') : 'fr';
|
||||
}
|
||||
|
||||
public static function isPast($date)
|
||||
{
|
||||
return self::FromDatetimeFr($date)->isPast();
|
||||
}
|
||||
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()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user