def month_add(value, arg): if isinstance(value, datetime.date): try: arg = int(arg) months = value.month + arg if months <= 12: return datetime.date(year=value.year, month=months, day=value.day) else: years = months//12 months = months % 12 or 12 return datetime.date(year=value.year+years, month=months, day=value.day) except (ValueError, TypeError): pass result = add(value, arg) if isinstance(result, int): return result % 12 or 12 else: return result
def test_add(self): self.assertEqual(add('1', '2'), 3)
def test_add(self): self.assertEqual(add('1', '2'), 3)
def test_add(self): self.assertEqual(add("1", "2"), 3)