def test_monthweekdaydaterange_is_correct(self): """ Test if time from next wednesday morning to next wednesday night is correct :return: None """ params = {'syear': 2015, 'smon': 7, 'smday': 0, 'swday': 1, 'swday_offset': 2, 'eyear': 2015, 'emon': 8, 'emday': 0, 'ewday': 4, 'ewday_offset': 3, 'skip_interval': 0, 'other': ''} caldate = MonthWeekDayDaterange(params) assert caldate.is_correct()
def test_monthweekdaydaterange_start_end_time(self): """ Test MonthWeekDayDaterange.get_start_and_end_time to get start and end date of date range :return: None """ data = {} local_offset = time.timezone - 3600 * time.daylight # TS below are for UTC local_hour_offset = local_offset / 3600 if local_hour_offset >= 0: local_hour_offset = "-%02d" % local_hour_offset else: local_hour_offset = "+%02d" % -local_hour_offset for num in xrange(1, 31): data['2015-07-%02d 01:50:00 %s' % (num, local_hour_offset)] = { 'start': 1436832000 + local_offset, 'end': 1440201599 + local_offset } for num in xrange(1, 21): data['2015-08-%02d 01:50:00 %s' % (num, local_hour_offset)] = { 'start': 1436832000 + local_offset, 'end': 1440201599 + local_offset } for num in xrange(22, 31): data['2015-08-%02d 01:50:00 %s ' % (num, local_hour_offset)] = { 'start': 1468281600 + local_offset, 'end': 1471651199 + local_offset } # 2nd tuesday of July 2015 => 14 # 3rd friday of August 2015 => 21 # next : 2nd tuesday of July 2016 => 12 # next 3rd friday of August 2016 => 19 params = {'syear': 2015, 'smon': 7, 'smday': 0, 'swday': 1, 'swday_offset': 2, 'eyear': 2015, 'emon': 8, 'emday': 0, 'ewday': 4, 'ewday_offset': 3, 'skip_interval': 0, 'other': ''} caldate = MonthWeekDayDaterange(params) for date_now in data: with freeze_time(date_now, tz_offset=0): ret = caldate.get_start_and_end_time() print "* %s" % date_now assert data[date_now]['start'] == ret[0] assert data[date_now]['end'] == ret[1]
def test_monthweekdaydaterange_start_end_time(self): """ Test MonthWeekDayDaterange.get_start_and_end_time to get start and end date of date range :return: None """ data = {} local_offset = time.timezone - 3600 * time.daylight # TS below are for UTC local_hour_offset = local_offset / 3600 if local_hour_offset >= 0: local_hour_offset = "-%02d" % local_hour_offset else: local_hour_offset = "+%02d" % -local_hour_offset for num in range(1, 31): data['2015-07-%02d 01:50:00 %s' % (num, local_hour_offset)] = { 'start': 1436832000 + local_offset, 'end': 1440201599 + local_offset } for num in range(1, 21): data['2015-08-%02d 01:50:00 %s' % (num, local_hour_offset)] = { 'start': 1436832000 + local_offset, 'end': 1440201599 + local_offset } for num in range(22, 31): data['2015-08-%02d 01:50:00 %s ' % (num, local_hour_offset)] = { 'start': 1468281600 + local_offset, 'end': 1471651199 + local_offset } # 2nd tuesday of July 2015 => 14 # 3rd friday of August 2015 => 21 # next : 2nd tuesday of July 2016 => 12 # next 3rd friday of August 2016 => 19 params = {'syear': 2015, 'smon': 7, 'smday': 0, 'swday': 1, 'swday_offset': 2, 'eyear': 2015, 'emon': 8, 'emday': 0, 'ewday': 4, 'ewday_offset': 3, 'skip_interval': 0, 'other': ''} caldate = MonthWeekDayDaterange(params) for date_now in data: with freeze_time(date_now, tz_offset=0): ret = caldate.get_start_and_end_time() print("* %s" % date_now) assert data[date_now]['start'] == ret[0] assert data[date_now]['end'] == ret[1]
def test_MonthWeekDayDaterange_start_end_time(self): data = {} local_offset = time.timezone - 3600 * time.daylight #TS below are for UTC local_hour_offset = local_offset / 3600 if local_hour_offset >= 0: local_hour_offset = "-%02d" % local_hour_offset else: local_hour_offset = "+%02d" % -local_hour_offset for x in xrange(1, 31): data['2015-07-%02d 01:50:00 %s' % (x, local_hour_offset)] = { 'start': 1436832000 + local_offset, 'end': 1440201599 + local_offset } for x in xrange(1, 21): data['2015-08-%02d 01:50:00 %s' % (x, local_hour_offset)] = { 'start': 1436832000 + local_offset, 'end': 1440201599 + local_offset } for x in xrange(22, 31): data['2015-08-%02d 01:50:00 %s ' % (x, local_hour_offset)] = { 'start': 1468281600 + local_offset, 'end': 1471651199 + local_offset } # 2nd tuesday of July 2015 => 14 # 3rd friday of August 2015 => 21 # next : 2nd tuesday of July 2016 => 12 # next 3rd friday of August 2016 => 19 caldate = MonthWeekDayDaterange(2015, 7, 0, 1, 2, 2015, 8, 0, 4, 3, 0, '') for date_now in data: with freeze_time(date_now, tz_offset=0): ret = caldate.get_start_and_end_time() print "* %s" % date_now self.assertEqual(data[date_now]['start'], ret[0]) self.assertEqual(data[date_now]['end'], ret[1])
def resolve_daterange(self, dateranges, entry): # pylint: disable=R0911,R0915,R0912 """ Try to solve dateranges (special cases) :param dateranges: dateranges :type dateranges: list :param entry: property of timeperiod :type entry: string :return: None """ res = re.search( r'(\d{4})-(\d{2})-(\d{2}) - (\d{4})-(\d{2})-(\d{2}) / (\d+)[\s\t]*([0-9:, -]+)', entry) if res is not None: (syear, smon, smday, eyear, emon, emday, skip_interval, other) = res.groups() data = { 'syear': syear, 'smon': smon, 'smday': smday, 'swday': 0, 'swday_offset': 0, 'eyear': eyear, 'emon': emon, 'emday': emday, 'ewday': 0, 'ewday_offset': 0, 'skip_interval': skip_interval, 'other': other } dateranges.append(CalendarDaterange(data)) return res = re.search(r'(\d{4})-(\d{2})-(\d{2}) / (\d+)[\s\t]*([0-9:, -]+)', entry) if res is not None: (syear, smon, smday, skip_interval, other) = res.groups() eyear = syear emon = smon emday = smday data = { 'syear': syear, 'smon': smon, 'smday': smday, 'swday': 0, 'swday_offset': 0, 'eyear': eyear, 'emon': emon, 'emday': emday, 'ewday': 0, 'ewday_offset': 0, 'skip_interval': skip_interval, 'other': other } dateranges.append(CalendarDaterange(data)) return res = re.search( r'(\d{4})-(\d{2})-(\d{2}) - (\d{4})-(\d{2})-(\d{2})[\s\t]*([0-9:, -]+)', entry) if res is not None: (syear, smon, smday, eyear, emon, emday, other) = res.groups() data = { 'syear': syear, 'smon': smon, 'smday': smday, 'swday': 0, 'swday_offset': 0, 'eyear': eyear, 'emon': emon, 'emday': emday, 'ewday': 0, 'ewday_offset': 0, 'skip_interval': 0, 'other': other } dateranges.append(CalendarDaterange(data)) return res = re.search(r'(\d{4})-(\d{2})-(\d{2})[\s\t]*([0-9:, -]+)', entry) if res is not None: (syear, smon, smday, other) = res.groups() eyear = syear emon = smon emday = smday data = { 'syear': syear, 'smon': smon, 'smday': smday, 'swday': 0, 'swday_offset': 0, 'eyear': eyear, 'emon': emon, 'emday': emday, 'ewday': 0, 'ewday_offset': 0, 'skip_interval': 0, 'other': other } dateranges.append(CalendarDaterange(data)) return res = re.search( r'([a-z]*) ([\d-]+) ([a-z]*) - ([a-z]*) ([\d-]+) ([a-z]*) / (\d+)[\s\t]*([0-9:, -]+)', entry) if res is not None: (swday, swday_offset, smon, ewday, ewday_offset, emon, skip_interval, other) = res.groups() smon_id = Daterange.get_month_id(smon) emon_id = Daterange.get_month_id(emon) swday_id = Daterange.get_weekday_id(swday) ewday_id = Daterange.get_weekday_id(ewday) data = { 'syear': 0, 'smon': smon_id, 'smday': 0, 'swday': swday_id, 'swday_offset': swday_offset, 'eyear': 0, 'emon': emon_id, 'emday': 0, 'ewday': ewday_id, 'ewday_offset': ewday_offset, 'skip_interval': skip_interval, 'other': other } dateranges.append(MonthWeekDayDaterange(data)) return res = re.search( r'([a-z]*) ([\d-]+) - ([a-z]*) ([\d-]+) / (\d+)[\s\t]*([0-9:, -]+)', entry) if res is not None: (t00, smday, t01, emday, skip_interval, other) = res.groups() if t00 in Daterange.weekdays and t01 in Daterange.weekdays: swday = Daterange.get_weekday_id(t00) ewday = Daterange.get_weekday_id(t01) swday_offset = smday ewday_offset = emday data = { 'syear': 0, 'smon': 0, 'smday': 0, 'swday': swday, 'swday_offset': swday_offset, 'eyear': 0, 'emon': 0, 'emday': 0, 'ewday': ewday, 'ewday_offset': ewday_offset, 'skip_interval': skip_interval, 'other': other } dateranges.append(WeekDayDaterange(data)) return elif t00 in Daterange.months and t01 in Daterange.months: smon = Daterange.get_month_id(t00) emon = Daterange.get_month_id(t01) data = { 'syear': 0, 'smon': smon, 'smday': smday, 'swday': 0, 'swday_offset': 0, 'eyear': 0, 'emon': emon, 'emday': emday, 'ewday': 0, 'ewday_offset': 0, 'skip_interval': skip_interval, 'other': other } dateranges.append(MonthDateDaterange(data)) return elif t00 == 'day' and t01 == 'day': data = { 'syear': 0, 'smon': 0, 'smday': smday, 'swday': 0, 'swday_offset': 0, 'eyear': 0, 'emon': 0, 'emday': emday, 'ewday': 0, 'ewday_offset': 0, 'skip_interval': skip_interval, 'other': other } dateranges.append(MonthDayDaterange(data)) return res = re.search( r'([a-z]*) ([\d-]+) - ([\d-]+) / (\d+)[\s\t]*([0-9:, -]+)', entry) if res is not None: (t00, smday, emday, skip_interval, other) = res.groups() if t00 in Daterange.weekdays: swday = Daterange.get_weekday_id(t00) swday_offset = smday ewday = swday ewday_offset = emday data = { 'syear': 0, 'smon': 0, 'smday': 0, 'swday': swday, 'swday_offset': swday_offset, 'eyear': 0, 'emon': 0, 'emday': 0, 'ewday': ewday, 'ewday_offset': ewday_offset, 'skip_interval': skip_interval, 'other': other } dateranges.append(WeekDayDaterange(data)) return elif t00 in Daterange.months: smon = Daterange.get_month_id(t00) emon = smon data = { 'syear': 0, 'smon': smon, 'smday': smday, 'swday': 0, 'swday_offset': 0, 'eyear': 0, 'emon': emon, 'emday': emday, 'ewday': 0, 'ewday_offset': 0, 'skip_interval': skip_interval, 'other': other } dateranges.append(MonthDateDaterange(data)) return elif t00 == 'day': data = { 'syear': 0, 'smon': 0, 'smday': smday, 'swday': 0, 'swday_offset': 0, 'eyear': 0, 'emon': 0, 'emday': emday, 'ewday': 0, 'ewday_offset': 0, 'skip_interval': skip_interval, 'other': other } dateranges.append(MonthDayDaterange(data)) return res = re.search( r'([a-z]*) ([\d-]+) ([a-z]*) - ([a-z]*) ([\d-]+) ([a-z]*) [\s\t]*([0-9:, -]+)', entry) if res is not None: (swday, swday_offset, smon, ewday, ewday_offset, emon, other) = res.groups() smon_id = Daterange.get_month_id(smon) emon_id = Daterange.get_month_id(emon) swday_id = Daterange.get_weekday_id(swday) ewday_id = Daterange.get_weekday_id(ewday) data = { 'syear': 0, 'smon': smon_id, 'smday': 0, 'swday': swday_id, 'swday_offset': swday_offset, 'eyear': 0, 'emon': emon_id, 'emday': 0, 'ewday': ewday_id, 'ewday_offset': ewday_offset, 'skip_interval': 0, 'other': other } dateranges.append(MonthWeekDayDaterange(data)) return res = re.search(r'([a-z]*) ([\d-]+) - ([\d-]+)[\s\t]*([0-9:, -]+)', entry) if res is not None: (t00, smday, emday, other) = res.groups() if t00 in Daterange.weekdays: swday = Daterange.get_weekday_id(t00) swday_offset = smday ewday = swday ewday_offset = emday data = { 'syear': 0, 'smon': 0, 'smday': 0, 'swday': swday, 'swday_offset': swday_offset, 'eyear': 0, 'emon': 0, 'emday': 0, 'ewday': ewday, 'ewday_offset': ewday_offset, 'skip_interval': 0, 'other': other } dateranges.append(WeekDayDaterange(data)) return elif t00 in Daterange.months: smon = Daterange.get_month_id(t00) emon = smon data = { 'syear': 0, 'smon': smon, 'smday': smday, 'swday': 0, 'swday_offset': 0, 'eyear': 0, 'emon': emon, 'emday': emday, 'ewday': 0, 'ewday_offset': 0, 'skip_interval': 0, 'other': other } dateranges.append(MonthDateDaterange(data)) return elif t00 == 'day': data = { 'syear': 0, 'smon': 0, 'smday': smday, 'swday': 0, 'swday_offset': 0, 'eyear': 0, 'emon': 0, 'emday': emday, 'ewday': 0, 'ewday_offset': 0, 'skip_interval': 0, 'other': other } dateranges.append(MonthDayDaterange(data)) return res = re.search( r'([a-z]*) ([\d-]+) - ([a-z]*) ([\d-]+)[\s\t]*([0-9:, -]+)', entry) if res is not None: (t00, smday, t01, emday, other) = res.groups() if t00 in Daterange.weekdays and t01 in Daterange.weekdays: swday = Daterange.get_weekday_id(t00) ewday = Daterange.get_weekday_id(t01) swday_offset = smday ewday_offset = emday data = { 'syear': 0, 'smon': 0, 'smday': 0, 'swday': swday, 'swday_offset': swday_offset, 'eyear': 0, 'emon': 0, 'emday': 0, 'ewday': ewday, 'ewday_offset': ewday_offset, 'skip_interval': 0, 'other': other } dateranges.append(WeekDayDaterange(data)) return elif t00 in Daterange.months and t01 in Daterange.months: smon = Daterange.get_month_id(t00) emon = Daterange.get_month_id(t01) data = { 'syear': 0, 'smon': smon, 'smday': smday, 'swday': 0, 'swday_offset': 0, 'eyear': 0, 'emon': emon, 'emday': emday, 'ewday': 0, 'ewday_offset': 0, 'skip_interval': 0, 'other': other } dateranges.append(MonthDateDaterange(data)) return elif t00 == 'day' and t01 == 'day': data = { 'syear': 0, 'smon': 0, 'smday': smday, 'swday': 0, 'swday_offset': 0, 'eyear': 0, 'emon': 0, 'emday': emday, 'ewday': 0, 'ewday_offset': 0, 'skip_interval': 0, 'other': other } dateranges.append(MonthDayDaterange(data)) return res = re.search(r'([a-z]*) ([\d-]+) ([a-z]*)[\s\t]*([0-9:, -]+)', entry) if res is not None: (t00, t02, t01, other) = res.groups() if t00 in Daterange.weekdays and t01 in Daterange.months: swday = Daterange.get_weekday_id(t00) smon = Daterange.get_month_id(t01) emon = smon ewday = swday ewday_offset = t02 data = { 'syear': 0, 'smon': smon, 'smday': 0, 'swday': swday, 'swday_offset': t02, 'eyear': 0, 'emon': emon, 'emday': 0, 'ewday': ewday, 'ewday_offset': ewday_offset, 'skip_interval': 0, 'other': other } dateranges.append(MonthWeekDayDaterange(data)) return if not t01: if t00 in Daterange.weekdays: swday = Daterange.get_weekday_id(t00) swday_offset = t02 ewday = swday ewday_offset = swday_offset data = { 'syear': 0, 'smon': 0, 'smday': 0, 'swday': swday, 'swday_offset': swday_offset, 'eyear': 0, 'emon': 0, 'emday': 0, 'ewday': ewday, 'ewday_offset': ewday_offset, 'skip_interval': 0, 'other': other } dateranges.append(WeekDayDaterange(data)) return if t00 in Daterange.months: smon = Daterange.get_month_id(t00) emon = smon emday = t02 data = { 'syear': 0, 'smon': smon, 'smday': t02, 'swday': 0, 'swday_offset': 0, 'eyear': 0, 'emon': emon, 'emday': emday, 'ewday': 0, 'ewday_offset': 0, 'skip_interval': 0, 'other': other } dateranges.append(MonthDateDaterange(data)) return if t00 == 'day': emday = t02 data = { 'syear': 0, 'smon': 0, 'smday': t02, 'swday': 0, 'swday_offset': 0, 'eyear': 0, 'emon': 0, 'emday': emday, 'ewday': 0, 'ewday_offset': 0, 'skip_interval': 0, 'other': other } dateranges.append(MonthDayDaterange(data)) return res = re.search(r'([a-z]*)[\s\t]+([0-9:, -]+)', entry) if res is not None: (t00, other) = res.groups() if t00 in Daterange.weekdays: day = t00 data = {'day': day, 'other': other} dateranges.append(StandardDaterange(data)) return logger.info("[timeentry::%s] no match for %s", self.get_name(), entry) self.invalid_entries.append(entry)
def resolve_daterange(self, dateranges, entry): """ Try to solve dateranges (special cases) :param dateranges: dateranges :type dateranges: list :param entry: property of timeperiod :type entry: string :return: None """ res = re.search( r'(\d{4})-(\d{2})-(\d{2}) - (\d{4})-(\d{2})-(\d{2}) / (\d+)[\s\t]*([0-9:, -]+)', entry) if res is not None: # print "Good catch 1" (syear, smon, smday, eyear, emon, emday, skip_interval, other) = res.groups() dateranges.append( CalendarDaterange(syear, smon, smday, 0, 0, eyear, emon, emday, 0, 0, skip_interval, other)) return res = re.search(r'(\d{4})-(\d{2})-(\d{2}) / (\d+)[\s\t]*([0-9:, -]+)', entry) if res is not None: # print "Good catch 2" (syear, smon, smday, skip_interval, other) = res.groups() eyear = syear emon = smon emday = smday dateranges.append( CalendarDaterange(syear, smon, smday, 0, 0, eyear, emon, emday, 0, 0, skip_interval, other)) return res = re.search( r'(\d{4})-(\d{2})-(\d{2}) - (\d{4})-(\d{2})-(\d{2})[\s\t]*([0-9:, -]+)', entry) if res is not None: # print "Good catch 3" (syear, smon, smday, eyear, emon, emday, other) = res.groups() dateranges.append( CalendarDaterange(syear, smon, smday, 0, 0, eyear, emon, emday, 0, 0, 0, other)) return res = re.search(r'(\d{4})-(\d{2})-(\d{2})[\s\t]*([0-9:, -]+)', entry) if res is not None: # print "Good catch 4" (syear, smon, smday, other) = res.groups() eyear = syear emon = smon emday = smday dateranges.append( CalendarDaterange(syear, smon, smday, 0, 0, eyear, emon, emday, 0, 0, 0, other)) return res = re.search( r'([a-z]*) ([\d-]+) ([a-z]*) - ([a-z]*) ([\d-]+) ([a-z]*) / (\d+)[\s\t]*([0-9:, -]+)', entry) if res is not None: # print "Good catch 5" (swday, swday_offset, smon, ewday, ewday_offset, emon, skip_interval, other) = res.groups() smon_id = Daterange.get_month_id(smon) emon_id = Daterange.get_month_id(emon) swday_id = Daterange.get_weekday_id(swday) ewday_id = Daterange.get_weekday_id(ewday) dateranges.append( MonthWeekDayDaterange(0, smon_id, 0, swday_id, swday_offset, 0, emon_id, 0, ewday_id, ewday_offset, skip_interval, other)) return res = re.search( r'([a-z]*) ([\d-]+) - ([a-z]*) ([\d-]+) / (\d+)[\s\t]*([0-9:, -]+)', entry) if res is not None: # print "Good catch 6" (t00, smday, t01, emday, skip_interval, other) = res.groups() if t00 in Daterange.weekdays and t01 in Daterange.weekdays: swday = Daterange.get_weekday_id(t00) ewday = Daterange.get_weekday_id(t01) swday_offset = smday ewday_offset = emday dateranges.append( WeekDayDaterange(0, 0, 0, swday, swday_offset, 0, 0, 0, ewday, ewday_offset, skip_interval, other)) return elif t00 in Daterange.months and t01 in Daterange.months: smon = Daterange.get_month_id(t00) emon = Daterange.get_month_id(t01) dateranges.append( MonthDateDaterange(0, smon, smday, 0, 0, 0, emon, emday, 0, 0, skip_interval, other)) return elif t00 == 'day' and t01 == 'day': dateranges.append( MonthDayDaterange(0, 0, smday, 0, 0, 0, 0, emday, 0, 0, skip_interval, other)) return res = re.search( r'([a-z]*) ([\d-]+) - ([\d-]+) / (\d+)[\s\t]*([0-9:, -]+)', entry) if res is not None: # print "Good catch 7" (t00, smday, emday, skip_interval, other) = res.groups() if t00 in Daterange.weekdays: swday = Daterange.get_weekday_id(t00) swday_offset = smday ewday = swday ewday_offset = emday dateranges.append( WeekDayDaterange(0, 0, 0, swday, swday_offset, 0, 0, 0, ewday, ewday_offset, skip_interval, other)) return elif t00 in Daterange.months: smon = Daterange.get_month_id(t00) emon = smon dateranges.append( MonthDateDaterange(0, smon, smday, 0, 0, 0, emon, emday, 0, 0, skip_interval, other)) return elif t00 == 'day': dateranges.append( MonthDayDaterange(0, 0, smday, 0, 0, 0, 0, emday, 0, 0, skip_interval, other)) return res = re.search( r'([a-z]*) ([\d-]+) ([a-z]*) - ([a-z]*) ([\d-]+) ([a-z]*) [\s\t]*([0-9:, -]+)', entry) if res is not None: # print "Good catch 8" (swday, swday_offset, smon, ewday, ewday_offset, emon, other) = res.groups() smon_id = Daterange.get_month_id(smon) emon_id = Daterange.get_month_id(emon) swday_id = Daterange.get_weekday_id(swday) ewday_id = Daterange.get_weekday_id(ewday) dateranges.append( MonthWeekDayDaterange(0, smon_id, 0, swday_id, swday_offset, 0, emon_id, 0, ewday_id, ewday_offset, 0, other)) return res = re.search(r'([a-z]*) ([\d-]+) - ([\d-]+)[\s\t]*([0-9:, -]+)', entry) if res is not None: # print "Good catch 9" (t00, smday, emday, other) = res.groups() if t00 in Daterange.weekdays: swday = Daterange.get_weekday_id(t00) swday_offset = smday ewday = swday ewday_offset = emday dateranges.append( WeekDayDaterange(0, 0, 0, swday, swday_offset, 0, 0, 0, ewday, ewday_offset, 0, other)) return elif t00 in Daterange.months: smon = Daterange.get_month_id(t00) emon = smon dateranges.append( MonthDateDaterange(0, smon, smday, 0, 0, 0, emon, emday, 0, 0, 0, other)) return elif t00 == 'day': dateranges.append( MonthDayDaterange(0, 0, smday, 0, 0, 0, 0, emday, 0, 0, 0, other)) return res = re.search( r'([a-z]*) ([\d-]+) - ([a-z]*) ([\d-]+)[\s\t]*([0-9:, -]+)', entry) if res is not None: # print "Good catch 10" (t00, smday, t01, emday, other) = res.groups() if t00 in Daterange.weekdays and t01 in Daterange.weekdays: swday = Daterange.get_weekday_id(t00) ewday = Daterange.get_weekday_id(t01) swday_offset = smday ewday_offset = emday dateranges.append( WeekDayDaterange(0, 0, 0, swday, swday_offset, 0, 0, 0, ewday, ewday_offset, 0, other)) return elif t00 in Daterange.months and t01 in Daterange.months: smon = Daterange.get_month_id(t00) emon = Daterange.get_month_id(t01) dateranges.append( MonthDateDaterange(0, smon, smday, 0, 0, 0, emon, emday, 0, 0, 0, other)) return elif t00 == 'day' and t01 == 'day': dateranges.append( MonthDayDaterange(0, 0, smday, 0, 0, 0, 0, emday, 0, 0, 0, other)) return res = re.search(r'([a-z]*) ([\d-]+) ([a-z]*)[\s\t]*([0-9:, -]+)', entry) if res is not None: # print "Good catch 11" (t00, t02, t01, other) = res.groups() if t00 in Daterange.weekdays and t01 in Daterange.months: swday = Daterange.get_weekday_id(t00) smon = Daterange.get_month_id(t01) emon = smon ewday = swday ewday_offset = t02 dateranges.append( MonthWeekDayDaterange(0, smon, 0, swday, t02, 0, emon, 0, ewday, ewday_offset, 0, other)) return if not t01: # print "Good catch 12" if t00 in Daterange.weekdays: swday = Daterange.get_weekday_id(t00) swday_offset = t02 ewday = swday ewday_offset = swday_offset dateranges.append( WeekDayDaterange(0, 0, 0, swday, swday_offset, 0, 0, 0, ewday, ewday_offset, 0, other)) return if t00 in Daterange.months: smon = Daterange.get_month_id(t00) emon = smon emday = t02 dateranges.append( MonthDateDaterange(0, smon, t02, 0, 0, 0, emon, emday, 0, 0, 0, other)) return if t00 == 'day': emday = t02 dateranges.append( MonthDayDaterange(0, 0, t02, 0, 0, 0, 0, emday, 0, 0, 0, other)) return res = re.search(r'([a-z]*)[\s\t]+([0-9:, -]+)', entry) if res is not None: # print "Good catch 13" (t00, other) = res.groups() if t00 in Daterange.weekdays: day = t00 dateranges.append(StandardDaterange(day, other)) return logger.info("[timeentry::%s] no match for %s", self.get_name(), entry) self.invalid_entries.append(entry)
def test_monthweekdaydaterange_is_correct(self): # Time from next wednesday morning to next wednesday night caldate = MonthWeekDayDaterange(2015, 7, 0, 1, 2, 2015, 8, 0, 4, 3, 0, '') self.assertTrue(caldate.is_correct())