回答ありがとうございます。コンパスの答えは正しかったので、Java で次の実装を作成しました。
public static long nextDate(int day, int hour, int minute) {
// Initialize the Calendar objects
Calendar current = Calendar.getInstance();
Calendar target = Calendar.getInstance();
// Fetch the current day of the week.
// Calendar class weekday indexing starts at 1 for Sunday, 2 for Monday etc.
// Change it to start from zero on Monday continueing to six for Sunday
int today = target.get(Calendar.DAY_OF_WEEK) - 2;
if(today == -1) today = 7;
int difference = -1;
if(today <= day) {
// Target date is this week
difference = day - today;
} else {
// Target date is passed already this week.
// Let's get the date next week
difference = 7 - today + day;
}
// Setting the target hour and minute
target.set(Calendar.HOUR_OF_DAY, hour);
target.set(Calendar.MINUTE, minute);
target.set(Calendar.SECOND, 0);
// If difference == 0 (target day is this day), let's check that the time isn't passed today.
// If it has, set difference = 7 to get the date next week
if(difference == 0 && current.getTimeInMillis() > target.getTimeInMillis()) {
difference = 7;
}
// Adding the days to the target Calendar object
target.add(Calendar.DATE, difference);
// Just for debug
System.out.println(target.getTime());
// Return the next suitable datetime in milliseconds
return target.getTimeInMillis();
}