Skip to content

Commit

Permalink
Make getPeriodDateFormat public and getPeriodTimestampFormat protected
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVanderbist committed Mar 4, 2022
1 parent 2a140f0 commit d980012
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to `laravel-stats` will be documented in this file

## 2.0.0 - 2022-02-20
## 2.0.0 - 2022-03-04

### Added

Expand All @@ -14,9 +14,10 @@ All notable changes to `laravel-stats` will be documented in this file
- Extended `StatsQuery` with additional attributes (`StatsQuery::for(StatsEvent::class, ['name' => 'OrderStats'])`)
- Extended `BaseStats` with direct writer access (`OrderStats::writer()` as addition to `OrderStats::query()`)

### Changed (breaks BC)
### Breaking changes

- Changed visibility of `StatsQuery::for($model)->generatePeriods()` from `public` to `protected`
- Changed visibility of `StatsQuery::get()` from `public` to `protected`
- Replaced `StatsQuery::for($model)->getStatistic()` with `StatsQuery::for($model)->getAttributes()`
- Removed `BaseStats->createEvent()`

Expand Down
38 changes: 19 additions & 19 deletions src/StatsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,21 @@ public function getValue(DateTimeInterface $dateTime): int
return $startValue + $differenceSinceSet;
}

public function getPeriodTimestampFormat(): string
public function getAttributes(): array
{
return match ($this->period) {
'year' => 'Y',
'month' => 'Y-m',
'week' => 'oW', // see https://stackoverflow.com/questions/15562270/php-datew-vs-mysql-yearweeknow
'day' => 'Y-m-d',
'hour' => 'Y-m-d H',
'minute' => 'Y-m-d H:i',
};
return $this->attributes;
}

public function getAttributes(): array
public static function getPeriodDateFormat(string $period): string
{
return $this->attributes;
return match ($period) {
'year' => "date_format(created_at,'%Y')",
'month' => "date_format(created_at,'%Y-%m')",
'week' => "yearweek(created_at, 3)", // see https://stackoverflow.com/questions/15562270/php-datew-vs-mysql-yearweeknow
'day' => "date_format(created_at,'%Y-%m-%d')",
'hour' => "date_format(created_at,'%Y-%m-%d %H')",
'minute' => "date_format(created_at,'%Y-%m-%d %H:%i')",
};
}

protected function generatePeriods(): Collection
Expand All @@ -197,15 +197,15 @@ protected function generatePeriods(): Collection
return $data;
}

protected static function getPeriodDateFormat(string $period): string
protected function getPeriodTimestampFormat(): string
{
return match ($period) {
'year' => "date_format(created_at,'%Y')",
'month' => "date_format(created_at,'%Y-%m')",
'week' => "yearweek(created_at, 3)", // see https://stackoverflow.com/questions/15562270/php-datew-vs-mysql-yearweeknow
'day' => "date_format(created_at,'%Y-%m-%d')",
'hour' => "date_format(created_at,'%Y-%m-%d %H')",
'minute' => "date_format(created_at,'%Y-%m-%d %H:%i')",
return match ($this->period) {
'year' => 'Y',
'month' => 'Y-m',
'week' => 'oW', // see https://stackoverflow.com/questions/15562270/php-datew-vs-mysql-yearweeknow
'day' => 'Y-m-d',
'hour' => 'Y-m-d H',
'minute' => 'Y-m-d H:i',
};
}

Expand Down

0 comments on commit d980012

Please sign in to comment.