openstudio::Date RunPeriodControlSpecialDays_Impl::getDate(const std::string& text) const { Date result; YearDescription yd = this->model().getUniqueModelObject<YearDescription>(); /* \note <number>/<number> (month/day) \note <number> <Month> \note <Month> <number> \note <Nth> <Weekday> in <Month) \note Last <WeekDay> in <Month> \note <Month> can be January, February, March, April, May, June, July, August, September, October, November, December \note Months can be the first 3 letters of the month \note <Weekday> can be Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday \note <Nth> can be 1 or 1st, 2 or 2nd, etc. up to 5(?) */ boost::smatch matches; if (boost::regex_search(text, matches, boost::regex("(\\d+)\\s?\\/\\s?(\\d+)"))){ std::string monthString(matches[1].first, matches[1].second); MonthOfYear monthOfYear(boost::lexical_cast<unsigned>(monthString)); std::string dayOfMonthString(matches[2].first, matches[2].second); unsigned dayOfMonth = boost::lexical_cast<unsigned>(dayOfMonthString); result = yd.makeDate(monthOfYear, dayOfMonth); return result; }else if (boost::regex_search(text, matches, boost::regex("(\\d+)\\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|January|February|March|April|May|June|July|August|September|October|November|December)", boost::regex::icase))){ std::string dayOfMonthString(matches[1].first, matches[1].second); unsigned dayOfMonth = boost::lexical_cast<unsigned>(dayOfMonthString); std::string monthString(matches[2].first, matches[2].second); result = yd.makeDate(monthOfYear(monthString), dayOfMonth); return result; }else if (boost::regex_search(text, matches, boost::regex("(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|January|February|March|April|May|June|July|August|September|October|November|December)\\s+(\\d+)", boost::regex::icase))){ std::string monthString(matches[1].first, matches[1].second); std::string dayOfMonthString(matches[2].first, matches[2].second); unsigned dayOfMonth = boost::lexical_cast<unsigned>(dayOfMonthString); result = yd.makeDate(monthOfYear(monthString), dayOfMonth); return result; }else if (boost::regex_search(text, matches, boost::regex("(1|2|3|4|5|1st|2nd|3rd|4th|5th|Last)\\s+(Sun|Mon|Tue|Wed|Thu|Fri|Sat|Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)\\s+in\\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|January|February|March|April|May|June|July|August|September|October|November|December)", boost::regex::icase))){ std::string nthString(matches[1].first, matches[1].second); std::string dayOfWeekString(matches[2].first, matches[2].second); std::string monthString(matches[3].first, matches[3].second); result = yd.makeDate(nthDayOfWeekInMonth(nthString), dayOfWeek(dayOfWeekString), monthOfYear(monthString)); return result; } LOG_AND_THROW("Could not determine date for startDate = '" << text << "'"); return Date(); }
std::vector<openstudio::Date> ScheduleRule_Impl::specificDates() const { YearDescription yd = this->model().getUniqueModelObject<model::YearDescription>(); std::vector<openstudio::Date> result; BOOST_FOREACH(const ModelExtensibleGroup& group,castVector<ModelExtensibleGroup>(extensibleGroups())) { OptionalInt month = group.getInt(0); BOOST_ASSERT(month); OptionalInt day = group.getInt(1); BOOST_ASSERT(day); result.push_back(yd.makeDate(MonthOfYear(*month), *day)); }
boost::optional<openstudio::Date> ScheduleRule_Impl::endDate() const { boost::optional<openstudio::Date> result; boost::optional<std::string> dateSpecificationType = this->getString(OS_Schedule_RuleFields::DateSpecificationType, true); BOOST_ASSERT(dateSpecificationType); if (istringEqual("DateRange", *dateSpecificationType)){ boost::optional<int> endMonth = this->getInt(OS_Schedule_RuleFields::EndMonth, true); BOOST_ASSERT(endMonth); boost::optional<int> endDay = this->getInt(OS_Schedule_RuleFields::EndDay, true); BOOST_ASSERT(endDay); YearDescription yd = this->model().getUniqueModelObject<model::YearDescription>(); result = yd.makeDate(MonthOfYear(*endMonth), *endDay); } return result; }
std::vector<openstudio::Date> ScheduleYear_Impl::dates() const { std::vector<openstudio::Date> result; YearDescription yd = this->model().getUniqueModelObject<YearDescription>(); for (const ModelExtensibleGroup& group : castVector<ModelExtensibleGroup>(this->extensibleGroups())) { OptionalUnsigned month = group.getUnsigned(0, true); OptionalUnsigned day = group.getUnsigned(1, true); if (month && day){ result.push_back(yd.makeDate(*month, *day)); }else{ LOG(Error, "Could not read date " << group.groupIndex() << " in " << briefDescription() << "." ); } } return result; }