FEATURE: add new helper Date
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace App\Helpers;
|
||||
|
||||
class Date
|
||||
{
|
||||
/**
|
||||
* Print date in configured format
|
||||
*
|
||||
* @param $datestamp
|
||||
* @param bool $withTime
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
public static function date($datestamp, $withTime = true)
|
||||
{
|
||||
$timestamp = strtotime($datestamp);
|
||||
|
||||
if ($timestamp <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$format = $withTime ? config('app.datetime_format') : config('app.date_format');
|
||||
|
||||
return date($format, $timestamp);
|
||||
}
|
||||
|
||||
public static function dateFormatted($format, $datestamp)
|
||||
{
|
||||
$timestamp = strtotime($datestamp);
|
||||
|
||||
if ($timestamp <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return date($format, $timestamp);
|
||||
}
|
||||
|
||||
public static function monthName($datestamp) {
|
||||
$timestamp = strtotime($datestamp);
|
||||
|
||||
if ($timestamp <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$months = [
|
||||
trans('common.months.january'),
|
||||
trans('common.months.february'),
|
||||
trans('common.months.march'),
|
||||
trans('common.months.april'),
|
||||
trans('common.months.may'),
|
||||
trans('common.months.june'),
|
||||
trans('common.months.july'),
|
||||
trans('common.months.august'),
|
||||
trans('common.months.semptember'),
|
||||
trans('common.months.october'),
|
||||
trans('common.months.november'),
|
||||
trans('common.months.december'),
|
||||
];
|
||||
|
||||
$monthNumber = date('n', $timestamp);
|
||||
|
||||
return $months[$monthNumber - 1];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user