Add & Fix ranges for Nova Metrics #4285
Unanswered
LTKort
asked this question in
Ideas & Feature Requests
Replies: 1 comment
-
In case anybody else comes here and wonders how to do this, I've found a workaround to add more abbreviated values (eg Last month). Just need to extend this class instead of the Value class: namespace App\Nova\Metrics;
use Carbon\CarbonImmutable;
use Laravel\Nova\Metrics\Value;
abstract class AbstractCustomRangesValue extends Value
{
public function ranges()
{
return [
'MTD' => 'Month to Date',
'LM' => 'Last Month',
'QTD' => 'Quarter to Date',
'YTD' => 'Year to Date',
];
}
protected function currentRange($range, $timezone)
{
if ($range == 'LM') {
return [
CarbonImmutable::now($timezone)->subMonth()->startOfMonth(),
CarbonImmutable::now($timezone)->subMonth()->endOfMonth(),
];
}
return parent::currentRange($range, $timezone);
}
protected function previousRange($range, $timezone)
{
if ($range == 'LM') {
return [
CarbonImmutable::now($timezone)->subMonths(2)->startOfMonth(),
CarbonImmutable::now($timezone)->subMonths(2)->endOfMonth(),
];
}
return parent::currentRange($range, $timezone);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As mentioned in #3996, #4066 and probably more..
The Date ranges are a little outdated / confusing of sorts. Especially the 'To Date' method.
E.g. MTD;
Is this comparing the current Time (05-01-2022 0:00 am - 05-19-2022 2:53 pm)
with last month: (04-01-2022 0:00 am - 04-19-2022 2:53 pm)
or is it compared with: (04-01-2022 0:00 am - 04-30-2022 11:59 pm)?
My solution is to propose a (non breaking) change in the currentRange() and previousRange() functions of /src/Metrics/Value.php.
My proposed solution also adds 3 new options;
MONTH => Start & End of current month, compared to start & end of last month
LAST_MONTH => Start & end of last month, compared to start & end of the month before
TDT => Start of today till current Time, compared to start yesterday till the same time yesterday as today.
It also adds a new parameter (bool $toExactDate) to the previousRange function. Which defaults as false.
The value can be set by different methods. Which I have not considered in this proposal right now. In the example I added a function like the Timezone, which can be set in the Nova config.
I changed the multiple mentions of CarbonImmutable and replaced it with a variable that sets it once. Also changed the Carbon methods to their new / corresponding methods. E.g.
to
Which, combined with the exact option, results in;
Beta Was this translation helpful? Give feedback.
All reactions