我在一小時內每16分鐘執行一次作業(3次運行)。這項工作將在16點結束,32點結束,48點結束。它不會蔓延到下一個小時。確定每天運行
這裏是奔跑了兩個小時的窗口樣本:
Run 1:
Thu Jul 04 06:16:00 EDT 2013
Run 2:
Thu Jul 04 06:32:00 EDT 2013
Run 3:
Thu Jul 04 06:48:00 EDT 2013
Run 4:
Thu Jul 04 07:16:00 EDT 2013
Run 5:
Thu Jul 04 07:32:00 EDT 2013
Run 6:
Thu Jul 04 07:48:00 EDT 2013
我的問題是,我需要建立一些目標爲每個作業(並不重要),但最終我還是決定在確定如何許多工作會在當天運行,然後爲每項工作設定一個目標。
我正在研究邏輯,以確定在給定可變啓動時間的情況下,每天工作的運行次數。我試着用一些計算這樣做,但後來最終依靠這片使用日曆代碼弄清楚有多少的運行都留在了天:
public int getRunsLeftInDay(int runIntervalMinutes, int offset){
/*
Offset is when the job starts
Currently runIntervalMinutes = 16 && offset = 16
So start 16 minutes after the hour and run on 16 minute interval
*/
/*
This method is tested returns proper next run date, basically gives
the next 16 past || 32 past || 48 past time that will occur
*/
Date nextRunDt = this.getNextRun(runIntervalMinutes, offset);
//Determine last run per hour
int lastRunMinute = (60/runIntervalMinutes) * runIntervalMinutes;
int runCount = 0;
Calendar cal = Calendar.getInstance();
cal.setTime(nextRunDt);
int currentDay = cal.get(Calendar.DAY_OF_YEAR);
while(cal.get(Calendar.DAY_OF_YEAR) == currentDay){
runCount++; //count first run since calendar is set to nextRunDt
if(cal.get(Calendar.MINUTE) == lastRunMinute){
cal.add(Calendar.HOUR_OF_DAY, 1);
cal.set(Calendar.MINUTE, offset);
}else{
cal.add(Calendar.MINUTE, runIntervalMinutes);
}
}
return runCount;
}
目前我的代碼返回正確的金額運行,但我想探討是否有更好的方法來確定這個值(通過一些日期計算)。
所以基本上我有兩個問題:
1是找到每天運行足夠量的這種方法嗎?
2.我如何使用日期/時間計算來做到這一點?
以爲你在談論板球(每天跑步),錯過了這裏。 – vikingsteve
@vikingsteve蟋蟀不跑。他們啾啾。 –
@vikingsteve每天跑步與蟋蟀有什麼關係? –