Skip to content

Commit

Permalink
Merge pull request #34 from CyberEkklesiaOwner/main
Browse files Browse the repository at this point in the history
Configurable user model & new aggregate value
  • Loading branch information
bilfeldt committed May 7, 2024
2 parents 8e052e2 + c7d4195 commit 33b6ee5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ No breaking changes. The only changes are to the development dependencies used f

## Changes

- Add second-level aggregation and make sure that microseconds is always set to 0

### 3.2.0 - 2024-02-28

- Add Laravel 11 compatibility
Expand Down
2 changes: 1 addition & 1 deletion config/route-statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
|--------------------------------------------------------------------------
|
| This setting controls how we should aggregate requests.
| Possible values are: MINUTE, HOUR, DAY, MONTH, YEAR
| Possible values are: SECOND, MINUTE, HOUR, DAY, MONTH, YEAR
|
*/
'aggregate' => env('ROUTE_STATISTICS_AGGREGATE', 'DAY'),
Expand Down
6 changes: 5 additions & 1 deletion src/Models/RouteStatistic.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,14 @@ protected function getDate()
$date = Date::now();
$aggregate = config('route-statistics.aggregate');

if ($aggregate && ! in_array($aggregate, ['YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE'])) {
if ($aggregate && ! in_array($aggregate, ['YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND'])) {
throw new \OutOfBoundsException('Invalid date aggregation');
}

if (in_array($aggregate, ['YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND'])) {
$date->setMicrosecond(0);
}

if (in_array($aggregate, ['YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE'])) {
$date->setSecond(0);
}
Expand Down

0 comments on commit 33b6ee5

Please sign in to comment.