Java Code Examples for java.util.Calendar#TUESDAY

The following examples show how to use java.util.Calendar#TUESDAY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateUtils.java    From Noyze with Apache License 2.0 6 votes vote down vote up
public static Date ThanksgivingObserved()
{
    int nX;
    int nMonth = 10; // November
    Date dtD;
    int nYear = Calendar.getInstance().get(Calendar.YEAR);
    dtD = NewDate(nYear, nMonth, 1); // November
    Calendar cal = Calendar.getInstance();
    cal.setTime(dtD);
    nX = cal.get(Calendar.DAY_OF_WEEK);
    switch(nX)
    {
        case Calendar.SUNDAY : // Sunday
        case Calendar.MONDAY : // Monday
        case Calendar.TUESDAY : // Tuesday
        case Calendar.WEDNESDAY : // Wednesday
        case Calendar.THURSDAY : // Thursday
            // This would be 26 - nX, but DAY_OF_WEEK starts at SUNDAY (1)
            return NewDate(nYear, nMonth, 27 - nX);
        case Calendar.FRIDAY : // Friday
            return NewDate(nYear, nMonth, 28);
        case Calendar.SATURDAY: // Saturday
            return NewDate(nYear, nMonth, 27);
    }
    return NewDate(nYear, nMonth, 27);
}
 
Example 2
Source File: MeetingCountingDuration.java    From unitime with Apache License 2.0 6 votes vote down vote up
protected int nbrMeetings(DatePattern datePattern, int dayCode) {
	if (datePattern == null) return 0;
	Calendar cal = Calendar.getInstance(Locale.US);
	cal.setTime(datePattern.getStartDate()); cal.setLenient(true);
       String pattern = datePattern.getPattern();
       int ret = 0;
       for (int idx = 0; idx < pattern.length(); idx++) {
       	if (pattern.charAt(idx) == '1') {
       		boolean offered = false;
       		switch (cal.get(Calendar.DAY_OF_WEEK)) {
       			case Calendar.MONDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_MON]) != 0); break;
       			case Calendar.TUESDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_TUE]) != 0); break;
       			case Calendar.WEDNESDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_WED]) != 0); break;
       			case Calendar.THURSDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_THU]) != 0); break;
       			case Calendar.FRIDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_FRI]) != 0); break;
       			case Calendar.SATURDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_SAT]) != 0); break;
       			case Calendar.SUNDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_SUN]) != 0); break;
       		}
       		if (offered) ret++;
       	}
       	cal.add(Calendar.DAY_OF_YEAR, 1);
       }
       return ret;
}
 
Example 3
Source File: SwitchStatement.java    From levelup-java-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void switch_statement_primitive_type () {
	
	int day = 5;
	
	String expression = null;

	switch (day) {
	
		case Calendar.SUNDAY:
		case Calendar.SATURDAY:
			expression = "This is a weekend day";
			break;
			
		case Calendar.MONDAY:
		case Calendar.TUESDAY:
		case Calendar.WEDNESDAY:
		case Calendar.THURSDAY:
		case Calendar.FRIDAY:
			expression = "This is a weekday";
			break;
	}
	
	assertEquals("This is a weekday", expression);
}
 
Example 4
Source File: EventRecurrence.java    From Android-RecurrencePicker with Apache License 2.0 6 votes vote down vote up
/**
 * Converts one of the SU, MO, etc. constants to the Calendar.SUNDAY
 * constants.  btw, I think we should switch to those here too, to
 * get rid of this function, if possible.
 */
public static int day2CalendarDay(int day) {
    switch (day) {
        case SU:
            return Calendar.SUNDAY;
        case MO:
            return Calendar.MONDAY;
        case TU:
            return Calendar.TUESDAY;
        case WE:
            return Calendar.WEDNESDAY;
        case TH:
            return Calendar.THURSDAY;
        case FR:
            return Calendar.FRIDAY;
        case SA:
            return Calendar.SATURDAY;
        default:
            throw new RuntimeException("bad day of week: " + day);
    }
}
 
Example 5
Source File: EventRecurrence.java    From SublimePicker with Apache License 2.0 6 votes vote down vote up
/**
 * Converts one of the Calendar.SUNDAY constants to the SU, MO, etc.
 * constants.  btw, I think we should switch to those here too, to
 * get rid of this function, if possible.
 */
public static int calendarDay2Day(int day) {
    switch (day) {
        case Calendar.SUNDAY:
            return SU;
        case Calendar.MONDAY:
            return MO;
        case Calendar.TUESDAY:
            return TU;
        case Calendar.WEDNESDAY:
            return WE;
        case Calendar.THURSDAY:
            return TH;
        case Calendar.FRIDAY:
            return FR;
        case Calendar.SATURDAY:
            return SA;
        default:
            throw new RuntimeException("bad day of week: " + day);
    }
}
 
Example 6
Source File: AbstractCalendarView.java    From holo-calendar with Apache License 2.0 6 votes vote down vote up
/**
 * Get a human readable name for this day of the week
 *
 * @param dayOfWeek between Calendar.SUNDAY and Calendar.SATURDAY
 * @param resources A resources object which can be retrieved by Context.getResources()
 * @return A name for this day of the week. MON - SUN.
 * @throws IllegalArgumentException Thrown when provided dayOfWeek is invalid
 */
protected String getNameForDay(final int dayOfWeek, final Resources resources) throws IllegalArgumentException {
    switch(dayOfWeek) {
        case Calendar.MONDAY:
            return resources.getString(R.string.lib_header_monday);
        case Calendar.TUESDAY:
            return resources.getString(R.string.lib_header_tuesday);
        case Calendar.WEDNESDAY:
            return resources.getString(R.string.lib_header_wednesday);
        case Calendar.THURSDAY:
            return resources.getString(R.string.lib_header_thursday);
        case Calendar.FRIDAY:
            return resources.getString(R.string.lib_header_friday);
        case Calendar.SATURDAY:
            return resources.getString(R.string.lib_header_saturday);
        case Calendar.SUNDAY:
            return resources.getString(R.string.lib_header_sunday);
        default:
            // unknown day
            throw new IllegalArgumentException("dayOfWeek is not valid. Pick a value between 1 and 7. " +
                    "dayOfWeek: " + dayOfWeek);
    }
}
 
Example 7
Source File: DOWSuggestionHandler.java    From DateTimeSeer with MIT License 5 votes vote down vote up
@Override
public void handle(Context context, String input, String lastToken, SuggestionValue suggestionValue) {
    Matcher matcher = pDow.matcher(input);
    if (matcher.find()) {
        int value = -1;
        if (matcher.group(2) != null) {
            // Monday
            value = Calendar.MONDAY;
        } else if (matcher.group(3) != null) {
            // Friday
            value = Calendar.FRIDAY;
        } else if (matcher.group(4) != null) {
            // Sunday
            value = Calendar.SUNDAY;
        } else if (matcher.group(5) != null) {
            // Tuesday
            value = Calendar.TUESDAY;
        } else if (matcher.group(6) != null) {
            // Wednesday
            value = Calendar.WEDNESDAY;
        } else if (matcher.group(7) != null) {
            // Thursday
            value = Calendar.THURSDAY;
        } else if (matcher.group(8) != null) {
            // Saturday
            value = Calendar.SATURDAY;
        }
        if (value != -1) {
            if (matcher.group(1) != null) {
                suggestionValue.appendSuggestion(SuggestionValue.DAY_OF_WEEK_NEXT, value);
            } else {
                suggestionValue.appendSuggestion(SuggestionValue.DAY_OF_WEEK, value);
            }
        }
    }

    super.handle(context, input, lastToken, suggestionValue);
}
 
Example 8
Source File: TheHubActivity.java    From ToDay with MIT License 5 votes vote down vote up
private void generateDrawerGreeting(NavigationView view) {
    View header=view.getHeaderView(0);
    TextView greeting = (TextView) header.findViewById(R.id.ndrawer_date_greeting);
    String[] array = this.getResources().getStringArray(R.array.drawer_greeting);

    switch(Calendar.getInstance().get(Calendar.DAY_OF_WEEK)){
        case Calendar.MONDAY:
            greeting.setText(array[0]);
            break;

        case Calendar.TUESDAY:
            greeting.setText(array[1]);
            break;

        case Calendar.WEDNESDAY:
            greeting.setText(array[2]);
            break;
        case Calendar.THURSDAY:
            greeting.setText(array[3]);
            break;
        case Calendar.FRIDAY:
            greeting.setText(array[4]);
            break;
        case Calendar.SATURDAY:
            greeting.setText(array[5]);
            break;

        case Calendar.SUNDAY:
            greeting.setText(array[6]);
            break;

        default:
            greeting.setText(array[7]);
            break;

    }

}
 
Example 9
Source File: MeetingCountingDuration.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public List<Date> getDates(int minutes, DatePattern datePattern, int dayCode, int minutesPerMeeting) {
	List<Date> ret = new ArrayList<Date>();
	if (datePattern == null) return ret;
	Calendar cal = Calendar.getInstance(Locale.US);
	cal.setTime(datePattern.getStartDate()); cal.setLenient(true);
       EventDateMapping.Class2EventDateMap class2eventDates = EventDateMapping.getMapping(datePattern.getSession().getUniqueId());
       String pattern = datePattern.getPattern();
       Integer max = getMaxMeetings(minutes, minutesPerMeeting);
       for (int idx = 0; idx < pattern.length(); idx++) {
       	if (pattern.charAt(idx) == '1') {
       		boolean offered = false;
       		switch (cal.get(Calendar.DAY_OF_WEEK)) {
       			case Calendar.MONDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_MON]) != 0); break;
       			case Calendar.TUESDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_TUE]) != 0); break;
       			case Calendar.WEDNESDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_WED]) != 0); break;
       			case Calendar.THURSDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_THU]) != 0); break;
       			case Calendar.FRIDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_FRI]) != 0); break;
       			case Calendar.SATURDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_SAT]) != 0); break;
       			case Calendar.SUNDAY : offered = ((dayCode & Constants.DAY_CODES[Constants.DAY_SUN]) != 0); break;
       		}
       		if (offered) ret.add(class2eventDates.getEventDate(cal.getTime()));
       	}
       	cal.add(Calendar.DAY_OF_YEAR, 1);
       	if (max != null && ret.size() >= max) break;
       }
	return ret;
}
 
Example 10
Source File: WeekWeatherAdapter.java    From privacy-friendly-weather with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBindViewHolder(WeekForecastViewHolder holder, int position) {
    Forecast f = forecastList.get(position);

    setIcon(f.getWeatherID(), holder.weather);
    holder.humidity.setText(StringFormatUtils.formatInt(f.getHumidity(), "%"));

    Calendar c = new GregorianCalendar();
    c.setTime(f.getLocalForecastTime(context));
    int day = c.get(Calendar.DAY_OF_WEEK);

    switch(day) {
        case Calendar.MONDAY:
            day = R.string.abbreviation_monday;
            break;
        case Calendar.TUESDAY:
            day = R.string.abbreviation_tuesday;
            break;
        case Calendar.WEDNESDAY:
            day = R.string.abbreviation_wednesday;
            break;
        case Calendar.THURSDAY:
            day = R.string.abbreviation_thursday;
            break;
        case Calendar.FRIDAY:
            day = R.string.abbreviation_friday;
            break;
        case Calendar.SATURDAY:
            day = R.string.abbreviation_saturday;
            break;
        case Calendar.SUNDAY:
            day = R.string.abbreviation_sunday;
            break;
        default:
            day = R.string.abbreviation_monday;
    }
    holder.day.setText(day);
    holder.temperature.setText(StringFormatUtils.formatTemperature(context, f.getTemperature()));
}
 
Example 11
Source File: MailDateFormat.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return the java.util.Calendar constant for the parsed day name
 */
final int parseDayName() throws ParseException {
    switch (getChar()) {
        case 'S':
            if (skipPair('u', 'n')) {
                return Calendar.SUNDAY;
            } else if (skipPair('a', 't')) {
                return Calendar.SATURDAY;
            }
            break;
        case 'T':
            if (skipPair('u', 'e')) {
                return Calendar.TUESDAY;
            } else if (skipPair('h', 'u')) {
                return Calendar.THURSDAY;
            }
            break;
        case 'M':
            if (skipPair('o', 'n')) {
                return Calendar.MONDAY;
            }
            break;
        case 'W':
            if (skipPair('e', 'd')) {
                return Calendar.WEDNESDAY;
            }
            break;
        case 'F':
            if (skipPair('r', 'i')) {
                return Calendar.FRIDAY;
            }
            break;
        case INVALID_CHAR:
            throw new ParseException("Invalid day-name",
                    pos.getIndex());
    }
    pos.setIndex(pos.getIndex() - 1);
    throw new ParseException("Invalid day-name", pos.getIndex());
}
 
Example 12
Source File: TimeUtil.java    From FriendCircle with GNU General Public License v3.0 5 votes vote down vote up
public static String getWeek(String pTime) {
    String week = "";
    Calendar c = Calendar.getInstance();
    try {
        c.setTime(yyyymmddFormate.parse(pTime));
    } catch (ParseException e) {
        e.printStackTrace();
    }
    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
        week = "周日";
    }
    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
        week = "周一";
    }
    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.TUESDAY) {
        week = "周二";
    }
    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) {
        week = "周三";
    }
    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY) {
        week = "周四";
    }
    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) {
        week = "周五";
    }
    if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
        week = "周六";
    }
    return week;
}
 
Example 13
Source File: JewishCalendar.java    From zmanim with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Return the type of year for parsha calculations. The algorithm follows the
 * <a href="http://hebrewbooks.org/pdfpager.aspx?req=14268&amp;st=&amp;pgnum=222">Luach Arba'ah Shearim</a> in the Tur Ohr Hachaim.
 * @return the type of year for parsha calculations.
 */
private int getParshaYearType() {
	int roshHashanaDayOfWeek = (getJewishCalendarElapsedDays(getJewishYear()) + 1) % 7; // plus one to the original Rosh Hashana of year 1 to get a week starting on Sunday
	if(roshHashanaDayOfWeek == 0) {
		roshHashanaDayOfWeek = 7; // convert 0 to 7 for Shabbos for readability
	}
	if (isJewishLeapYear()) {
		switch (roshHashanaDayOfWeek) {
		case Calendar.MONDAY:
			if (isKislevShort()) { //BaCh
				if (getInIsrael()) {
					return 14;
				}
				return 6;
			}
			if (isCheshvanLong()) { //BaSh
				if (getInIsrael()) {
					return 15;
				}
				return 7;
			}
			break;
		case Calendar.TUESDAY: //Gak
			if (getInIsrael()) {
				return 15;
			}
			return 7;
		case Calendar.THURSDAY:
			if (isKislevShort()) { //HaCh
				return 8;
			}
			if (isCheshvanLong()) { //HaSh
				return 9;
			}
			break;
		case Calendar.SATURDAY:
			if (isKislevShort()) { //ZaCh
				return 10;
			}
			if (isCheshvanLong()) { //ZaSh
				if (getInIsrael()) {
					return 16;
				}
				return 11;
			}
			break;
		}
	} else { //not a leap year
		switch (roshHashanaDayOfWeek) {
		case Calendar.MONDAY:
			if (isKislevShort()) { //BaCh
				return 0;
			}
			if (isCheshvanLong()) { //BaSh
				if (getInIsrael()) {
					return 12;
				}
				return 1;
			}
			break;
		case Calendar.TUESDAY: //GaK
			if (getInIsrael()) {
				return 12;
			}
			return 1;
		case Calendar.THURSDAY:
			if (isCheshvanLong()) { //HaSh
				return 3;
			}
			if (!isKislevShort()) { //Hak
				if (getInIsrael()) {
					return 13;
				}
				return 2;
			}
			break;
		case Calendar.SATURDAY:
			if (isKislevShort()) { //ZaCh
				return 4;
			}
			if (isCheshvanLong()) { //ZaSh
				return 5;
			}
			break;
		}
	}
	return -1; //keep the compiler happy
}
 
Example 14
Source File: FunAlmanac.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public static Reply getRepresentation(double bgValue, String arrowName, boolean usingMgDl) {
    final Calendar c = Calendar.getInstance();
    int currentDayOfWeek;
    boolean preserveDayOfWeek = true; // keep same or represent trend
    c.setTimeInMillis(JoH.tsl());
    if (preserveDayOfWeek) {
        switch (arrowName) {
            case "DoubleDown":
                currentDayOfWeek = Calendar.MONDAY;
                break;
            case "SingleDown":
                currentDayOfWeek = Calendar.TUESDAY;
                break;
            case "FortyFiveDown":
                currentDayOfWeek = Calendar.WEDNESDAY;
                break;
            case "Flat":
                currentDayOfWeek = Calendar.THURSDAY;
                break;
            case "FortyFiveUp":
                currentDayOfWeek = Calendar.FRIDAY;
                break;
            case "SingleUp":
                currentDayOfWeek = Calendar.SATURDAY;
                break;
            case "DoubleUp":
                currentDayOfWeek = Calendar.SUNDAY;
                break;
            default:
                currentDayOfWeek = Calendar.THURSDAY;
        }
    } else currentDayOfWeek = c.get(Calendar.DAY_OF_WEEK);

    int macro = 0, micro = 0;
    double value = bgValue;
    if (usingMgDl) {
        if (value > 299) value = 299;
        else if (value < 10) value = 10;
        macro = (int) value / 10;
        micro = (int) value % 10;
    } else {
        value = roundDouble(mmolConvert(value), 1);
        if (value >= 18.9) value = 18.9;
        macro = (int) value;
        micro = (int) (JoH.roundDouble(value - macro, 1) * 10);
        macro++;
    }
    if (micro == 0) micro = 10; //10th month will be displayed as 0 on the custom watchface
    micro--;
    c.set(Calendar.DAY_OF_MONTH, macro); //day 1 represent 0
    c.set(Calendar.MONTH, micro);
    int max = c.getActualMaximum(Calendar.DAY_OF_MONTH);
    int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
    while ((dayOfWeek != currentDayOfWeek) || ((max < 29))) {
        c.set(Calendar.YEAR, c.get(Calendar.YEAR) + 1);
        c.set(Calendar.DAY_OF_MONTH, macro);
        c.set(Calendar.MONTH, micro);
        max = c.getActualMaximum(Calendar.DAY_OF_MONTH);
        dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
    }
    String textVal = Double.toString(value) + " " + Unitized.unit(usingMgDl) + ", " + arrowName;
    return new Reply(c.getTimeInMillis(), textVal);
}
 
Example 15
Source File: InfoFragment.java    From apollo-DuerOS with Apache License 2.0 4 votes vote down vote up
public void updateTime() {
    Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH) + 1;
    int date = c.get(Calendar.DATE);
    int hours = c.get(Calendar.HOUR_OF_DAY);
    int minutes = c.get(Calendar.MINUTE);
    int week = c.get(Calendar.DAY_OF_WEEK);

    String hour;
    String minute;
    String weekDay;

    if (hours < 10) {
        hour = "0" + hours;
    } else {
        hour = "" + hours;
    }
    if (minutes < 10) {
        minute = "0" + minutes;
    } else {
        minute = "" + minutes;
    }

    String[] weeks = getResources().getStringArray(R.array.info_week);

    switch (week) {
        case Calendar.MONDAY:
            weekDay = weeks[0];
            break;
        case Calendar.TUESDAY:
            weekDay = weeks[1];
            break;
        case Calendar.WEDNESDAY:
            weekDay = weeks[2];
            break;
        case Calendar.THURSDAY:
            weekDay = weeks[3];
            break;
        case Calendar.FRIDAY:
            weekDay = weeks[4];
            break;
        case Calendar.SATURDAY:
            weekDay = weeks[5];
            break;
        case Calendar.SUNDAY:
            weekDay = weeks[6];
            break;
        default:
            weekDay = "";
            break;
    }

    mTimeText.setText(hour + ":" + minute);
    if (mShowYear) {
        mDateText.setText(year + getResources().getString(R.string.info_year)
                + month + getResources().getString(R.string.info_month)
                + date + getResources().getString(R.string.info_day));
    } else {
        mDateText.setText(month + getResources().getString(R.string.info_month)
                + date + getResources().getString(R.string.info_day));
    }
    mWeekText.setText(getResources().getString(R.string.info_week) + weekDay);
    mHandler.removeMessages(REFRESH_TIME);
    mHandler.sendEmptyMessageDelayed(REFRESH_TIME, 1000);
}
 
Example 16
Source File: TimeUtils.java    From your-local-weather with GNU General Public License v3.0 4 votes vote down vote up
public static Long setupAlarmForVoiceForVoiceSetting(Context context, Long voiceSettingId, VoiceSettingParametersDbHelper voiceSettingParametersDbHelper) {
    Long storedHourMinute = voiceSettingParametersDbHelper.getLongParam(
            voiceSettingId,
            VoiceSettingParamType.VOICE_SETTING_TIME_TO_START.getVoiceSettingParamTypeId());

    if (storedHourMinute == null) {
        return null;
    }

    int hourMinute = storedHourMinute.intValue();
    int hour = hourMinute / 100;
    int minute = hourMinute - (hour * 100);

    final Calendar now = Calendar.getInstance();
    now.set(Calendar.SECOND, 0);
    now.set(Calendar.MILLISECOND, 0);
    now.add(Calendar.MINUTE, 1);

    final Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, hour);
    c.set(Calendar.MINUTE, minute);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);

    if (now.after(c)) {
        c.add(Calendar.DAY_OF_YEAR, 1);
    }

    Long enabledDaysOfWeek = voiceSettingParametersDbHelper.getLongParam(
            voiceSettingId,
            VoiceSettingParamType.VOICE_SETTING_TRIGGER_DAY_IN_WEEK.getVoiceSettingParamTypeId());

    if (enabledDaysOfWeek == null) {
        return null;
    }

    for (int dayOfWeek = 0; dayOfWeek < 7; dayOfWeek++) {
        int currentDayOfWeek = c.get(Calendar.DAY_OF_WEEK);

        if (currentDayOfWeek == Calendar.MONDAY) {
            if (isCurrentSettingIndex(enabledDaysOfWeek, 6)) {
                break;
            } else {
                c.add(Calendar.DAY_OF_YEAR, 1);
                continue;
            }
        }
        if (currentDayOfWeek == Calendar.TUESDAY) {
            if (isCurrentSettingIndex(enabledDaysOfWeek, 5)) {
                break;
            } else {
                c.add(Calendar.DAY_OF_YEAR, 1);
                continue;
            }
        }
        if (currentDayOfWeek == Calendar.WEDNESDAY) {
            if (isCurrentSettingIndex(enabledDaysOfWeek, 4)) {
                break;
            } else {
                c.add(Calendar.DAY_OF_YEAR, 1);
                continue;
            }
        }
        if (currentDayOfWeek == Calendar.THURSDAY) {
            if (isCurrentSettingIndex(enabledDaysOfWeek, 3)) {
                break;
            } else {
                c.add(Calendar.DAY_OF_YEAR, 1);
                continue;
            }
        }
        if (currentDayOfWeek == Calendar.FRIDAY) {
            if (isCurrentSettingIndex(enabledDaysOfWeek, 2)) {
                break;
            } else {
                c.add(Calendar.DAY_OF_YEAR, 1);
                continue;
            }
        }
        if (currentDayOfWeek == Calendar.SATURDAY) {
            if (isCurrentSettingIndex(enabledDaysOfWeek, 1)) {
                break;
            } else {
                c.add(Calendar.DAY_OF_YEAR, 1);
                continue;
            }
        }
        if (currentDayOfWeek == Calendar.SUNDAY) {
            if (isCurrentSettingIndex(enabledDaysOfWeek, 0)) {
                break;
            } else {
                c.add(Calendar.DAY_OF_YEAR, 1);
                continue;
            }
        }
    }
    return c.getTimeInMillis();
}
 
Example 17
Source File: EventRoomAvailabilityBackend.java    From unitime with Apache License 2.0 4 votes vote down vote up
public static TreeSet<MeetingConflictInterface> generateUnavailabilityMeetings(Location location, List<Integer> dates, int startSlot, int endSlot) {
	if (location.getEventAvailability() == null || location.getEventAvailability().length() != Constants.SLOTS_PER_DAY * Constants.DAY_CODES.length) return null;

	TreeSet<MeetingConflictInterface> ret = new TreeSet<MeetingConflictInterface>();
	
	ResourceInterface resource = new ResourceInterface();
	resource.setType(ResourceType.ROOM);
	resource.setId(location.getUniqueId());
	resource.setName(location.getLabel());
	resource.setSize(location.getCapacity());
	resource.setRoomType(location.getRoomTypeLabel());
	resource.setBreakTime(location.getEffectiveBreakTime());
	resource.setMessage(location.getEventMessage());
	resource.setIgnoreRoomCheck(location.isIgnoreRoomCheck());
	resource.setDisplayName(location.getDisplayName());
	
	Calendar calendar = Calendar.getInstance();
       for (int day = 0; day < Constants.DAY_CODES.length; day++)
       	for (int startTime = 0; startTime < Constants.SLOTS_PER_DAY; ) {
       		if (location.getEventAvailability().charAt(day * Constants.SLOTS_PER_DAY + startTime) != '1') { startTime++; continue; }
       		int endTime = startTime + 1;
       		while (endTime < Constants.SLOTS_PER_DAY && location.getEventAvailability().charAt(day * Constants.SLOTS_PER_DAY + endTime) == '1') endTime++;
       		if (startTime < endSlot && startSlot < endTime) {
           		calendar.setTime(location.getSession().getEventBeginDate());
           		int dayOfYear = CalendarUtils.date2dayOfYear(location.getSession().getSessionStartYear(), calendar.getTime());
           		
           		do {
           			if (dates.contains(dayOfYear)) {
               			int dayOfWeek = -1;
               			switch (calendar.get(Calendar.DAY_OF_WEEK)) {
               			case Calendar.MONDAY: dayOfWeek = Constants.DAY_MON; break;
               			case Calendar.TUESDAY: dayOfWeek = Constants.DAY_TUE; break;
               			case Calendar.WEDNESDAY: dayOfWeek = Constants.DAY_WED; break;
               			case Calendar.THURSDAY: dayOfWeek = Constants.DAY_THU; break;
               			case Calendar.FRIDAY: dayOfWeek = Constants.DAY_FRI; break;
               			case Calendar.SATURDAY: dayOfWeek = Constants.DAY_SAT; break;
               			case Calendar.SUNDAY: dayOfWeek = Constants.DAY_SUN; break;
               			}
               			
               			if (day == dayOfWeek) {
                   			MeetingConflictInterface m = new MeetingConflictInterface();
               				m.setName(MESSAGES.unavailableEventDefaultName());
               				m.setType(EventInterface.EventType.Unavailabile);
                       		m.setStartSlot(startTime);
                       		m.setEndSlot(endTime);
                       		m.setDayOfWeek(dayOfWeek);
                       		m.setMeetingDate(calendar.getTime());
                       		m.setDayOfYear(dayOfYear);
                       		m.setLocation(resource);
                       		ret.add(m);
               			}
           			}
           			calendar.add(Calendar.DAY_OF_YEAR, 1); dayOfYear++;
           		} while (!calendar.getTime().after(location.getSession().getEventEndDate()));        			
       		}
       		startTime = endTime;
       	}
	return ret;
}
 
Example 18
Source File: dayOfWeekAsString.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
public cfData execute(cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException {

		int weekDay = getNamedIntParam(argStruct, "dayOfWeek", 1);
		if (weekDay < 1 || weekDay > 7)
			throwException(_session, "Day must be within 1 and 7");

		DateFormatSymbols dfs = new DateFormatSymbols(_session.getLocale());
		String[] weekdays = dfs.getWeekdays();

		String weekDayString = "";
		switch (weekDay) {
		case 0:
			weekDayString = weekdays[Calendar.SATURDAY];
			break;
		case 1:
			weekDayString = weekdays[Calendar.SUNDAY];
			break;
		case 2:
			weekDayString = weekdays[Calendar.MONDAY];
			break;
		case 3:
			weekDayString = weekdays[Calendar.TUESDAY];
			break;
		case 4:
			weekDayString = weekdays[Calendar.WEDNESDAY];
			break;
		case 5:
			weekDayString = weekdays[Calendar.THURSDAY];
			break;
		case 6:
			weekDayString = weekdays[Calendar.FRIDAY];
			break;
		case 7:
			weekDayString = weekdays[Calendar.SATURDAY];
			break;
		default:
			throw new IllegalStateException("invalid week day - " + weekDay);
		}

		return new cfStringData(weekDayString);
	}
 
Example 19
Source File: PeriodicScheduler.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void setDays(final String days) {
	dayBits = 0;
	for (int i = 0; i < days.length(); i++) {
		char ch = days.charAt(i);
		switch (ch) {
		case 'M':
		case 'm':
			dayBits |= 1 << Calendar.MONDAY;
			break;

		case 'T':
		case 't':
			dayBits |= 1 << Calendar.TUESDAY;
			break;

		case 'W':
		case 'w':
			dayBits |= 1 << Calendar.WEDNESDAY;
			break;

		case 'R':
		case 'r':
			dayBits |= 1 << Calendar.THURSDAY;
			break;

		case 'F':
		case 'f':
			dayBits |= 1 << Calendar.FRIDAY;
			break;

		case 'S':
		case 's':
			dayBits |= 1 << Calendar.SATURDAY;
			break;

		case 'U':
		case 'u':
			dayBits |= 1 << Calendar.SUNDAY;
			break;

		}
	}
	if (dayBits < (1 << Calendar.SUNDAY))
		throw new IllegalStateException("No valid day bits set");
}
 
Example 20
Source File: AddSectionsBean.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public String getTuesday() {
    return daysOfWeek[Calendar.TUESDAY];
}