diff --git a/posthog/hogql_queries/insights/trends/test/test_trends_query_runner.py b/posthog/hogql_queries/insights/trends/test/test_trends_query_runner.py index 88e012672e12d..9344a227c48d4 100644 --- a/posthog/hogql_queries/insights/trends/test/test_trends_query_runner.py +++ b/posthog/hogql_queries/insights/trends/test/test_trends_query_runner.py @@ -204,6 +204,19 @@ def test_trends_query_labels(self): response.results[0]["labels"], ) + def test_trends_query_labels_hour(self): + self._create_test_events() + + response = self._run_trends_query(self.default_date_from, self.default_date_from, IntervalType.hour) + + self.assertEqual( + [ + "9-Jan-2020 00:00", + ], + response.results[0]["labels"], + response.results[0]["labels"], + ) + def test_trends_query_multiple_series(self): self._create_test_events() diff --git a/posthog/hogql_queries/insights/trends/trends_query_runner.py b/posthog/hogql_queries/insights/trends/trends_query_runner.py index 02bae1e35da6f..7518711e73eb8 100644 --- a/posthog/hogql_queries/insights/trends/trends_query_runner.py +++ b/posthog/hogql_queries/insights/trends/trends_query_runner.py @@ -150,8 +150,18 @@ def build_series_response(self, response: HogQLQueryResponse, series: SeriesWith for val in response.results: series_object = { "data": val[1], - "labels": [item.strftime("%-d-%b-%Y") for item in val[0]], # TODO: Add back in hour formatting - "days": [item.strftime("%Y-%m-%d") for item in val[0]], # TODO: Add back in hour formatting + "labels": [ + item.strftime( + "%-d-%b-%Y{}".format(" %H:%M" if self.query_date_range.interval_name == "hour" else "") + ) + for item in val[0] + ], + "days": [ + item.strftime( + "%Y-%m-%d{}".format(" %H:%M:%S" if self.query_date_range.interval_name == "hour" else "") + ) + for item in val[0] + ], "count": float(sum(val[1])), "label": "All events" if self.series_event(series.series) is None else self.series_event(series.series), "filter": self._query_to_filter(),