Skip to content

Commit

Permalink
fix(hogql): Fix labels not showing time (#18455)
Browse files Browse the repository at this point in the history
* Add back time if interval hour

* Add test
  • Loading branch information
webjunkie authored Nov 7, 2023
1 parent 61a563a commit fb80cae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
14 changes: 12 additions & 2 deletions posthog/hogql_queries/insights/trends/trends_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit fb80cae

Please sign in to comment.