Modular Megafauna Model 1.1.5
A physiological, dynamic herbivore simulator in C++.
Loading...
Searching...
No Matches
Fauna::Date Class Reference

Helper class to hold an absolute simulation day. More...

#include <date.h>

Public Member Functions

 Date (const unsigned int julian_day, const int year)
 Constructor. More...
 
unsigned int get_day_of_month (bool leap_year=false) const
 Get the day of the month (0 = 1st). More...
 
unsigned int get_julian_day () const
 Day of the year (counting from 0 == Jan 1st). More...
 
unsigned int get_month (const bool leap_year=false) const
 The month (counting from 0 == January). More...
 
int get_year () const
 The year specified in the constructor. More...
 
bool is_successive (const Date &other_date) const
 Whether another Date object represents the following day. More...
 
bool operator== (const Date &rhs) const
 Whether another Date object specifies the same day. More...
 
bool operator!= (const Date &rhs) const
 Whether another Date object specifies a different day. More...
 
bool operator< (const Date &rhs) const
 Whether another date is after this date. More...
 
bool operator> (const Date &rhs) const
 Whether another date is before this date. More...
 

Private Attributes

unsigned int julian_day
 
int year
 

Static Private Attributes

static const std::array< int, 12 > MONTH_LENGTH
 The number of days in each month in a 365-days (non-leap) year. More...
 
static const std::array< int, 12 > FIRST_OF_MONTH
 The Julian day of the first of each month in a 365-days (non-leap) year. More...
 
static const std::array< int, 12 > FIRST_OF_MONTH_LEAP
 The Julian day of the first of each month in a 366-days (leap) year. More...
 

Detailed Description

Helper class to hold an absolute simulation day.

Constructor & Destructor Documentation

◆ Date()

Date::Date ( const unsigned int  julian_day,
const int  year 
)

Constructor.

Parameters
julian_dayDay of the year. A value of zero equals January 1st. A value of 365 is valid because it might be a leap year.
yearAn arbitrary year number. This could be a calendar year or an abstract simulation year counter.
Exceptions
std::invalid_argumentIf julian_day not in interval [0,365].

Member Function Documentation

◆ get_day_of_month()

unsigned int Date::get_day_of_month ( bool  leap_year = false) const

Get the day of the month (0 = 1st).

See also
Note on leap year in get_month().
Parameters
leap_yearIf false, a 365-days year is assumed with February counting 28 days. If true, February has 29 days.
Returns
The day of the month for this date object.

◆ get_julian_day()

unsigned int Fauna::Date::get_julian_day ( ) const
inline

Day of the year (counting from 0 == Jan 1st).

◆ get_month()

unsigned int Date::get_month ( const bool  leap_year = false) const

The month (counting from 0 == January).

If the Julian day is already the 366th day of the year, it is obviously a leap year. In that special case the leap_year parameter is ignored and a leap year is assumed.

Parameters
leap_yearIf false, a 365-days year is assumed with February counting 28 days. If true, February has 29 days.
Returns
Number of the month with 0 for January and 11 for December.

◆ get_year()

int Fauna::Date::get_year ( ) const
inline

The year specified in the constructor.

◆ is_successive()

bool Date::is_successive ( const Date other_date) const

Whether another Date object represents the following day.

This assumes a non-leap year: A Julian day of 364 (0==Jan 1st) can be followed by a Julian day of 0. The last day of a leap year (365) will also be validly followed by day 0.

◆ operator!=()

bool Date::operator!= ( const Date rhs) const

Whether another Date object specifies a different day.

◆ operator<()

bool Date::operator< ( const Date rhs) const

Whether another date is after this date.

◆ operator==()

bool Date::operator== ( const Date rhs) const

Whether another Date object specifies the same day.

◆ operator>()

bool Date::operator> ( const Date rhs) const

Whether another date is before this date.

Member Data Documentation

◆ FIRST_OF_MONTH

const std::array< int, 12 > Date::FIRST_OF_MONTH
staticprivate

The Julian day of the first of each month in a 365-days (non-leap) year.

◆ FIRST_OF_MONTH_LEAP

const std::array< int, 12 > Date::FIRST_OF_MONTH_LEAP
staticprivate
Initial value:
= {
FIRST_OF_MONTH[2] + 1,
FIRST_OF_MONTH[3] + 1,
FIRST_OF_MONTH[4] + 1,
FIRST_OF_MONTH[5] + 1,
FIRST_OF_MONTH[6] + 1,
FIRST_OF_MONTH[7] + 1,
FIRST_OF_MONTH[8] + 1,
FIRST_OF_MONTH[9] + 1,
FIRST_OF_MONTH[10] + 1,
FIRST_OF_MONTH[11] + 1
}
static const std::array< int, 12 > FIRST_OF_MONTH
The Julian day of the first of each month in a 365-days (non-leap) year.
Definition: date.h:84

The Julian day of the first of each month in a 366-days (leap) year.

◆ julian_day

unsigned int Fauna::Date::julian_day
private

◆ MONTH_LENGTH

const std::array< int, 12 > Date::MONTH_LENGTH
staticprivate
Initial value:
= {
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
}

The number of days in each month in a 365-days (non-leap) year.

◆ year

int Fauna::Date::year
private

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