import re,json
from pathlib import Path
def intervals(name):
 out=[]
 for part in Path(name).read_text().split('BEGIN:VEVENT')[1:]:
  uid=re.search(r'UID:(.*?)@',part)[1];a=re.search(r'DTSTART:\d{8}T(\d{4})',part)[1];b=re.search(r'DTEND:\d{8}T(\d{4})',part)[1]
  minute=lambda x:int(x[:2])*60+int(x[2:]);out.append((uid,minute(a),minute(b)))
 return out
before=intervals('before.ics');after=intervals('after-reference.ics')
assert [x for x in before if x[0]in['A','D']]==[x for x in after if x[0]in['A','D']]
for a,b in zip(sorted(after,key=lambda x:x[1]),sorted(after,key=lambda x:x[1])[1:]):assert a[2]<=b[1]
assert next(x[2]-x[1]for x in after if x[0]=='Focus')==90
print('Same A/D UIDs and times; 90-minute Focus; no overlap. ICS uses UTC test calendar.')
