Add ListView.selected_item helper.
[matthijs/upstream/mobilegtd.git] / src / model / tickler.py
1 import re
2 date_regexp = re.compile('(?P<number>\d{1,2})(\D.*)?\Z',re.U)
3 class TickleDirectory:
4     
5     def __init__(self,path):
6         self.path = path
7     def is_obsolete(self):
8         import datetime
9         date = self.date()
10         if not date:
11             # This directory is not a month-day directory
12             return False
13         obsolete = date <= datetime.datetime.now()
14         return obsolete
15     def date(self):
16         import datetime
17         spp = self.path.split(u'/')
18         year = datetime.datetime.now().year
19         try:
20             if len(spp) < 2 or len(spp[0]) == 0:
21                 month_match = date_regexp.match(spp[-1])
22                 if month_match == None:
23                     return None
24                 month = int(month_match.group('number').rstrip(u' \r\n'))
25                 day = 1
26             else:
27                 month_match = date_regexp.match(spp[-2])
28                 day_match = date_regexp.match(spp[-1])
29                 if month_match == None or day_match == None:
30                     return None
31                 month = int(month_match.group('number').rstrip(u' \r\n'))
32                 day = int(day_match.group('number').rstrip(u' \r\n'))
33                 
34                 if len(spp) > 2:
35                     try:
36                         year = int(spp[-3].rstrip(u' \r\n'))
37                     except:
38                         pass
39                                
40                 
41         except ValueError:
42             logger.log(repr(spp))
43         return datetime.datetime(year,month,day)