From c4d730bb4cc0d74a02bf3b967a487297b2518d8b Mon Sep 17 00:00:00 2001 From: Xiangnan Dang Date: Sat, 6 Jun 2020 00:34:14 -0400 Subject: [PATCH] timeZone for check_daylight_savings_crossover --- accelerometer/summariseEpoch.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/accelerometer/summariseEpoch.py b/accelerometer/summariseEpoch.py index 97325204..d963aae4 100644 --- a/accelerometer/summariseEpoch.py +++ b/accelerometer/summariseEpoch.py @@ -202,6 +202,7 @@ def check_daylight_savings_crossover(e, startTime, endTime, summary, """ daylightSavingsCrossover = 0 + utc_tz = pytz.timezone("UTC") localTime = pytz.timezone(timeZone) # Convert because pytz can error if not using python datetime type startTimeZone = localTime.localize(startTime.to_pydatetime()) @@ -218,11 +219,14 @@ def check_daylight_savings_crossover(e, startTime, endTime, summary, for t in localTime._utc_transition_times: if t>startTime: transition = t + transition = transition - pd.DateOffset(seconds = 1) + transition = utc_tz.localize(transition) + transition = localTime.normalize(transition) + transition = transition.replace(tzinfo = None) + transition = transition + pd.DateOffset(seconds = 1) break # If Autumn crossover time, adjust transition time plus remove 1hr chunk if offset == -1: - # pytz stores dst crossover at 1am, but clocks change at 2am local - transition = transition + pd.DateOffset(hours=1) # Remove last hr before DST cut, which will be subsequently overwritten e = e[(e.index < transition - pd.DateOffset(hours=1)) | (e.index >= transition)]