Flowframe / laravel-trend

Generate trends for your models. Easily generate charts or reports.
MIT License
671 stars 70 forks source link

Request: add `perWeek` interval #7

Closed sunxyw closed 2 years ago

sunxyw commented 2 years ago

It will be great if you can add support for the perWeek interval.

Larsklopstra commented 2 years ago

Won't be adding this feature myself anytime soon, however, if you can please make a PR!

kurucu commented 2 years ago

This would be easy, but it might be a breaking change.CarbonPeriod accepts text for interval, and would accept e.g. "7 days". But, the way that it's currently coded, "interval" accepts any singular period and then appends it to "1 ". I think the cleanest way to make the change is have the library just accept any loose text and pass it straight to CarbonPeriod.

Then the preset methods would read e.g.:

public function perYear()
{
    $this->interval = '1 year';
}

public function perWeek()
{
    $this->interval = '7 days';
}

Alternative option would be some clunky code e.g. look for an integer in $this->interval and if its not found, then add a 1 in front. That way, interval() would still work with the current interface, and perWeek (like above) could still be implemented.