I have some kind of an event, that is characterized by the start date and duration.
I need to identify is event already finished for current time or not and how many hours are remained or passed after finish.
And I have a condition to count work hours only between 10AM and 6PM (int work_start = 10, int work_end = 18
).
If now is 9AM it should calculate only yesterday hours as last working hours, and if today is 01PM it should calculate for today that 3 hours are already passed
I've created two methods but the calculation doesn't take into account working hours. How to calculate working time only?
The condition is NOT to use Joda Time. Is it possible?
My two methods are:
public String getProgramEndDate(Date dateStart, int totalDuration){
long durationInMillis = totalDuration * 3600000;
long end = dateStart.getTime() + durationInMillis;
Date date=new Date(end);
SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yyyy");
String endD = df2.format(date);
return endD;
}
public StringBuilder getDaysEndOfTheProgram(Long howMuchTime) {
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH");
long diffHours = howMuchTime / (60 * 60 * 1000) % 8;
long diffDays = howMuchTime / (24 * 60 * 60 * 1000);
StringBuilder sb = new StringBuilder();
sb.append(diffDays + " days, ");
sb.append(diffHours + " hours. ");
return sb;