bool Schedule::MatchesTime( const SchedItem& si, Date& now ) { EnEx ee(FL, "Schedule::MatchesTime(const SchedItem& si, Date& now)"); // Are we active? if(si.isActive == 0){ // nope. Bail out early. return false; } // Check to see if today matches the day of week filters. If not, then don't bother // checking the other stuff if(now.DayW() == 0 && si.dowSunday == 0) return false; // It's sunday and we don't run on sundays. if(now.DayW() == 1 && si.dowMonday == 0) return false; // It's monday and we don't run on mondays. if(now.DayW() == 2 && si.dowTuesday == 0) return false; // It's tuesday and we don't run on tuesdays. if(now.DayW() == 3 && si.dowWednesday == 0) return false; // It's wednesday and we don't run on wednesdays. if(now.DayW() == 4 && si.dowThursday == 0) return false; // It's thursday and we don't run on thursdays. if(now.DayW() == 5 && si.dowFriday == 0) return false; // It's friday and we don't run on fridays. if(now.DayW() == 6 && si.dowSaturday == 0) return false; // It's saturday and we don't run on saturdays. // Are we a runEvery, or a runAtTime: if(si.useInterval){ // We are a runEvery. Check our LastRun time: if(si.LastRun.length() == 0){ // We've never been run. Time to get started. DEBUG(FL, "%s: Interval check: si.LastRun.length() == 0 - return true", si.TaskName()); return true; } Date lastRunDate; lastRunDate.SetValue( si.LastRun ); Interval diff = now.operator-(lastRunDate); if( diff.Sec() >= (si.runEvery * 60)){ // runEvery is measured in minutes DEBUG(FL, "%s: Interval check: LastRun(%s) Now(%s) RunEvery(%d) - return true", si.TaskName(), si.LastRun(), now.GetValue(), si.runEvery ); return true; // time to run. } else { DEBUG(FL, "%s: Interval check: LastRun(%s) Now(%s) RunEvery(%d) - return false", si.TaskName(), si.LastRun(), now.GetValue(), si.runEvery ); return false; // not yet. } } else { // We are a runAtTime. Check the time now, vs. the time we are supposed to run. if(si.RunAtTime.length() < 4){ WARN(FL, "Schedule entry %s has an invalid RunAtTime setting.", si.TaskName() ); return false; } twine hours = si.RunAtTime.substr(0, 2); twine mins = si.RunAtTime.substr(2); if(hours.get_int() == now.Hour() && mins.get_int() == now.Min() ){ DEBUG(FL, "%s: RunAtTime check: (%s) Now (%s) - return true", si.TaskName(), si.RunAtTime(), now.GetValue() ); return true; } else { DEBUG(FL, "%s: RunAtTime check: (%s) Now (%s) - return false", si.TaskName(), si.RunAtTime(), now.GetValue() ); return false; } } }