This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
def is_between(dttm, begin, end): | |
begin_check = datetime.combine(dttm.date(), begin) | |
end_check = datetime.combine(dttm.date(), end) | |
# Handle the case where the range crosses midnight (or both times given are | |
# the same, assuming semantically you want this mean a 24-hr range instead | |
# of a null range that always returns False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dateutil import tz | |
def _convert_tz(val, from_tzinfo, to_tzinfo): | |
# Interpret the naive datetime as in the 'from' time zone | |
val = val.replace(tzinfo=from_tzinfo) | |
# Convert to specified time zone | |
val = val.astimezone(to_tzinfo) | |
# Make it a naive datetime again |