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 <miketheman@gmail.com> Co-authored-by: Ee Durbin <ewdurbin@gmail.com>
1 parent 18e1d74 commit 00b4302

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

events/importer.py

Lines changed: 1 addition & 7 deletions
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

Lines changed: 1 addition & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy