Skip to content

Commit

Permalink
Add perWeek() interval (#63)
Browse files Browse the repository at this point in the history
* Add perWeek() interval

* Update PgsqlAdapter for ISO week
  • Loading branch information
marcoboers authored Sep 27, 2024
1 parent c7beab3 commit 5b9a8b4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Adapters/MySqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function format(string $column, string $interval): string
'minute' => '%Y-%m-%d %H:%i:00',
'hour' => '%Y-%m-%d %H:00',
'day' => '%Y-%m-%d',
'week' => '%Y-%u',
'month' => '%Y-%m',
'year' => '%Y',
default => throw new Error('Invalid interval.'),
Expand Down
1 change: 1 addition & 0 deletions src/Adapters/PgsqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function format(string $column, string $interval): string
'minute' => 'YYYY-MM-DD HH24:MI:00',
'hour' => 'YYYY-MM-DD HH24:00:00',
'day' => 'YYYY-MM-DD',
'week' => 'IYYY-IW',
'month' => 'YYYY-MM',
'year' => 'YYYY',
default => throw new Error('Invalid interval.'),
Expand Down
1 change: 1 addition & 0 deletions src/Adapters/SqliteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function format(string $column, string $interval): string
'minute' => '%Y-%m-%d %H:%M:00',
'hour' => '%Y-%m-%d %H:00',
'day' => '%Y-%m-%d',
'week' => '%Y-%W',
'month' => '%Y-%m',
'year' => '%Y',
default => throw new Error('Invalid interval.'),
Expand Down
6 changes: 6 additions & 0 deletions src/Trend.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public function perDay(): self
return $this->interval('day');
}

public function perWeek(): self
{
return $this->interval('week');
}

public function perMonth(): self
{
return $this->interval('month');
Expand Down Expand Up @@ -181,6 +186,7 @@ protected function getCarbonDateFormat(): string
'minute' => 'Y-m-d H:i:00',
'hour' => 'Y-m-d H:00',
'day' => 'Y-m-d',
'week' => 'Y-W',
'month' => 'Y-m',
'year' => 'Y',
default => throw new Error('Invalid interval.'),
Expand Down

0 comments on commit 5b9a8b4

Please sign in to comment.