I'm writing a Java program that automatically generates a certain amount of "units" for the user to do (Actual purpose not important in this question).
I'm struggling to find a good way to determine how many of these "units" to give the user for the next week.
Intentions of the calculation :
- Gives "units" of a specific week
- Calculates units for the week based on the actual day of the week (Mon-Fri)
- Accounts for all of the units that month (Ex. If it is the last week of the month, give all possible units that entire week)
- If estimating, should over-estimate (Due to the program's nature, under-estimating would be far worse.)
- Units cannot be decimals (Hence the cast to int)
Variables I have :
- The amount of "units" to do that month
I have tried to do this in a few different ways, and so far, the best way I have is this :
public static int getRemainingUnitsThisWeek() {
return (int) Math.round(((double) getUnitsThisMonth() / (((30 - (double) DateTime.now().getDayOfMonth()+1) / 7) < 1 ? 1 :
((30 - (double) DateTime.now().getDayOfMonth()+1) / 7))) / (double)DateTime.now().getDayOfWeek());
}
The problem that I end up (specifically, I'm still not happy with how it does it) with is that in the "units" given on the last week of the month is still divided by the day of the week (Which in turn gives you a much lower number each day - even though the user needs to receive all the "units" by the end of the month).
Any questions you might have, just ask!
PS. The library I am using in the DateTime.now() function is joda-time.