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.
This commit is contained in:
Christopher Charbonneau Wells 2017-11-07 06:23:19 -05:00
parent e2733e6b1e
commit 490e07c381
1 changed files with 7 additions and 0 deletions

View File

@ -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 last_end_time = end_time
dates = list(y_df) dates = list(y_df)