I have code that I've put together to identify the exact hour the daylight savings time starts and when it ends. The problem is that I can't catch everything between those particular hours, on those dates, and say that yes it is within daylight savings time. My code for detecting the hours is as follows:
def getDaylightSavings(date, hourEnding):
# daylight saving's time switches
#print date.month, date.isoweekday(), date.day, hourEnding
if (date.month == 3 and date.isoweekday() == 7 and (date.day >= 8 and date.day <= 14) and hourEnding == 3): return 1
if (date.month == 11 and date.isoweekday() == 7 and (date.day >= 1 and date.day <= 7) and hourEnding == 3): return 2
This way I know what time adjustments to use. The problem is that if the time I pass into the function is 3/11/2018 4:00:00
it won't return as daylight savings whereas 3/11/2018 3:00:00
will be detected.
Is there a library I can use for determining daylight savings or something I can do here code-wise that will help?
This question is not a duplicate because I need to determine whether daylight savings time is in effect for any arbitrary time. Please help.