From 490e07c3815205de19e8c0d159dc4e4f3c976428 Mon Sep 17 00:00:00 2001 From: Christopher Charbonneau Wells Date: Tue, 7 Nov 2017 06:23:19 -0500 Subject: [PATCH] Handle utc offset changes (daylight savings) in the Sleep Patterns graph. This change simply adjusts the size of the bar in the graph if an offset change happened between a sleep entry's start and end date. --- reports/graphs/sleep_pattern.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/reports/graphs/sleep_pattern.py b/reports/graphs/sleep_pattern.py index 9d9f3e09..e8913839 100644 --- a/reports/graphs/sleep_pattern.py +++ b/reports/graphs/sleep_pattern.py @@ -95,6 +95,13 @@ def sleep_pattern(instances): ) ) + # Update the previous entry duration if an offset change occurred. + # This can happen when an entry crosses a daylight savings time change. + if start_time.utcoffset() != end_time.utcoffset(): + diff = start_time.utcoffset() - end_time.utcoffset() + duration -= timezone.timedelta(seconds=diff.seconds) + y_df.set_value(df_index - 1, start_date, duration.seconds/60) + last_end_time = end_time dates = list(y_df)