add methods to get icon on article natures
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
class DateTime
|
||||
{
|
||||
@@ -28,60 +28,90 @@ class DateTime
|
||||
return $short ? $date->shortDayName : $date->dayName;
|
||||
}
|
||||
|
||||
public static function DatetoLocale($date = null)
|
||||
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 App::currentLocale();
|
||||
// return session('locale') ? session('locale') : 'fr';
|
||||
}
|
||||
|
||||
public static function datetoLocale($date = null)
|
||||
{
|
||||
$format = self::getLocaleFormatDate();
|
||||
if (! is_null($date) && ! empty($date)) {
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
} elseif ($date == 'now') {
|
||||
} elseif ($date === 'now') {
|
||||
$date = today()->format($format);
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
public static function DatetimeToLocale($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') {
|
||||
} elseif ($date === 'now') {
|
||||
$date = now()->format($format);
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
public static function getDateTime()
|
||||
public static function countDaysFrom($date)
|
||||
{
|
||||
return self::DatetimeToLocale(date('Y-m-d H:i:s'));
|
||||
$begin = DateTime::getCarbonTime($date);
|
||||
|
||||
return $begin->diffInDays(now()) + 1;
|
||||
}
|
||||
|
||||
public static function getDate()
|
||||
public static function getCarbonTime($date)
|
||||
{
|
||||
return self::DateToLocale(date('Y-m-d'));
|
||||
$format = self::getLocaleFormatDatetime();
|
||||
if (strlen($date) === 16) {
|
||||
$date .= ':00';
|
||||
}
|
||||
|
||||
return ! empty($date) ? Carbon::createFromFormat($format, $date) : null;
|
||||
}
|
||||
|
||||
public static function getLang()
|
||||
public static function getCarbonDate($date)
|
||||
{
|
||||
return session('locale') ? session('locale') : 'fr';
|
||||
$format = self::getLocaleFormatDate();
|
||||
|
||||
return ! empty($date) ? Carbon::createFromFormat($format, $date) : null;
|
||||
}
|
||||
|
||||
public static function convert($date)
|
||||
{
|
||||
$format = self::getLocaleFormatDate();
|
||||
|
||||
return ! empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD') : null;
|
||||
return ! empty($date) ? self::getCarbonDate($date)->isoFormat('Y-MM-DD') : null;
|
||||
}
|
||||
|
||||
public static function convertTime($date)
|
||||
{
|
||||
$format = self::getLocaleFormatDatetime();
|
||||
if (strlen($date) == 16) {
|
||||
$date .= ':00';
|
||||
}
|
||||
return ! empty($date) ? self::getCarbonTime($date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
}
|
||||
|
||||
return ! empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
public static function toLocale($date)
|
||||
{
|
||||
$format = self::getLocaleFormatDate();
|
||||
|
||||
return ! empty($date) ? Carbon::parse($date)->Format($format) : null;
|
||||
}
|
||||
|
||||
public static function toISO($date)
|
||||
{
|
||||
return ! empty($date) ? Carbon::parse($date)->isoFormat('Y-MM-DD') : null;
|
||||
}
|
||||
|
||||
public static function toFr($date)
|
||||
@@ -97,7 +127,7 @@ class DateTime
|
||||
public static function getYearFromDate($date)
|
||||
{
|
||||
// return date_format(DateTime::convert($signature_date), 'Y');
|
||||
$date = DateTime::convert($date);
|
||||
$date = self::convert($date);
|
||||
$date = date_create($date);
|
||||
|
||||
return date_format($date, 'Y');
|
||||
@@ -118,6 +148,20 @@ class DateTime
|
||||
return $format;
|
||||
}
|
||||
|
||||
public static function checkDateFormat($date)
|
||||
{
|
||||
if (preg_match("/^\d{2}\/\d{2}\/\d{4}$/", $date)) {
|
||||
$day = substr($date, 0, 2);
|
||||
$month = substr($date, 3, 2);
|
||||
$year = substr($date, 6, 4);
|
||||
if (checkdate($month, $day, $year)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getLocaleFormatDatetime()
|
||||
{
|
||||
$locale = self::getLang();
|
||||
@@ -165,7 +209,8 @@ class DateTime
|
||||
return Carbon::parse($date)->isoFormat($format);
|
||||
}
|
||||
|
||||
public static function relativeTime()
|
||||
public static function convertTimeToDate($date)
|
||||
{
|
||||
return substr($date, 0, 10);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user