Java Code Examples for java.util.Calendar.TUESDAY

The following are Jave code examples for showing how to use TUESDAY of the java.util.Calendar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: NotifyTools   File: ChineseCalendar.java   View Source Code Vote up 7 votes
public String WeekDayStr()
{
    cld.setTime(_date);
        switch (cld.get(Calendar.DAY_OF_WEEK))
        {
            case Calendar.SUNDAY:
                return "星期日";
            case Calendar.MONDAY:
                return "星期一";
            case Calendar.TUESDAY:
                return "星期二";
            case Calendar.WEDNESDAY:
                return "星期三";
            case Calendar.THURSDAY:
                return "星期四";
            case Calendar.FRIDAY:
                return "星期五";
            default:
                return "星期六";
        }

}
 
Example 2
Project: GitHub   File: Countly.java   View Source Code Vote up 7 votes
/**
 * Utility method to return a current day of the week that can be used in the Count.ly API.
 */
static int currentDayOfWeek(){
    int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
    switch (day) {
        case Calendar.MONDAY:
            return 1;
        case Calendar.TUESDAY:
            return 2;
        case Calendar.WEDNESDAY:
            return 3;
        case Calendar.THURSDAY:
            return 4;
        case Calendar.FRIDAY:
            return 5;
        case Calendar.SATURDAY:
            return 6;
    }
    return 0;
}
 
Example 3
Project: leoapp-sources   File: NotificationHandler.java   View Source Code Vote up 7 votes
private int getNextDayOfWeek() {
    Calendar c = new GregorianCalendar();
    c.setTime(new Date());
    int i = c.get(Calendar.DAY_OF_WEEK);
    if (i == Calendar.SUNDAY)
        return 1;
    if (i == Calendar.MONDAY)
        return 2;
    if (i == Calendar.TUESDAY)
        return 3;
    if (i == Calendar.WEDNESDAY)
        return 4;
    if (i == Calendar.THURSDAY)
        return 5;
    return 6;
}
 
Example 4
Project: unitimes   File: PersonalizedExamReportAction.java   View Source Code Vote up 7 votes
public int getDaysCode(Set meetings) {
    int daysCode = 0;
    for (Iterator i=meetings.iterator();i.hasNext();) {
        Meeting meeting = (Meeting)i.next();
        Calendar date = Calendar.getInstance(Locale.US);
        date.setTime(meeting.getMeetingDate());
        switch (date.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.MONDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_MON]; break;
        case Calendar.TUESDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_TUE]; break;
        case Calendar.WEDNESDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_WED]; break;
        case Calendar.THURSDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_THU]; break;
        case Calendar.FRIDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_FRI]; break;
        case Calendar.SATURDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_SAT]; break;
        case Calendar.SUNDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_SUN]; break;
        }
    }
    return daysCode;
}
 
Example 5
Project: Android-Scrapper   File: GridCalendarAdapter.java   View Source Code Vote up 7 votes
private int getDay(int day) {
    switch (day) {
        case Calendar.SUNDAY:
            return 0;
        case Calendar.MONDAY:
            return 1;
        case Calendar.TUESDAY:
            return 2;
        case Calendar.WEDNESDAY:
            return 3;
        case Calendar.THURSDAY:
            return 4;
        case Calendar.FRIDAY:
            return 5;
        case Calendar.SATURDAY:
            return 6;
        default:
            return 0;
    }
}
 
Example 6
Project: L2J-Global   File: L2TeleporterInstance.java   View Source Code Vote up 7 votes
/**
 * For characters below level 77 teleport service is free.<br>
 * From 8.00 pm to 00.00 from Monday till Tuesday for all characters there's a 50% discount on teleportation services
 * @param player
 * @param type
 * @param loc
 * @return
 */
private long calculateFee(L2PcInstance player, TeleportType type, TeleportLocation loc)
{
	if (type == TeleportType.NORMAL)
	{
		if (!player.isSubClassActive() && (player.getLevel() < 77))
		{
			return 0;
		}
		
		final Calendar cal = Calendar.getInstance();
		final int hour = cal.get(Calendar.HOUR_OF_DAY);
		final int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
		if ((hour >= 20) && ((dayOfWeek >= Calendar.MONDAY) && (dayOfWeek <= Calendar.TUESDAY)))
		{
			return loc.getFeeCount() / 2;
		}
	}
	return loc.getFeeCount();
}
 
Example 7
Project: CHIP-Android-SDK   File: AlarmFragment.java   View Source Code Vote up 6 votes
void setCurrentClock() {
    ChipRobot robot = ChipRobotFinder.getInstance().getChipRobotConnectedList().get(0);

    Calendar rightNow = Calendar.getInstance();
    final int year = rightNow.get(Calendar.YEAR);
    final int month = rightNow.get(Calendar.MONTH);
    final int day = rightNow.get(Calendar.DATE);
    final int hour = rightNow.get(Calendar.HOUR_OF_DAY);
    final int minute = rightNow.get(Calendar.MINUTE);
    final int seconds = rightNow.get(Calendar.SECOND);
    int dayOfWeek_t = rightNow.get(Calendar.DAY_OF_WEEK);
    switch (dayOfWeek_t) {
        case Calendar.SUNDAY:
            dayOfWeek_t = 0;
            break;
        case Calendar.MONDAY:
            dayOfWeek_t = 1;
            break;
        case Calendar.TUESDAY:
            dayOfWeek_t = 2;
            break;
        case Calendar.WEDNESDAY:
            dayOfWeek_t = 3;
            break;
        case Calendar.THURSDAY:
            dayOfWeek_t = 4;
            break;
        case Calendar.FRIDAY:
            dayOfWeek_t = 5;
            break;
        case Calendar.SATURDAY:
            break;
    }
    final int dayOfWeek = dayOfWeek_t;
    robot.chipSetCurrentClock(year, (byte) (month + 1), (byte) day, (byte) hour, (byte) minute, (byte) seconds, (byte) dayOfWeek);
}
 
Example 8
Project: workdays   File: DateUtils.java   View Source Code Vote up 6 votes
public static int parseWeekday(String s) {
    if(s == null) return -1;
    switch(s.toLowerCase()) {
        case "monday": return Calendar.MONDAY;
        case "tuesday": return Calendar.TUESDAY;
        case "wednesday": return Calendar.WEDNESDAY;
        case "thursday": return Calendar.THURSDAY;
        case "friday": return Calendar.FRIDAY;
        case "saturday": return Calendar.SATURDAY;
        case "sunday": return Calendar.SUNDAY;
        default: return -1;
    }
}
 
Example 9
Project: NeuTV   File: Video.java   View Source Code Vote up 6 votes
private String getWeek(String pTime) {
    String Week = "";
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    Calendar c = Calendar.getInstance();
    try {
        c.setTime(format.parse(pTime));
    } catch (ParseException e) {
        return null;
    }
    switch (c.get(Calendar.DAY_OF_WEEK)){
        case Calendar.SUNDAY:
            Week = "周日";
            break;
        case Calendar.MONDAY:
            Week = "周一";
            break;
        case Calendar.TUESDAY:
            Week = "周二";
            break;
        case Calendar.WEDNESDAY:
            Week = "周三";
            break;
        case Calendar.THURSDAY:
            Week = "周四";
            break;
        case Calendar.FRIDAY:
            Week = "周五";
            break;
        case Calendar.SATURDAY:
            Week = "周六";
            break;
    }
    return Week;
}
 
Example 10
Project: SER316-Dresden   File: EventsTableMonthly.java   View Source Code Vote up 6 votes
public Object getValueAt(int row, int col) {
	Event ev = getEventAt(row,col);
	if(ev == null) return "";
	Calendar cal = (Calendar)days[col].get(row);
	String res = "";
	switch(cal.get(Calendar.DAY_OF_WEEK)){
		case Calendar.SUNDAY: res += "SU";
			break;
		case Calendar.MONDAY: res += "MO";
			break;
		case Calendar.TUESDAY: res += "TU";
			break;
		case Calendar.WEDNESDAY: res += "WE";
			break;
		case Calendar.THURSDAY: res += "TH";
			break;
		case Calendar.FRIDAY: res += "FR";
			break;
		case Calendar.SATURDAY: res += "SA";
			break;
		default: res += "??";
	}
	String dOM = cal.get(Calendar.DAY_OF_MONTH) + "";
	switch(cal.get(Calendar.DAY_OF_MONTH)%10){
		case 1: dOM += "st";
			break;
		case 2: dOM += "nd";
			break;
		case 3: dOM += "rd";
			break;
		default:dOM+="th";
	}
	res+= " / " + dOM  + ": ";
	if(ev.getText().equals("")) res+= "EVENT";
	else res += ev.getText();
	return res;       		
}
 
Example 11
Project: unitimes   File: PdfLegacyExamReport.java   View Source Code Vote up 6 votes
public String getShortDate(Date date) {
    Calendar c = Calendar.getInstance(Locale.US);
    c.setTime(date);
    String day = "";
    switch (c.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.MONDAY : day = DAY_NAMES_SHORT[Constants.DAY_MON]; break;
        case Calendar.TUESDAY : day = DAY_NAMES_SHORT[Constants.DAY_TUE]; break;
        case Calendar.WEDNESDAY : day = DAY_NAMES_SHORT[Constants.DAY_WED]; break;
        case Calendar.THURSDAY : day = DAY_NAMES_SHORT[Constants.DAY_THU]; break;
        case Calendar.FRIDAY : day = DAY_NAMES_SHORT[Constants.DAY_FRI]; break;
        case Calendar.SATURDAY : day = DAY_NAMES_SHORT[Constants.DAY_SAT]; break;
        case Calendar.SUNDAY : day = DAY_NAMES_SHORT[Constants.DAY_SUN]; break;
    }
    return day+" "+new SimpleDateFormat("MM/dd").format(date);
}
 
Example 12
Project: hive-udf-backports   File: GenericUDFNextDay.java   View Source Code Vote up 6 votes
protected int getIntDayOfWeek(String dayOfWeek) throws UDFArgumentException {
  if (dayOfWeek == null) {
    return -1;
  }
  if (MON.matches(dayOfWeek)) {
    return Calendar.MONDAY;
  }
  if (TUE.matches(dayOfWeek)) {
    return Calendar.TUESDAY;
  }
  if (WED.matches(dayOfWeek)) {
    return Calendar.WEDNESDAY;
  }
  if (THU.matches(dayOfWeek)) {
    return Calendar.THURSDAY;
  }
  if (FRI.matches(dayOfWeek)) {
    return Calendar.FRIDAY;
  }
  if (SAT.matches(dayOfWeek)) {
    return Calendar.SATURDAY;
  }
  if (SUN.matches(dayOfWeek)) {
    return Calendar.SUNDAY;
  }
  return -1;
}
 
Example 13
Project: Expert-Android-Programming   File: PlaceDetailActivity.java   View Source Code Vote up 6 votes
private void setTimings(List<RestaurantTiming> timings) {

        for (int i = 0; i < timings.size(); i++) {
            switch (AppUtils.getDay(timings.get(i).getDay())) {

                case Calendar.MONDAY:
                    timingMonday.setText(timings.get(i).getTiming());
                    break;
                case Calendar.TUESDAY:
                    timingTuesday.setText(timings.get(i).getTiming());
                    break;
                case Calendar.WEDNESDAY:
                    timingWednesday.setText(timings.get(i).getTiming());
                    break;
                case Calendar.THURSDAY:
                    timingThursday.setText(timings.get(i).getTiming());
                    break;
                case Calendar.FRIDAY:
                    timingFriday.setText(timings.get(i).getTiming());
                    break;
                case Calendar.SATURDAY:
                    timingSaturday.setText(timings.get(i).getTiming());
                    break;
                case Calendar.SUNDAY:
                    timingSunday.setText(timings.get(i).getTiming());
                    break;
            }
        }
        setToday();
    }
 
Example 14
Project: bluewatcher   File: TimeService.java   View Source Code Vote up 6 votes
private static byte[] createCurrentTimeValue() {
	byte[] arrayOfByte = new byte[10];
	Calendar localCalendar = Calendar.getInstance();
	int i = localCalendar.get(1);
	arrayOfByte[0] = (byte) (0xFF & i >>> 0);
	arrayOfByte[1] = (byte) (0xFF & i >>> 8);
	arrayOfByte[2] = (byte) (1 + localCalendar.get(2));
	arrayOfByte[3] = (byte) localCalendar.get(5);
	arrayOfByte[4] = (byte) localCalendar.get(11);
	arrayOfByte[5] = (byte) localCalendar.get(12);
	arrayOfByte[6] = (byte) (localCalendar.get(13) + 1);
	switch (localCalendar.get(7)) {
	case Calendar.MONDAY:
		arrayOfByte[7] = 0x01;
		break;
	case Calendar.TUESDAY:
		arrayOfByte[7] = 0x02;
		break;
	case Calendar.WEDNESDAY:
		arrayOfByte[7] = 0x03;
		break;
	case Calendar.THURSDAY:
		arrayOfByte[7] = 0x04;
		break;
	case Calendar.FRIDAY:
		arrayOfByte[7] = 0x05;
		break;
	case Calendar.SATURDAY:
		arrayOfByte[7] = 0x06;
		break;
	case Calendar.SUNDAY:
		arrayOfByte[7] = 0x07;
		break;
	}
	arrayOfByte[8] = (byte) (int) TimeUnit.MILLISECONDS.toSeconds(256 * localCalendar.get(14));
	arrayOfByte[9] = 0;
	return arrayOfByte;
}
 
Example 15
Project: unitimes   File: MinutesPerWeek.java   View Source Code Vote up 6 votes
/**
 * Return all dates marked yellow in the given date pattern that are matching the selected day code (days of week)
 */
@Override
public List<Date> getDates(int minsPerWeek, 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();
       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);
       }
	return ret;
}
 
Example 16
Project: unitimes   File: MeetingCountingDuration.java   View Source Code Vote up 6 votes
@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 17
Project: SharedPermission   File: DateUtil.java   View Source Code Vote up 5 votes
/**
 * Returns abbreviated (3 letters) day of the week.
 *
 * @param date ISO format date
 * @return The name of the day of the week
 */
public static String getDayOfWeekAbbreviated(String date) {
    Date dateDT = parseDate(date);

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

    // Get current date
    Calendar c = Calendar.getInstance();
    // it is very important to
    // set the date of
    // the calendar.
    c.setTime(dateDT);
    int day = c.get(Calendar.DAY_OF_WEEK);

    String dayStr = null;

    switch (day) {

        case Calendar.SUNDAY:
            dayStr = "Sun";
            break;

        case Calendar.MONDAY:
            dayStr = "Mon";
            break;

        case Calendar.TUESDAY:
            dayStr = "Tue";
            break;

        case Calendar.WEDNESDAY:
            dayStr = "Wed";
            break;

        case Calendar.THURSDAY:
            dayStr = "Thu";
            break;

        case Calendar.FRIDAY:
            dayStr = "Fri";
            break;

        case Calendar.SATURDAY:
            dayStr = "Sat";
            break;
    }

    return dayStr;
}
 
Example 18
Project: routineKeen   File: HabitTrackerFullTest.java   View Source Code Vote up 5 votes
@Test
public void testHabitSchedule() {

    // Get current day of the week in string form
    String today;
    int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
    switch (day) {
        case Calendar.SUNDAY:   today = "Sun";  break;
        case Calendar.MONDAY:   today = "Mon";  break;
        case Calendar.TUESDAY:  today = "Tue";  break;
        case Calendar.WEDNESDAY:today = "Wed";  break;
        case Calendar.THURSDAY: today = "Thu";  break;
        case Calendar.FRIDAY:   today = "Fri";  break;
        case Calendar.SATURDAY: today = "Sat";  break;
        default:                today = null;   break;
    }

    login();

    // add 2 habits
    solo.assertCurrentActivity("Wrong Activity", UserMenu.class);
    solo.clickOnText("View Habit List");
    clearHabitList();

    addTestHabit(TEST_HABIT_NAME, TEST_HABIT_REASON);
    addTestHabit(TEST_HABIT_NAME2, TEST_HABIT_REASON);
    addTestHabit(TEST_HABIT_NAME3, TEST_HABIT_REASON);

    solo.assertCurrentActivity("Wrong Activity", HabitListActivity.class);
    solo.clickOnText(TEST_HABIT_NAME);
    disableAllDays();
    solo.clickOnButton("Save");

    solo.assertCurrentActivity("Wrong Activity", HabitListActivity.class);
    solo.clickOnText(TEST_HABIT_NAME2);
    disableAllDays();
    solo.clickOnText(today);
    solo.clickOnButton("Save");

    solo.goBack();
    solo.assertCurrentActivity("Wrong Activity", UserMenu.class);
    solo.clickOnText("View Habit Schedule");

    try { TimeUnit.SECONDS.sleep(2); } catch (InterruptedException e) { Log.d(LOG, "wait interrupted"); }
    // check that there are 2 habits in today's schedule
    assertEquals(((ListView)solo.getView("habitSchedule_listView")).getAdapter().getCount(), 2);
}
 
Example 19
Project: unitimes   File: TimetableGridSolutionHelper.java   View Source Code Vote up 5 votes
protected static void createMeetingCells(TimetableGridModel model, Session session, TimetableGridContext context, Collection<TimeBlock> times, String room) {
if (times == null) return;
int sessionYear = session.getSessionStartYear();
      int firstDOY = session.getDayOfYear(1, session.getPatternStartMonth());
      int lastDOY = session.getDayOfYear(0, session.getPatternEndMonth() + 1);
      Calendar c = Calendar.getInstance(Locale.US);
      Formats.Format<Date> df = Formats.getDateFormat(Formats.Pattern.DATE_EVENT_SHORT);
for (TimeBlock time: times) {
	if (time.getEndTime().before(context.getSessionStartDate()) || time.getStartTime().after(context.getSessionEndDate())) continue;
          int dayCode = 0;
          c.setTime(time.getStartTime());
          int m = c.get(Calendar.MONTH);
          int d = c.get(Calendar.DAY_OF_MONTH);
          if (c.get(Calendar.YEAR)<sessionYear) m-=(12 * (sessionYear - c.get(Calendar.YEAR)));
          if (c.get(Calendar.YEAR)>sessionYear) m+=(12 * (c.get(Calendar.YEAR) - sessionYear));
          BitSet weekCode = new BitSet(lastDOY - firstDOY);
          int offset = session.getDayOfYear(d,m) - firstDOY;
          weekCode.set(offset);
          switch (c.get(Calendar.DAY_OF_WEEK)) {
              case Calendar.MONDAY    : dayCode = Constants.DAY_CODES[Constants.DAY_MON]; break;
              case Calendar.TUESDAY   : dayCode = Constants.DAY_CODES[Constants.DAY_TUE]; break;
              case Calendar.WEDNESDAY : dayCode = Constants.DAY_CODES[Constants.DAY_WED]; break;
              case Calendar.THURSDAY  : dayCode = Constants.DAY_CODES[Constants.DAY_THU]; break;
              case Calendar.FRIDAY    : dayCode = Constants.DAY_CODES[Constants.DAY_FRI]; break;
              case Calendar.SATURDAY  : dayCode = Constants.DAY_CODES[Constants.DAY_SAT]; break;
              case Calendar.SUNDAY    : dayCode = Constants.DAY_CODES[Constants.DAY_SUN]; break;
          }
          int startSlot = (c.get(Calendar.HOUR_OF_DAY)*60 + c.get(Calendar.MINUTE) - Constants.FIRST_SLOT_TIME_MIN) / Constants.SLOT_LENGTH_MIN;
          c.setTime(time.getEndTime());
          int endSlot = (c.get(Calendar.HOUR_OF_DAY)*60 + c.get(Calendar.MINUTE) - Constants.FIRST_SLOT_TIME_MIN) / Constants.SLOT_LENGTH_MIN;
          int length = endSlot - startSlot;
          if (length<=0) continue;
          TimeLocation timeLocation = new TimeLocation(dayCode, startSlot, length, 0, 0, null, df.format(time.getStartTime()), weekCode, 0);
  		TimetableGridCell cell = null;
  		for (Enumeration<Integer> f=timeLocation.getStartSlots();f.hasMoreElements();) {
  			int slot = f.nextElement();
  			int idx = (7 + slot/Constants.SLOTS_PER_DAY - context.getWeekOffset()) % 7;
  			if (context.getFirstDay()>=0 && !timeLocation.getWeekCode().get(context.getFirstDay() + idx)) continue;
  			if (cell == null) {
  				cell = new TimetableGridCell();
  				cell.setType(TimetableGridCell.Type.Event);
  				cell.setId(time.getEventId());
  				cell.setDay(slot / Constants.SLOTS_PER_DAY);
  				cell.setSlot(slot % Constants.SLOTS_PER_DAY);
  				cell.addRoom(room);
  				cell.addName(time.getEventName());
  				cell.setProperty(Property.EventType, time.getEventType());
  				cell.setBackground(sBgColorNotAvailable);
  				cell.setLength(length);
  				cell.setTime(Constants.toTime(Constants.SLOT_LENGTH_MIN * startSlot + Constants.FIRST_SLOT_TIME_MIN) + " - " + Constants.toTime(Constants.SLOT_LENGTH_MIN  * endSlot + Constants.FIRST_SLOT_TIME_MIN));
  				cell.setDate(df.format(time.getStartTime()));
  				cell.setWeekCode(pattern2string(weekCode));
  			} else {
  				cell = new TimetableGridCell(cell, slot / Constants.SLOTS_PER_DAY, null);
  			}
  			model.addCell(cell);
  		}
}
  }
 
Example 20
Project: unitimes   File: EventLookupBackend.java   View Source Code Vote up 5 votes
public static TreeSet<MeetingInterface> generateUnavailabilityMeetings(Location location, boolean conflict) {
	if (location.getEventAvailability() == null || location.getEventAvailability().length() != Constants.SLOTS_PER_DAY * Constants.DAY_CODES.length) return null;

	TreeSet<MeetingInterface> ret = new TreeSet<MeetingInterface>();
	
	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++;
       		
       		calendar.setTime(location.getSession().getEventBeginDate());
       		int dayOfYear = CalendarUtils.date2dayOfYear(location.getSession().getSessionStartYear(), calendar.getTime());
       		do {
       			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) {
       				MeetingInterface m = null;
       				if (conflict) {
       					MeetingConflictInterface c = new MeetingConflictInterface();
       					c.setName(MESSAGES.unavailableEventDefaultName());
       					c.setType(EventInterface.EventType.Unavailabile);
       					m = c;
       				} else {
       					m = new MeetingInterface();
       				}
               		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;
}