Java tutorial
//package com.java2s; // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. import java.util.Calendar; public class Main { public static Calendar calculateNextAlarmTime(int repetition) { if (repetition == 0) return null; Calendar alarmTime = Calendar.getInstance(); alarmTime.set(Calendar.HOUR_OF_DAY, 20); alarmTime.set(Calendar.MINUTE, 0); alarmTime.set(Calendar.SECOND, 0); int day_of_week = alarmTime.get(Calendar.DAY_OF_WEEK) - 2; if (day_of_week == -1) day_of_week = 6;// sunday repetition &= 0x7f; int rot = (repetition >> (day_of_week + 1)) | (repetition << (7 - day_of_week - 1)); rot &= 0x7f; int ndays = 0; for (ndays = 0; ndays < 7; ndays++) { if ((rot & (1 << ndays)) != 0) break; } alarmTime.add(Calendar.DATE, ndays + 1); return alarmTime; } }