pops-core  0.9
PoPS (Pest or Pathogen Spread) Model Core C++ library
Public Member Functions | Friends | List of all members
pops::Date Class Reference

Representation and manipulation of a date for the simulation. More...

#include <date.hpp>

Public Member Functions

 Date (const Date &d)
 
 Date (int y, int m, int d)
 
 Date (std::string date)
 Construct date from string. More...
 
Dateoperator= (const Date &)=default
 
void increased_by_days (int num_days)
 Increases the date by the num_days (specified by the user) except on the last timestep of the year, which is increased by num_days plus the number of days left in the year that are less than num_days (e.g. More...
 
void increased_by_week ()
 Increases the date by one week (7 days) except on the last week of the year, which is increased by 8 or 9 days if a leap year. More...
 
void increased_by_month ()
 
void add_day ()
 Adds 1 day to a date. More...
 
void add_days (unsigned n)
 Adds N days to a date. More...
 
void subtract_day ()
 Subtract 1 day from a date. More...
 
void subtract_days (unsigned n)
 Subtract N days from a date. More...
 
Date get_year_end ()
 
Date get_next_year_end ()
 
Date get_last_day_of_week ()
 Assumes we call it on the first day of a week. More...
 
Date get_last_day_of_month ()
 Compute the last day of a month. More...
 
bool is_last_week_of_year ()
 
bool is_last_month_of_year ()
 
bool is_last_day_of_year ()
 
bool is_last_day_of_month ()
 
bool is_last_week_of_month ()
 
bool is_leap_year ()
 
std::string to_string ()
 Returns the current date as a string Will be replaced by C++20 format function. More...
 
int month () const
 
int year () const
 
int day () const
 
int weeks_from_date (Date start)
 Gets number of weeks between start date and this date. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const Date &d)
 
bool operator> (const Date &d1, const Date &d2)
 
bool operator>= (const Date &d1, const Date &d2)
 
bool operator< (const Date &d1, const Date &d2)
 
bool operator<= (const Date &d1, const Date &d2)
 
bool operator== (const Date &d1, const Date &d2)
 
bool operator!= (const Date &d1, const Date &d2)
 

Detailed Description

Representation and manipulation of a date for the simulation.

This class represents and manipulates dates in way which is most useful for the PoPS simulation, i.e. by weeks and months.

Definition at line 32 of file date.hpp.

Constructor & Destructor Documentation

◆ Date() [1/3]

pops::Date::Date ( const Date d)
inline

Definition at line 44 of file date.hpp.

Here is the caller graph for this function:

◆ Date() [2/3]

pops::Date::Date ( int  y,
int  m,
int  d 
)
inline

Definition at line 45 of file date.hpp.

◆ Date() [3/3]

pops::Date::Date ( std::string  date)

Construct date from string.

Checks if months and days are in proper range (ignores Feb leap year), throws invalid_argument exception

Parameters
datein the format YYYY-MM-DD (or Y-M-D)

Definition at line 96 of file date.hpp.

Member Function Documentation

◆ add_day()

void pops::Date::add_day ( )
inline

Adds 1 day to a date.

Definition at line 383 of file date.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_days()

void pops::Date::add_days ( unsigned  n)
inline

Adds N days to a date.

Definition at line 413 of file date.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ day()

int pops::Date::day ( ) const
inline

Definition at line 74 of file date.hpp.

Here is the caller graph for this function:

◆ get_last_day_of_month()

Date pops::Date::get_last_day_of_month ( )
inline

Compute the last day of a month.

Definition at line 144 of file date.hpp.

Here is the call graph for this function:

◆ get_last_day_of_week()

Date pops::Date::get_last_day_of_week ( )
inline

Assumes we call it on the first day of a week.

Weeks always start 1/1. Advances date by week and subtracts 1 day to work correctly at the end of the year.

Definition at line 125 of file date.hpp.

Here is the call graph for this function:

◆ get_next_year_end()

Date pops::Date::get_next_year_end ( )
inline

Definition at line 200 of file date.hpp.

Here is the call graph for this function:

◆ get_year_end()

Date pops::Date::get_year_end ( )
inline

Definition at line 115 of file date.hpp.

Here is the call graph for this function:

◆ increased_by_days()

void pops::Date::increased_by_days ( int  num_days)
inline

Increases the date by the num_days (specified by the user) except on the last timestep of the year, which is increased by num_days plus the number of days left in the year that are less than num_days (e.g.

if the num_days = 28 the last time step is 29 or 30 (if leap year), if num_days = 23 that last time step is 43 or 44 (if leap year) days). This ensures that each year of the forecast starts on January 1st.

Definition at line 287 of file date.hpp.

Here is the call graph for this function:

◆ increased_by_month()

void pops::Date::increased_by_month ( )
inline

Definition at line 362 of file date.hpp.

Here is the call graph for this function:

◆ increased_by_week()

void pops::Date::increased_by_week ( )
inline

Increases the date by one week (7 days) except on the last week of the year, which is increased by 8 or 9 days if a leap year.

This ensures that each year of the forecast starts on January 1st.

Definition at line 327 of file date.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_last_day_of_month()

bool pops::Date::is_last_day_of_month ( )
inline

Definition at line 186 of file date.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_last_day_of_year()

bool pops::Date::is_last_day_of_year ( )
inline

Definition at line 165 of file date.hpp.

◆ is_last_month_of_year()

bool pops::Date::is_last_month_of_year ( )
inline

Definition at line 158 of file date.hpp.

◆ is_last_week_of_month()

bool pops::Date::is_last_week_of_month ( )
inline

Definition at line 172 of file date.hpp.

Here is the call graph for this function:

◆ is_last_week_of_year()

bool pops::Date::is_last_week_of_year ( )
inline

Definition at line 151 of file date.hpp.

◆ is_leap_year()

bool pops::Date::is_leap_year ( )
inline

Definition at line 208 of file date.hpp.

Here is the caller graph for this function:

◆ month()

int pops::Date::month ( ) const
inline

Definition at line 66 of file date.hpp.

Here is the caller graph for this function:

◆ operator=()

Date& pops::Date::operator= ( const Date )
default

◆ subtract_day()

void pops::Date::subtract_day ( )
inline

Subtract 1 day from a date.

Definition at line 398 of file date.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subtract_days()

void pops::Date::subtract_days ( unsigned  n)
inline

Subtract N days from a date.

Definition at line 422 of file date.hpp.

Here is the call graph for this function:

◆ to_string()

std::string pops::Date::to_string ( )
inline

Returns the current date as a string Will be replaced by C++20 format function.

Parameters
Date,currentdate
Returns
String, current date as string

Definition at line 452 of file date.hpp.

◆ weeks_from_date()

int pops::Date::weeks_from_date ( Date  start)
inline

Gets number of weeks between start date and this date.

The parameter is copied and untouched.

Parameters
startdate to start from
Returns
Number of weeks

Definition at line 436 of file date.hpp.

Here is the call graph for this function:

◆ year()

int pops::Date::year ( ) const
inline

Definition at line 70 of file date.hpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const Date d1,
const Date d2 
)
friend

Definition at line 272 of file date.hpp.

◆ operator<

bool operator< ( const Date d1,
const Date d2 
)
friend

Definition at line 240 of file date.hpp.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Date d 
)
friend

Definition at line 109 of file date.hpp.

◆ operator<=

bool operator<= ( const Date d1,
const Date d2 
)
friend

Definition at line 235 of file date.hpp.

◆ operator==

bool operator== ( const Date d1,
const Date d2 
)
friend

Definition at line 265 of file date.hpp.

◆ operator>

bool operator> ( const Date d1,
const Date d2 
)
friend

Definition at line 215 of file date.hpp.

◆ operator>=

bool operator>= ( const Date d1,
const Date d2 
)
friend

Definition at line 260 of file date.hpp.


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