add methods to get icon on article natures
This commit is contained in:
@@ -3,9 +3,10 @@
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use function League\Period\interval_after;
|
||||
use League\Period\Period;
|
||||
|
||||
use function League\Period\interval_after;
|
||||
|
||||
class DateRange
|
||||
{
|
||||
public static function today()
|
||||
@@ -60,9 +61,10 @@ class DateRange
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPeriodsLastMonthWithLabels($nb, $with_actual = true)
|
||||
public static function getPeriodsLastMonthWithLabels($nb, $withActual = true)
|
||||
{
|
||||
$periods = DateRange::PeriodsToCarbon(DateRange::getPeriodsLastMonth($nb, $with_actual));
|
||||
$data = [];
|
||||
$periods = DateRange::PeriodsToCarbon(DateRange::getPeriodsLastMonth($nb, $withActual));
|
||||
$labels = DateRange::getMonthNames($periods);
|
||||
foreach ($labels as $label) {
|
||||
$data[$label] = $periods;
|
||||
@@ -76,13 +78,12 @@ class DateRange
|
||||
return self::getMonthNames(self::PeriodsToCarbon(self::getPeriodsLastMonth(12)));
|
||||
}
|
||||
|
||||
public static function getPeriodsLastMonth($nb = 1, $with_actual = true)
|
||||
public static function getPeriodsLastMonth($nb = 1, $withActual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfMonth() : self::lastMonth();
|
||||
$begin = ($nb == 1) ? $end->copy()->startOfMonth() : $end->copy()->startOfMonth()->subMonth($nb - 1);
|
||||
$t = self::getPeriodsbyMonth($begin, $end);
|
||||
$end = $withActual ? Carbon::now()->endOfMonth() : self::lastMonth();
|
||||
$begin = $nb === 1 ? $end->copy()->startOfMonth() : $end->copy()->startOfMonth()->subMonth($nb - 1);
|
||||
|
||||
return self::getPeriodsbyMonth($begin, $end);
|
||||
return self::getPeriodsByMonth($begin, $end);
|
||||
}
|
||||
|
||||
public static function getMonthNamesByPeriods($periods)
|
||||
@@ -106,20 +107,20 @@ class DateRange
|
||||
return $months;
|
||||
}
|
||||
|
||||
public static function getPeriodsLastWeek($nb = 1, $with_actual = true)
|
||||
public static function getPeriodsLastWeek($nb = 1, $withActual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfWeek() : self::lastWeek();
|
||||
$end = $withActual ? Carbon::now()->endOfWeek() : self::lastWeek();
|
||||
$begin = $end->copy()->subWeek($nb);
|
||||
|
||||
return self::getPeriodsbyWeek($begin, $end);
|
||||
return static::getPeriodsByWeek($begin, $end);
|
||||
}
|
||||
|
||||
public static function getPeriodsLastDay($nb = 1, $with_actual = true)
|
||||
public static function getPeriodsLastDay($nb = 1, $withActual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfDay() : static::lastDay();
|
||||
$end = $withActual ? Carbon::now()->endOfDay() : static::lastDay();
|
||||
$begin = $end->copy()->subDay($nb);
|
||||
|
||||
return self::getPeriodsbyDay($begin, $end);
|
||||
return static::getPeriodsByDay($begin, $end);
|
||||
}
|
||||
|
||||
public static function byDay()
|
||||
@@ -156,6 +157,8 @@ class DateRange
|
||||
case 4:
|
||||
$date = Carbon::now()->subMonth(3)->startOfQuarter();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return [$date, $date->addMonth(6)];
|
||||
@@ -181,32 +184,38 @@ class DateRange
|
||||
return Carbon::now()->subDay()->startOfDay();
|
||||
}
|
||||
|
||||
public static function getPeriodsbyMonth($begin, $end, $interval = 1)
|
||||
public static function getPeriodsByMonth($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval MONTH");
|
||||
return self::getPeriods($begin, $end, "{$interval} MONTH");
|
||||
}
|
||||
|
||||
public static function getPeriodsbyWeek($begin, $end, $interval = 1)
|
||||
public static function getPeriodsByWeek($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval WEEK");
|
||||
return self::getPeriods($begin, $end, "{$interval} WEEK");
|
||||
}
|
||||
|
||||
public static function getPeriodsbyDay($begin, $end, $interval = 1)
|
||||
public static function getPeriodsByDay($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval DAY");
|
||||
return self::getPeriods($begin, $end, "{$interval} DAY");
|
||||
}
|
||||
|
||||
public static function getPeriods($begin, $end, $duration, $interval = 1)
|
||||
public static function getPeriods($begin, $end, $duration)
|
||||
{
|
||||
$period = new Period($begin, $end, $interval);
|
||||
$range = [];
|
||||
$period = new Period($begin, $end);
|
||||
foreach ($period->getDatePeriod($duration) as $day) {
|
||||
$daterange[] = interval_after($day, $duration);
|
||||
$range[] = interval_after($day, $duration);
|
||||
}
|
||||
|
||||
return $daterange;
|
||||
/*
|
||||
foreach ($period->dateRangeForward($duration) as $day) {
|
||||
$daterange[] = interval_after($day, $duration);
|
||||
}
|
||||
*/
|
||||
return $range;
|
||||
}
|
||||
|
||||
public static function PeriodsToCarbon($periods)
|
||||
public static function periodsToCarbon($periods)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($periods as $period) {
|
||||
@@ -216,13 +225,39 @@ class DateRange
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function PeriodToCarbon($period)
|
||||
public static function periodToCarbon($period)
|
||||
{
|
||||
return ['start' => self::DatePointToCarbon($period->getStartDate()), 'end' => self::DatePointToCarbon($period->getEndDate())];
|
||||
return [
|
||||
'start' => self::DatePointToCarbon($period->getStartDate()),
|
||||
'end' => self::DatePointToCarbon($period->getEndDate()),
|
||||
];
|
||||
}
|
||||
|
||||
public static function DatePointToCarbon($date)
|
||||
public static function datePointToCarbon($date)
|
||||
{
|
||||
return Carbon::createFromFormat('Y-m-d H:i:s', $date->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public static function convertPeriod($txt)
|
||||
{
|
||||
return array_values(self::convertDaterange($txt));
|
||||
}
|
||||
|
||||
public static function convertDaterange($txt)
|
||||
{
|
||||
$dates = explode('-', $txt);
|
||||
|
||||
return [
|
||||
'start' => DateTime::convert(trim($dates[0])),
|
||||
'end' => DateTime::convert(trim($dates[1])),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPeriodByLocale($start, $end)
|
||||
{
|
||||
return [
|
||||
'start' => DateTime::convert($start),
|
||||
'end' => DateTime::convert($end),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user