Player12
An open source football management simulator
Loading...
Searching...
No Matches
GameDateValue Struct Reference

Represents a specific date in the game world. More...

#include <gamedate.h>

Public Member Functions

 GameDateValue (uint16_t y=2025, uint8_t m=7, uint8_t d=1)
 Constructs a GameDateValue.
 
void nextDay ()
 Advances the date by one day.
 
void nextWeek ()
 Advances the date by one week.
 
void nextMonth ()
 Advances the date by one month.
 
GameDateValue operator[] (size_t i) const
 Accesses the date part by index (0=year, 1=month, 2=day).
 
GameDateValue operator+ (size_t days) const
 Adds a specified number of days to the date.
 
GameDateValue operator- (size_t days) const
 Subtracts a specified number of days from the date.
 
bool operator< (const GameDateValue &other) const
 Checks if this date is earlier than another.
 
bool operator== (const GameDateValue &other) const
 Checks if this date is equal to another.
 
std::string toString () const
 Converts the date to a string representation.
 
SeasonPhase checkPhase () const
 Checks the current phase of the season.
 

Static Public Member Functions

static GameDateValue fromString (const std::string &str)
 Parses a date from a string.
 

Public Attributes

uint16_t year
 
uint8_t month
 
uint8_t day
 

Static Private Member Functions

static bool isLeapYear (uint16_t y)
 
static uint8_t daysInMonth (uint8_t m, uint16_t y)
 

Detailed Description

Represents a specific date in the game world.

Constructor & Destructor Documentation

◆ GameDateValue()

GameDateValue::GameDateValue ( uint16_t  y = 2025,
uint8_t  m = 7,
uint8_t  d = 1 
)
inlineexplicit

Constructs a GameDateValue.

Parameters
yYear (default 2025).
mMonth (default 7).
dDay (default 1).

Let's start the game from July first, so that we have the transfer window and some friendlies before starting the championship.

Member Function Documentation

◆ checkPhase()

SeasonPhase GameDateValue::checkPhase ( ) const

Checks the current phase of the season.

Returns
The current SeasonPhase.

◆ daysInMonth()

uint8_t GameDateValue::daysInMonth ( uint8_t  m,
uint16_t  y 
)
staticprivate

◆ fromString()

GameDateValue GameDateValue::fromString ( const std::string &  str)
static

Parses a date from a string.

Parameters
strString representation of the date.
Returns
The parsed GameDateValue.

◆ isLeapYear()

bool GameDateValue::isLeapYear ( uint16_t  y)
staticprivate

Cultural moment, I needed to lookup the formula and this is what I found:

The Gregorian calendar year is approximately 365.2425 days. If we only used the "divisible by 4" rule, we'd have too many leap years and the calendar would drift about 3 days every 400 years.

Seems like you never stop learning when writing code :P

◆ nextDay()

void GameDateValue::nextDay ( )

Advances the date by one day.

◆ nextMonth()

void GameDateValue::nextMonth ( )

Advances the date by one month.

◆ nextWeek()

void GameDateValue::nextWeek ( )

Advances the date by one week.

◆ operator+()

GameDateValue GameDateValue::operator+ ( size_t  days) const

Adds a specified number of days to the date.

Parameters
daysDays to add.
Returns
The new date.

◆ operator-()

GameDateValue GameDateValue::operator- ( size_t  days) const

Subtracts a specified number of days from the date.

Parameters
daysDays to subtract.
Returns
The new date.

◆ operator<()

bool GameDateValue::operator< ( const GameDateValue &  other) const

Checks if this date is earlier than another.

Parameters
otherThe date to compare against.
Returns
True if earlier, false otherwise.

◆ operator==()

bool GameDateValue::operator== ( const GameDateValue &  other) const

Checks if this date is equal to another.

Parameters
otherThe date to compare against.
Returns
True if equal, false otherwise.

◆ operator[]()

GameDateValue GameDateValue::operator[] ( size_t  i) const

Accesses the date part by index (0=year, 1=month, 2=day).

Parameters
iIndex.
Returns
The corresponding part of the date.

◆ toString()

std::string GameDateValue::toString ( ) const

Converts the date to a string representation.

Returns
String representation of the date.

Member Data Documentation

◆ day

uint8_t GameDateValue::day

◆ month

uint8_t GameDateValue::month

◆ year

uint16_t GameDateValue::year

The documentation for this struct was generated from the following files: