Skip to content

Commit 00b4302

Browse files
mikethemanewdurbin
andauthored
refactor: update all_day detection logic (#2601)
Instead of using a particular resolution on an object, which differs between `datetime.date` and `datetime.datetime` objects, operate on parent class of `datetime` and convert all `dt` to timezone-aware `datetime` values. This is also in accordance to the model field being a `DateTimeField`, so we should always be passing the correctly-created object, instead of a `datetime.date()`, raising `received a naive datetime` warnings. Removes unused constants. Signed-off-by: Mike Fiedler <[email protected]> Co-authored-by: Ee Durbin <[email protected]>
1 parent 18e1d74 commit 00b4302

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

events/importer.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
from .models import EventLocation, Event, OccurringRule
88
from .utils import extract_date_or_datetime
99

10-
DATE_RESOLUTION = timedelta(1)
11-
TIME_RESOLUTION = timedelta(0, 0, 1)
12-
1310
logger = logging.getLogger(__name__)
1411

1512

@@ -31,10 +28,7 @@ def import_occurrence(self, event, event_data):
3128
dt_end = dt_start
3229

3330
# Let's mark those occurrences as 'all-day'.
34-
all_day = (
35-
dt_start.resolution == DATE_RESOLUTION or
36-
dt_end.resolution == DATE_RESOLUTION
37-
)
31+
all_day = dt_end - dt_start >= timedelta(days=1)
3832

3933
defaults = {
4034
'dt_start': dt_start,

events/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def date_to_datetime(date, tzinfo=None):
2121

2222

2323
def extract_date_or_datetime(dt):
24-
if isinstance(dt, datetime.datetime):
24+
if isinstance(dt, datetime.date):
2525
return convert_dt_to_aware(dt)
2626
return dt
2727

0 commit comments

Comments
 (0)