GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 0 / 1 / 1
Functions: -% 0 / 1 / 1
Branches: -% 0 / 1 / 1

src/utilities/time/Calendar.hpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #ifndef UTILITIES_TIME_CALENDAR_HPP
7 #define UTILITIES_TIME_CALENDAR_HPP
8
9 #include "../UtilitiesAPI.hpp"
10
11 #include "Date.hpp"
12 #include "../core/Macro.hpp"
13 #include "../core/String.hpp"
14 #include "../core/Logger.hpp"
15
16 #include <map>
17
18 namespace openstudio {
19
20 /// Calendar is a description of a year, noting special days like holidays,
21 /// special periods like seasons, and daylight savings time
22 class UTILITIES_API Calendar
23 {
24 private:
25 // private class for storing information about days on the calendar
26 struct CalendarDay
27 {
28 bool isHoliday;
29 std::string name;
30 };
31
32 // map of Date to CalendarDay
33 using MapType = std::map<Date, CalendarDay>;
34
35 public:
36 − REGISTER_LOGGER("utilities.time.Calendar");
37 /// default constructor, uses full assumed year
38 Calendar();
39
40 /// constructor with year, uses full assumed year
41 Calendar(int year);
42
43 /// constructor with start and end dates, [startDate, endDate]
44 Calendar(const Date& startDate, const Date& endDate);
45
46 /// standard daylight savings time, [2nd Sunday in March, 1st Sunday in November)
47 void standardDaylightSavings();
48
49 /// add a standard set of holidays
50 void standardHolidays();
51
52 /// set daylight savings time, [daylightSavingsStart, daylightSavingsEnd)
53 void daylightSavings(const Date& daylightSavingsStart, const Date& daylightSavingsEnd);
54
55 /// add a holiday
56 void addHoliday(const Date& date, const std::string& name);
57
58 /// add a non holiday named day
59 void addNamedDay(const Date& date, const std::string& name);
60
61 /// does the calendar include this date, e.g. are they from the same year
62 bool includesDate(const Date& date) const;
63
64 /// is date within daylight savings
65 bool isDaylightSavings(const Date& date) const;
66
67 /// is date a holiday
68 bool isHoliday(const Date& date) const;
69
70 /// is the date named on the calendar, either holiday or non holiday
71 bool isNamedDay(const Date& date) const;
72
73 /// get the name of date, return empty if not on calendar
74 std::string getName(const Date& date) const;
75
76 /// get the first date in the calendar
77 Date startDate() const;
78
79 /// get the last date in the calendar
80 Date endDate() const;
81
82 private:
83 Date m_startDate;
84 Date m_endDate;
85 MapType m_dateMap;
86 OptionalDate m_daylightSavingsStart;
87 OptionalDate m_daylightSavingsEnd;
88 };
89
90 /// optional Calendar
91 using OptionalCalendar = boost::optional<Calendar>;
92
93 /// vector of Calendar
94 using CalendarVector = std::vector<Calendar>;
95
96 } // namespace openstudio
97
98 #endif //UTILITIES_TIME_CALENDAR_HPP
99