From be93436d49c997bc42743ad1692607650bc130b5 Mon Sep 17 00:00:00 2001 From: Jordy van Dortmont Date: Sun, 25 Mar 2018 00:10:14 +0100 Subject: [PATCH] Fix SQLite metric points retrieval datetime --- app/Repositories/Metric/SqliteRepository.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Repositories/Metric/SqliteRepository.php b/app/Repositories/Metric/SqliteRepository.php index 239b17cb..ac05c320 100644 --- a/app/Repositories/Metric/SqliteRepository.php +++ b/app/Repositories/Metric/SqliteRepository.php @@ -37,8 +37,8 @@ class SqliteRepository extends AbstractMetricRepository implements MetricInterfa "FROM {$this->getMetricsTable()} ". "INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id ". "WHERE {$this->getMetricsTable()}.id = :metricId ". - "AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$minutes} minutes') ". - "AND {$this->getMetricPointsTable()}.`created_at` <= datetime('now') ". + "AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', 'localtime', '-{$minutes} minutes') ". + "AND {$this->getMetricPointsTable()}.`created_at` <= datetime('now', 'localtime') ". "GROUP BY strftime('%H', {$this->getMetricPointsTable()}.`created_at`), strftime('%M', {$this->getMetricPointsTable()}.`created_at`) ". "ORDER BY {$this->getMetricPointsTable()}.`created_at`", [ 'metricId' => $metric->id, @@ -61,8 +61,8 @@ class SqliteRepository extends AbstractMetricRepository implements MetricInterfa $points = DB::select("SELECT strftime('%Y-%m-%d %H:00', {$this->getMetricPointsTable()}.`created_at`) AS `key`, {$queryType} ". "FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id ". "WHERE {$this->getMetricsTable()}.id = :metricId ". - "AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$hour} hours') ". - "AND {$this->getMetricPointsTable()}.`created_at` <= datetime('now') ". + "AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', 'localtime', '-{$hour} hours') ". + "AND {$this->getMetricPointsTable()}.`created_at` <= datetime('now', 'localtime') ". "GROUP BY strftime('%H', {$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [ 'metricId' => $metric->id, ]); @@ -84,8 +84,8 @@ class SqliteRepository extends AbstractMetricRepository implements MetricInterfa $points = DB::select("SELECT strftime('%Y-%m-%d', {$this->getMetricPointsTable()}.`created_at`) AS `key`, {$queryType} ". "FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id ". "WHERE {$this->getMetricsTable()}.id = :metricId ". - "AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', '-{$day} days') ". - "AND {$this->getMetricPointsTable()}.`created_at` <= datetime('now') ". + "AND {$this->getMetricPointsTable()}.`created_at` >= datetime('now', 'localtime', '-{$day} days') ". + "AND {$this->getMetricPointsTable()}.`created_at` <= datetime('now', 'localtime') ". "GROUP BY DATE({$this->getMetricPointsTable()}.`created_at`) ". "ORDER BY {$this->getMetricPointsTable()}.`created_at`", [ 'metricId' => $metric->id,