wowtoken.app-backend

git clone https://git.emily.sh/wowtoken-app/wowtoken.app-backend.git
Log | Files | Refs | LICENSE

year_month.py (816B)


      1 class YearMonth:
      2     # I really don't like how this class is named and used but
      3     # past me is my own worst enemy and used it to make sorting on Dynamo easier
      4     VALID_YEARS = [2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030]
      5     VALID_MONTHS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
      6     def __init__(self, year: int, month: int):
      7         if year not in YearMonth.VALID_YEARS:
      8             raise ValueError(f'Invalid year: {year}')
      9         if month not in YearMonth.VALID_MONTHS:
     10             raise ValueError(f'Invalid month: {month}')
     11         self._year = year
     12         self._month = month
     13 
     14     @property
     15     def month(self) -> int:
     16         return self._month
     17 
     18     @property
     19     def year(self) -> int:
     20         return self._year
     21 
     22     def __str__(self):
     23         return f'{self._year}-{self._month}'