/*!\ingroup time_format
  */
 inline
 std::string
 to_simple_string(time_period tp)
 {
   std::string d1(to_simple_string(tp.begin()));
   std::string d2(to_simple_string(tp.last()));
   return std::string("[" + d1 + "/" + d2 +"]");
 }
Example #2
0
void MistController::ElapseTime(pt::time_period interval, 
                                std::vector<pt::time_duration> &sprinklerOnDurations)
{
   using namespace pt;

   size_t numSprinklers = current_schedule_.zone_data().size();

	if (sprinklerOnDurations.size() < numSprinklers) {
		throw std::logic_error("sprinklerOnDurations is smaller than numSprinklers");
	}

   for (size_t i = 0; i < numSprinklers; ++i) {
      ZoneInfo &zone = current_schedule_.zone_data()[i];
      sprinklerOnDurations[i] = seconds(0);

      while(!zone.OnTimes.empty()) {
         const time_period currOnTime = zone.OnTimes.front();
         
         // Fall through to removing the OnTime if the scheduled
         //    on period is completely before the interval in question.
         if (currOnTime.end() > interval.begin()) {
            // Move onto the next zone if the OnTime comes after the 
            //    interval in question.
            if (currOnTime.begin() < interval.end()) {
               // Fall through to remove the current on time if it is completely
               //    inside the interval in question.
               sprinklerOnDurations[i] += currOnTime.intersection(interval).length();
               if (currOnTime.end() >= interval.end()) {
                  break;
               }
            } else {
               // Don't bother iterating through this zone any more
               break;
            }
         } 
         
         // Remove the current on time
         zone.OnTimes.pop_front();
      }
   }
}