| import calendar | |
| from datetime import datetime | |
| def get_reporting_year(date: datetime, reporting_end_month: int) -> int: | |
| """Calculate reporting year based on the last month of reporting year""" | |
| if date.month <= reporting_end_month: | |
| return date.year | |
| return date.year + 1 | |
| def format_reporting_period(year: int, reporting_month: int) -> str: | |
| """Format the reporting period for a given reporting year""" | |
| end_date = datetime( | |
| year, reporting_month, calendar.monthrange(year, reporting_month)[1] | |
| ) | |
| # If reporting month is December, start date should be January 1st of same year | |
| # Otherwise, start date is the first day of the next month from previous year | |
| if reporting_month == 12: | |
| start_date = datetime(year, 1, 1) | |
| else: | |
| start_date = datetime(year - 1, reporting_month + 1, 1) | |
| return f"{start_date.strftime('%-m/%-d/%y')} - {end_date.strftime('%-m/%-d/%y')}" | |