Code Repositories xandikos / 51ff636
Check for non-None rather than just presence. Jelmer Vernooń≥ 22 days ago
1 changed file(s) with 59 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
231231
232232
233233 def apply_time_range_vevent(start, end, comp, tzify):
234 if 'DTSTART' not in comp:
234 dtstart = comp.get('DTSTART')
235 if not dtstart:
235236 raise MissingProperty('DTSTART')
236237
237 if not (end > tzify(comp['DTSTART'].dt)):
238 if not (end > tzify(dtstart.dt)):
238239 return False
239240
240 if 'DTEND' in comp:
241 if tzify(comp['DTEND'].dt) < tzify(comp['DTSTART'].dt):
241 dtend = comp.get('DTEND')
242 if dtend:
243 if tzify(dtend.dt) < tzify(dtstart.dt):
242244 logging.debug('Invalid DTEND < DTSTART')
243 return (start < tzify(comp['DTEND'].dt))
244
245 if 'DURATION' in comp:
246 return (start < tzify(comp['DTSTART'].dt) + comp['DURATION'].dt)
247 if getattr(comp['DTSTART'].dt, 'time', None) is not None:
248 return (start <= tzify(comp['DTSTART'].dt))
245 return (start < tzify(dtend.dt))
246
247 duration = comp.get('DURATION')
248 if duration:
249 return (start < tzify(dtstart.dt) + duration.dt)
250 if getattr(dtstart.dt, 'time', None) is not None:
251 return (start <= tzify(dtstart.dt))
249252 else:
250 return (start < (tzify(comp['DTSTART'].dt) + datetime.timedelta(1)))
253 return (start < (tzify(dtstart.dt) + datetime.timedelta(1)))
251254
252255
253256 def apply_time_range_vjournal(start, end, comp, tzify):
254 if 'DTSTART' not in comp:
257 dtstart = comp.get('DTSTART')
258 if not dtstart:
259 raise MissingProperty('DTSTART')
260
261 if not (end > tzify(dtstart.dt)):
255262 return False
256263
257 if not (end > tzify(comp['DTSTART'].dt)):
258 return False
259
260 if getattr(comp['DTSTART'].dt, 'time', None) is not None:
261 return (start <= tzify(comp['DTSTART'].dt))
264 if getattr(dtstart.dt, 'time', None) is not None:
265 return (start <= tzify(dtstart.dt))
262266 else:
263 return (start < (tzify(comp['DTSTART'].dt) + datetime.timedelta(1)))
267 return (start < (tzify(dtstart.dt) + datetime.timedelta(1)))
264268
265269
266270 def apply_time_range_vtodo(start, end, comp, tzify):
271 dtstart = comp.get('DTSTART')
272 due = comp.get('DUE')
273
267274 # See RFC4719, section 9.9
268 if 'DTSTART' in comp:
269 if 'DURATION' in comp and 'DUE' not in comp:
275 if dtstart:
276 duration = comp.get('DURATION')
277 if duration and not due:
270278 return (
271 start <= tzify(comp['DTSTART'].dt) + comp['DURATION'].dt and
272 (end > tzify(comp['DTSTART'].dt) or
273 end >= tzify(comp['DTSTART'].dt) + comp['DURATION'].dt)
279 start <= tzify(dtstart.dt) + duration.dt and
280 (end > tzify(dtstart.dt) or
281 end >= tzify(dtstart.dt) + duration.dt)
274282 )
275 elif 'DUE' in comp and 'DURATION' not in comp:
283 elif due and not duration:
276284 return (
277 (start <= tzify(comp['DTSTART'].dt) or
278 start < tzify(comp['DUE'].dt)) and
279 (end > tzify(comp['DTSTART'].dt) or
280 end < tzify(comp['DUE'].dt))
285 (start <= tzify(dtstart.dt) or
286 start < tzify(due.dt)) and
287 (end > tzify(dtstart.dt) or
288 end < tzify(due.dt))
281289 )
282290 else:
283 return (start <= tzify(comp['DTSTART'].dt) and
284 end > tzify(comp['DTSTART'].dt))
285 elif 'DUE' in comp:
286 return start < tzify(comp['DUE'].dt) and end >= tzify(comp['DUE'].dt)
287 elif 'COMPLETED' in comp:
288 if 'CREATED' in comp:
291 return (start <= tzify(dtstart.dt) and
292 end > tzify(dtstart.dt))
293
294 if due:
295 return start < tzify(due.dt) and end >= tzify(due.dt)
296
297 completed = comp.get('COMPLETED')
298 created = comp.get('CREATED')
299 if completed:
300 if created:
289301 return (
290 (start <= tzify(comp['CREATED'].dt) or
291 start <= tzify(comp['COMPLETED'].dt)) and
292 (end >= tzify(comp['CREATED'].dt) or
293 end >= tzify(comp['COMPLETED'].dt))
302 (start <= tzify(created.dt) or
303 start <= tzify(completed.dt)) and
304 (end >= tzify(created.dt) or
305 end >= tzify(completed.dt))
294306 )
295307 else:
296308 return (
297 start <= tzify(comp['COMPLETED'].dt) and
298 end >= tzify(comp['COMPLETED'].dt)
309 start <= tzify(completed.dt) and
310 end >= tzify(completed.dt)
299311 )
300 elif 'CREATED' in comp:
301 return end >= tzify(comp['CREATED'].dt)
312 elif created:
313 return end >= tzify(created.dt)
302314 else:
303315 return True
304316
305317
306318 def apply_time_range_vfreebusy(start, end, comp, tzify):
307 if 'DTSTART' in comp and 'DTEND' in comp:
319 dtstart = comp.get('DTSTART')
320 dtend = comp.get('DTEND')
321 if dtstart and dtend:
308322 return (
309 start <= tzify(comp['DTEND'].dt) and
310 end > tzify(comp['DTEND'].dt)
323 start <= tzify(dtend.dt) and
324 end > tzify(dtstart.dt)
311325 )
312326
313327 for period in comp.get('FREEBUSY', []):