kopia lustrzana https://github.com/jazzband/icalevents
Keep type() instead of isinstance() for some cases
Since isinstance() deals with inheritance and `datetime.datetime` inherits from `datetime.date` we have no way to distinguish the object type.pull/25/head
rodzic
e3b3356105
commit
682dbe2ff5
|
@ -157,7 +157,7 @@ def create_event(component):
|
|||
event.end = normalize(component.get('dtend').dt)
|
||||
event.summary = str(component.get('summary'))
|
||||
event.description = str(component.get('description'))
|
||||
event.all_day = isinstance(component.get('dtstart').dt, date)
|
||||
event.all_day = type(component.get('dtstart').dt) is date
|
||||
|
||||
return event
|
||||
|
||||
|
@ -169,10 +169,10 @@ def normalize(dt):
|
|||
:param dt: date to normalize
|
||||
:return: date as datetime with timezone
|
||||
"""
|
||||
if isinstance(dt, datetime):
|
||||
pass
|
||||
elif isinstance(dt, date):
|
||||
if type(dt) is date:
|
||||
dt = datetime(dt.year, dt.month, dt.day, 0, 0)
|
||||
elif type(dt) is datetime:
|
||||
pass
|
||||
else:
|
||||
raise ValueError("unknown type %s" % type(dt))
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue