Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- def ordinal(n: int) -> str:
- # ...existing code...
- if 10 <= n % 100 <= 20:
- suffix = "th"
- else:
- suffix = {1: "st", 2: "nd", 3: "rd"}.get(n % 10, "th")
- return f"{n}{suffix}"
- class GameCalendar:
- """
- Manage the game calendar and date operations.
- """
- def __init__(self, start_year: int = 1950) -> None:
- self.base_date = datetime.date(start_year, 1, 1)
- self.current_date = self.base_date
- self.recruited_today: bool = False
- @property
- def day(self) -> str:
- return self.current_date.strftime("%A")
- @property
- def date(self) -> int:
- return self.current_date.day
- @property
- def month(self) -> str:
- return self.current_date.strftime("%B")
- @property
- def year(self) -> int:
- return self.current_date.year
- @property
- def ordinal_date(self) -> str:
- return ordinal(self.current_date.day)
- @property
- def day_of_week(self) -> str:
- return self.current_date.strftime("%A")
- @property
- def date_str(self) -> str:
- return f"{self.current_date.strftime('%A')}, {self.ordinal_date} {self.current_date.strftime('%B %Y')}"
- @property
- def numeric_date(self) -> str:
- """
- Return the numeric date as ddmmyyyy.
- For example: 4th January 1950 -> "04011950"
- """
- return self.current_date.strftime("%d%m%Y")
- @property
- def total_days(self) -> int:
- return (self.current_date - self.base_date).days
- def get_date_from_total_days(self, total_days: int) -> str:
- new_date = self.base_date + datetime.timedelta(days=total_days)
- return f"{new_date.strftime('%A')}, {ordinal(new_date.day)} {new_date.strftime('%B %Y')}"
- def next_day(self) -> None:
- self.current_date += datetime.timedelta(days=1)
- self.recruited_today = False
- from pricing import update_daily_prices
- update_daily_prices(self.total_days)
- from deliveries import process_deliveries
- process_deliveries()
- def reset_game_state(self, loaded_game=None) -> None:
- # ...existing code...
- if loaded_game:
- day = loaded_game.get("date", self.base_date.day)
- month = loaded_game.get("month", self.base_date.strftime("%B"))
- year = loaded_game.get("year", self.base_date.year)
- try:
- new_date = datetime.datetime.strptime(f"{day} {month} {year}", "%d %B %Y").date()
- except Exception:
- new_date = self.base_date
- self.current_date = new_date
- self.recruited_today = loaded_game.get("recruited_today", False)
- else:
- self.current_date = self.base_date
- self.recruited_today = False
- game_calendar = GameCalendar()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement