def cal_selected(cal): self.eventcount += 1 if self.eventcount == 1: cd = cal.get_date() d = make_time(cd[0], cd[1] + 1, cd[2]) task.date = TaskDate(date=d) finish() self.destroy_cal() else: self.eventcount = 0
def parse_date(text): x = None out = '<?>' date = TaskDate(None) try: x = text.split()[-1] except: return '<?>', text, date x = x.lower() found = True if '/' in x: today = now() try: x = x.split('/') a = make_time(today.year, int(x[0]), int(x[1])) b = make_time(today.year + 1, int(x[0]), int(x[1])) if (a - today).days < -30: out = "%s next year" % b.strftime("%b %d") date = TaskDate(date=b) elif (a - today).days < 0: out = "%s (past)" % a.strftime("%b %d") date = TaskDate(date=a) else: out = a.strftime("%b %d") date = TaskDate(date=a) except: found = False elif len(x) >= 3: o, f = out, found # save in case date match fails verify, out, f_date, found = DATE_MATCH_DICT.get(x[0:3], ['', out, lambda: date, False]) if found and not verify.startswith(x): out, found = o, f # reset on failed date match else: date = f_date() # assign date else: found = False if found: text = ' '.join(text.split()[:-1]) return out, text, date