def test_range_repr_identity(self): date_range2 = Date.convert_from_iso(646, 2, repr(self.date_range)) self.assertEqual(repr(self.date_range), repr(date_range2))
def _get_date(self, id, id2): """ Helper function to create a date object, used in both deletion and creation. """ c.entity = h.fetch_obj(Entity, id, new_id=True) id2 = int(id2) string = request.params.get('string', None) if string is not None: return Date.convert_from_iso(c.entity.ID, id2, string) # process form fields month = request.params.get('month', 0) try: month = None if month == '' else int(month) except: abort(400, "Invalid month.") day = request.params.get('day', 0) try: day = None if day == '' else int(day) except: abort(400, "Invalid day.") year = request.params.get('year', 0) try: year = None if year == '' else int(year) except: abort(400, "Invalid year.") era = request.params.get('era', None) # process range fields range = request.params.get('is_date_range', False) if range: month_end = request.params.get('month_end', 0) try: month_end = None if month_end == '' else int(month_end) except: abort(400, "Invalid month_end.") day_end = request.params.get('day_end', 0) try: day_end = None if day_end == '' else int(day_end) except: abort(400, "Invalid day_end.") year_end = request.params.get('year_end', 0) try: year_end = None if year_end == '' else int(year_end) except: abort(400, "Invalid year_end.") era_end = request.params.get('era_end', None) # process era markers: if year and era == 'bce': year *= -1 if range and year_end and era_end == 'bce': year_end *= -1 # data integrity checks, raise a bad request if failed. # TODO: Make data integrity checks if not year: raise DateException("You must specify a year.") if year and not month and day: raise DateException("You must specify a month.") if range and (year > year_end): raise DateException("Start year must be before end year.") if not range: date = Date(c.entity.ID, id2, year, month, day) date.entity = c.entity else: date = Date(c.entity.ID, id2, year, month, day, year_end, month_end, day_end) date.entity = c.entity return date
def _get_date(self, id, id2): """ Helper function to create a date object, used in both deletion and creation. """ c.entity = h.fetch_obj(Entity, id, new_id=True) id2 = int(id2) string = request.params.get("string", None) if string is not None: return Date.convert_from_iso(c.entity.ID, id2, string) # process form fields month = request.params.get("month", 0) try: month = None if month == "" else int(month) except: abort(400, "Invalid month.") day = request.params.get("day", 0) try: day = None if day == "" else int(day) except: abort(400, "Invalid day.") year = request.params.get("year", 0) try: year = None if year == "" else int(year) except: abort(400, "Invalid year.") era = request.params.get("era", None) # process range fields range = request.params.get("is_date_range", False) if range: month_end = request.params.get("month_end", 0) try: month_end = None if month_end == "" else int(month_end) except: abort(400, "Invalid month_end.") day_end = request.params.get("day_end", 0) try: day_end = None if day_end == "" else int(day_end) except: abort(400, "Invalid day_end.") year_end = request.params.get("year_end", 0) try: year_end = None if year_end == "" else int(year_end) except: abort(400, "Invalid year_end.") era_end = request.params.get("era_end", None) # process era markers: if year and era == "bce": year *= -1 if range and year_end and era_end == "bce": year_end *= -1 # data integrity checks, raise a bad request if failed. # TODO: Make data integrity checks if not year: raise DateException("You must specify a year.") if year and not month and day: raise DateException("You must specify a month.") if range and (year > year_end): raise DateException("Start year must be before end year.") if not range: date = Date(c.entity.ID, id2, year, month, day) date.entity = c.entity else: date = Date(c.entity.ID, id2, year, month, day, year_end, month_end, day_end) date.entity = c.entity return date