diff --git a/apps/payment/models.py b/apps/payment/models.py index d9ed1bc1..0d4d7c25 100644 --- a/apps/payment/models.py +++ b/apps/payment/models.py @@ -129,10 +129,10 @@ class Payment(PolymorphicModel): @classmethod def adjust_date_bounds(cls, date_start=None, date_end=None, is_camp=False): - school_start = date(now().year, 9, 1) - school_end = date(now().year, 5, 31) - camp_start = date(now().year, 6, 1) - camp_end = date(now().year, 8, 31) + school_start = date((date_start or date_end).year, 9, 1) + school_end = date((date_end or date_start).year, 5, 31) + camp_start = date((date_start or date_end).year, 6, 1) + camp_end = date((date_end or date_start).year, 8, 31) if date_start: if is_camp: @@ -153,6 +153,17 @@ class Payment(PolymorphicModel): else: return date_start or date_end + @classmethod + def date_add(cls, date_start, days=0, months=0, is_camp=False): + date_end = arrow.get(date_start + timedelta(days=days), settings.TIME_ZONE).shift( + months=months).date() - timedelta(1) + if months == 1: + if is_camp or (date_start.month == 2 and date_start.day >= 28) or ( + date_start.day == 31 and date_end.day <= 30) \ + or (date_start.month == 1 and date_start.day >= 29 and date_end.day == 28): + date_end = date_start.replace(day=1, month=date_start.month + 1) - timedelta(1) + return date_end + @classmethod def get_date_range(cls, date_start=None, days=0, months=0, is_camp=False): date_start = date_start or now().date() @@ -161,12 +172,9 @@ class Payment(PolymorphicModel): date_start = cls.adjust_date_bounds(date_start=date_start, is_camp=is_camp) if is_camp and date_start.month == 6 and date_start.day > 16: date_start = date_start.replace(month=7, day=1) - date_end = arrow.get(date_start + timedelta(days=days), settings.TIME_ZONE).shift(months=months).date() - timedelta(1) - if months == 1: - if is_camp or (date_start.month == 2 and date_start.day >= 28) or (date_start.day == 31 and date_end.day <= 30) \ - or (date_start.month == 1 and date_start.day >= 29 and date_end.day == 28): - date_end = date_start.replace(day=1, month=date_start.month + 1) - timedelta(1) - date_end = cls.adjust_date_bounds(date_end=date_end, is_camp=is_camp) + date_end = cls.date_add(date_start, days, months, is_camp) + if is_camp: + date_end = cls.adjust_date_bounds(date_end, is_camp=is_camp) return [date_start, date_end] @classmethod diff --git a/project/templates/blocks/banner.html b/project/templates/blocks/banner.html index f047c2cf..f60baa34 100644 --- a/project/templates/blocks/banner.html +++ b/project/templates/blocks/banner.html @@ -1,5 +1,5 @@