25 #include <boost/property_tree/json_parser.hpp> 26 #include <boost/property_tree/ptree.hpp> 33 using boost::property_tree::ptree;
37 Calendar::Calendar(
const ptree& configPt) : m_date(), m_holidays(), m_school_holidays(), m_day(0U)
40 m_date = boost::gregorian::from_simple_string(configPt.get<
string>(
"run.start_date",
"2016-01-01"));
43 InitializeHolidays(configPt);
49 m_date = m_date + boost::gregorian::date_duration(1);
67 const string fName{configPt.get<
string>(
"run.holidays_file",
"holidays_flanders_2017.json")};
69 if (!is_regular_file(fPath)) {
70 throw runtime_error(
string(__func__) +
"Holidays file " + fPath.string() +
" not present.");
72 read_json(fPath.string(), holidaysPt);
76 for (
int i = 1; i < 13; i++) {
77 const auto month = to_string(i);
78 const auto year = holidaysPt.get<
string>(
"year",
"2017");
79 const auto lead = string(year).append(
"-").append(month).append(
"-");
82 for (
const auto& date : holidaysPt.get_child(
"general." + month)) {
83 const auto d = string(lead).append(date.second.get_value<
string>());
84 m_holidays.push_back(boost::gregorian::from_simple_string(d));
88 for (
const auto& date : holidaysPt.get_child(
"school." + month)) {
89 const string d = string(lead).append(date.second.get_value<
string>());
90 m_school_holidays.push_back(boost::gregorian::from_simple_string(d));
100 stringstream ss(day);
101 ss >> get_time(&timeinfo,
"%Y-%m-%d");
102 auto date = date::year{timeinfo.tm_year + 1900} / date::month{
static_cast<unsigned int>(timeinfo.tm_mon + 1)} /
103 date::day{
static_cast<unsigned int>(timeinfo.tm_mday)};
108 : m_date(), m_holidays(), m_school_holidays(), m_day(static_cast<size_t>(0))
110 const string start_date{configPt.get<
string>(
"run.start_date",
"2016-01-01")};
120 m_date =
static_cast<date::year_month_day
>(
static_cast<date::sys_days
>(
m_date) + date::days(1));
128 const string fName{configPt.get<
string>(
"run.holidays_file",
"holidays_flanders_2017.json")};
130 if (!is_regular_file(fPath)) {
131 throw runtime_error(
string(__func__) +
"Holidays file " + fPath.string() +
" not present.");
133 read_json(fPath.string(), holidaysPt);
137 for (
int i = 1; i < 13; i++) {
138 const auto month = to_string(i);
139 const auto year = holidaysPt.get<
string>(
"year",
"2017");
142 for (
const auto& date : holidaysPt.get_child(
"general." + month)) {
145 d << year <<
"-" << setw(2) << setfill(
'0') << month <<
"-" << setw(2) << setfill(
'0')
146 << date.second.get_value<
string>();
151 for (
const auto& date : holidaysPt.get_child(
"school." + month)) {
154 d << year <<
"-" << setw(2) << setfill(
'0') << month <<
"-" << setw(2) << setfill(
'0')
155 << date.second.get_value<
string>();
165 return static_cast<unsigned>(
static_cast<date::year_month_weekday
>(
m_date).weekday());
Calendar(const boost::property_tree::ptree &configPt)
Constructor.
static filesys::path GetDataDir()
/// Return data dir (only relevant when use_install_dirs mode is active)
void InitializeHolidays(const boost::property_tree::ptree &configPt)
std::vector< date::year_month_day > m_school_holidays
Vector of school holidays.
unsigned short int m_day
Current day since start of simulation.
void AdvanceDay()
Advance the simulated calendar by one day.
Utilities for the project.
std::vector< date::year_month_day > m_holidays
Vector of general holidays.
date::year_month_day m_date
Current simulated date.
std::size_t GetDayOfTheWeek() const
Current day of the week (0 (Sunday), ..., 6 (Saturday)) in the simulated calendar.
std::size_t GetYear() const
Current year in the simulated calendar.
std::size_t GetDay() const
Current day of the month in the simulated calendar.
date::year_month_day ConvertFromString(const string &day)
unsigned short int GetSimulationDay() const
Current simulated day since the start of the simulation.
Interface for install directory queries.
Header file for the Calendar class.
Namespace for the simulator and related classes.
std::size_t GetMonth() const
Current month in the simulated calendar.