#NEWLINE# def sanitize_timerange( dtstart , dtend , duration = None ) : #NEWLINE# #INDENT# 'return sensible dtstart and end for events that have an invalid or\n    missing DTEND, assuming the event just lasts one day.' #NEWLINE# if ( isinstance ( dtstart , datetime ) and isinstance ( dtend , datetime ) ) : #NEWLINE# #INDENT# if ( dtstart . tzinfo and ( not dtend . tzinfo ) ) : #NEWLINE# #INDENT# logger . warning ( "Event end time has no timezone. Assuming it's the same timezone as the start time" ) #NEWLINE# dtend = dtstart . tzinfo . localize ( dtend ) #NEWLINE# #UNINDENT# if ( ( not dtstart . tzinfo ) and dtend . tzinfo ) : #NEWLINE# #INDENT# logger . warning ( "Event start time has no timezone. Assuming it's the same timezone as the end time" ) #NEWLINE# dtstart = dtend . tzinfo . localize ( dtstart ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( dtend is None ) and ( duration is None ) ) : #NEWLINE# #INDENT# if isinstance ( dtstart , datetime ) : #NEWLINE# #INDENT# dtstart = dtstart . date ( ) #NEWLINE# #UNINDENT# dtend = ( dtstart + timedelta ( days = 1 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( dtend is not None ) : #NEWLINE# #INDENT# if ( dtend < dtstart ) : #NEWLINE# #INDENT# raise ValueError ( "The event's end time (DTEND) is older than the event's start time (DTSTART)." ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( dtend == dtstart ) : #NEWLINE# #INDENT# dtend += timedelta ( days = 1 ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return ( dtstart , dtend )