Skip to content

Commit

Permalink
fix(retention): handle timezones with daylight saving transitions cor…
Browse files Browse the repository at this point in the history
…rectly (#17305)
  • Loading branch information
thmsobrmlr authored Sep 6, 2023
1 parent e00caf4 commit bc091c6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion frontend/src/scenes/retention/retentionLineGraphLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const retentionLineGraphLogic = kea<retentionLineGraphLogicType>({
label: cohortRetention.date
? period === 'Hour'
? dayjs(cohortRetention.date).format('MMM D, h A')
: dayjs.utc(cohortRetention.date).format('MMM D')
: dayjs(cohortRetention.date).format('MMM D')
: cohortRetention.label,
data:
retention_reference === 'previous'
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/retention/retentionTableLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const retentionTableLogic = kea<retentionTableLogicType>({
? results[rowIndex].label
: period === 'Hour'
? dayjs(results[rowIndex].date).format('MMM D, h A')
: dayjs.utc(results[rowIndex].date).format('MMM D'),
: dayjs(results[rowIndex].date).format('MMM D'),
// Second column is the first value (which is essentially the total)
results[rowIndex].values[0].count,
// All other columns are rendered as percentage
Expand Down
6 changes: 4 additions & 2 deletions posthog/queries/retention/retention.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ def construct_url(first_day):
for day in range(filter.total_intervals - first_day)
],
"label": "{} {}".format(filter.period, first_day),
"date": (filter.date_from + RetentionFilter.determine_time_delta(first_day, filter.period)[0]).replace(
tzinfo=pytz.timezone(team.timezone)
"date": pytz.timezone(team.timezone).localize(
(filter.date_from + RetentionFilter.determine_time_delta(first_day, filter.period)[0]).replace(
tzinfo=None
)
),
"people_url": construct_url(first_day),
}
Expand Down
3 changes: 2 additions & 1 deletion posthog/queries/test/test_retention.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,8 @@ def test_timezones(self):
["Day 0", "Day 1", "Day 2", "Day 3", "Day 4", "Day 5", "Day 6", "Day 7", "Day 8", "Day 9", "Day 10"],
)

self.assertEqual(result_pacific[0]["date"], datetime(2020, 6, 10, 0, tzinfo=pytz.timezone("US/Pacific")))
self.assertEqual(result_pacific[0]["date"], pytz.timezone("US/Pacific").localize(datetime(2020, 6, 10)))
self.assertEqual(result_pacific[0]["date"].isoformat(), "2020-06-10T00:00:00-07:00")

self.assertEqual(
pluck(result, "values", "count"),
Expand Down

0 comments on commit bc091c6

Please sign in to comment.