SessionSchedule(Date startTime, Date endTime, int startDay, int endDay) { this.startTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")); this.startTime.setTime(startTime); this.endTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")); this.endTime.setTime(endTime); this.startDay = startDay; this.endDay = endDay; if (startDay > 0 && endDay > 0 && startDay == endDay && endTime.after(startTime)) { endTime = startTime;
SessionSchedule(SessionSettings settings, SessionID sessionID) throws ConfigError, FieldConvertError { boolean startDayPresent = settings.isSetting(sessionID, Session.SETTING_START_DAY); boolean endDayPresent = settings.isSetting(sessionID, Session.SETTING_END_DAY);  if (startDayPresent && !endDayPresent) { throw new ConfigError("Session " + sessionID + ": StartDay used without EndDay"); }  if (endDayPresent && !startDayPresent) { throw new ConfigError("Session " + sessionID + ": EndDay used without StartDay"); }  boolean weeklySession = startDayPresent && endDayPresent;  String startTimeString = settings.getString(sessionID, Session.SETTING_START_TIME); String endTimeString = settings.getString(sessionID, Session.SETTING_END_TIME);  if (settings.isSetting(sessionID, Session.SETTING_TIMEZONE)) { String sessionTimeZoneID = settings.getString(sessionID, Session.SETTING_TIMEZONE); sessionTimeZone = TimeZone.getTimeZone(sessionTimeZoneID); if ("GMT".equals(sessionTimeZone.getID()) && !"GMT".equals(sessionTimeZoneID)) { throw new ConfigError("Unrecognized time zone '" + sessionTimeZoneID + "' for session " + sessionID); } } else { sessionTimeZone = TimeZone.getTimeZone("UTC"); }  Matcher matcher = TIME_PATTERN.matcher(startTimeString); if (!matcher.find()) { throw new ConfigError("Session " + sessionID + ": could not parse start time '" + startTimeString + "'."); } Calendar localTime = SystemTime.getUtcCalendar(); localTime.setTimeZone(sessionTimeZone); localTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(matcher.group(1))); localTime.set(Calendar.MINUTE, Integer.parseInt(matcher.group(2))); localTime.set(Calendar.SECOND, Integer.parseInt(matcher.group(3))); startTime = SystemTime.getUtcCalendar(); startTime.setTime(localTime.getTime()); if (weeklySession) { startDay = getDay(settings, sessionID, Session.SETTING_START_DAY, -1); }  matcher = TIME_PATTERN.matcher(endTimeString); if (!matcher.find()) { throw new ConfigError("Session " + sessionID + ": could not parse end time '" + endTimeString + "'."); } localTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(matcher.group(1))); localTime.set(Calendar.MINUTE, Integer.parseInt(matcher.group(2))); localTime.set(Calendar.SECOND, Integer.parseInt(matcher.group(3))); endTime = SystemTime.getUtcCalendar(); endTime.setTime(localTime.getTime()); if (weeklySession) { endDay = getDay(settings, sessionID, Session.SETTING_END_DAY, -1);
    SessionSchedule(Date startTime, Date endTime, int startDay, int endDay) {        this.startTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"));        this.startTime.setTime(startTime);        this.endTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"));        this.endTime.setTime(endTime);        this.startDay = startDay;        this.endDay = endDay;        if (startDay > 0 && endDay > 0 && startDay == endDay && endTime.after(startTime)) {            endTime = startTime;        }        calendar1.setTimeZone(TimeZone.getTimeZone("UTC"));        calendar2.setTimeZone(TimeZone.getTimeZone("UTC"));    }