Skip to content

Commit 222ecb1

Browse files
author
Andrew Daniels
committed
BUG: Fixes issue with offsetting days in days_at_time calendar helper
Offsetting days in the local timezone can cause issues when there are discontinuities, such as at the start of DST. So we instead do this offset in UTC, then localize to the local timezone once dealing with times.
1 parent 5f09203 commit 222ecb1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

zipline/utils/calendars/trading_calendar.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,13 @@ def days_at_time(days, t, tz, day_offset=0):
677677
day_offset : int
678678
The number of days we want to offset @days by
679679
"""
680-
days = DatetimeIndex(days).tz_localize(None).tz_localize(tz)
680+
681+
# Offset days in UTC to avoid discontinuities due to DST, before
682+
# localizing to tz.
683+
days = DatetimeIndex(days).tz_localize(None).tz_localize('UTC')
681684
days_offset = days + DateOffset(day_offset)
685+
days_offset = days_offset.tz_localize(None).tz_localize(tz)
686+
682687
return days_offset.shift(
683688
1, freq=DateOffset(hour=t.hour, minute=t.minute, second=t.second)
684689
).tz_convert('UTC')

0 commit comments

Comments
 (0)