Skip to content

Commit

Permalink
Setting date format for Postgres in an adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
devatreides committed Oct 15, 2021
1 parent 6fda6e4 commit ba62e0c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Adapters/PgsqlAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Flowframe\Trend\Adapters;

use Error;

class PgsqlAdapter extends AbstractAdapter
{
public function format(string $column, string $interval): string
{
$format = match ($interval) {
'minute' => 'YYYY-MM-DD HH24:MI:00',
'hour' => 'YYYY-MM-DD HH24:00:00',
'day' => 'YYYY-MM-DD',
'month' => 'YYYY-MM',
'year' => 'YYYY',
default => throw new Error('Invalid interval.'),
};

return "to_char({$column}, '{$format}')";
}
}

0 comments on commit ba62e0c

Please sign in to comment.