Java Code Examples for java.util.Calendar#FRIDAY

The following examples show how to use java.util.Calendar#FRIDAY . 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: UpdaterRootJob.java    From developer-studio with Apache License 2.0 6 votes vote down vote up
private int getIntValOfDay(String updateIntervalDay) {
	switch (updateIntervalDay) {
	case (PreferenceConstants.EVERY_MONDAY):
		return Calendar.MONDAY;
	case (PreferenceConstants.EVERY_TUESDAY):
		return Calendar.TUESDAY;
	case (PreferenceConstants.EVERY_WEDNESDAY):
		return Calendar.WEDNESDAY;
	case (PreferenceConstants.EVERY_THURSDAY):
		return Calendar.THURSDAY;
	case (PreferenceConstants.EVERY_FRIDAY):
		return Calendar.FRIDAY;
	case (PreferenceConstants.EVERY_SATURDAY):
		return Calendar.SATURDAY;
	default:
		return Calendar.SUNDAY; // case SUNDAY default setting
	}

}
 
Example 2
Source File: RecurrenceUtils.java    From SublimePicker with Apache License 2.0 6 votes vote down vote up
/**
 * Converts the day of the week from android.text.format.Time to java.util.Calendar
 */
public static int convertDayOfWeekFromTimeToCalendar(int timeDayOfWeek) {
    switch (timeDayOfWeek) {
        case Time.MONDAY:
            return Calendar.MONDAY;
        case Time.TUESDAY:
            return Calendar.TUESDAY;
        case Time.WEDNESDAY:
            return Calendar.WEDNESDAY;
        case Time.THURSDAY:
            return Calendar.THURSDAY;
        case Time.FRIDAY:
            return Calendar.FRIDAY;
        case Time.SATURDAY:
            return Calendar.SATURDAY;
        case Time.SUNDAY:
            return Calendar.SUNDAY;
        default:
            throw new IllegalArgumentException("Argument must be between Time.SUNDAY and " +
                    "Time.SATURDAY");
    }
}
 
Example 3
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 4
Source File: DateCalc.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static int getWeekdayNum(Weekday weekday) {
	switch (weekday) {
		case SUNDAY:
			return Calendar.SUNDAY;
		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;
		default:
			throw new IllegalArgumentException(L10nUtil.getMessage(MessageCodes.UNSUPPORTED_WEEKDAY, DefaultMessages.UNSUPPORTED_WEEKDAY, weekday));
	}
}
 
Example 5
Source File: ManualRecord.java    From sagetv with Apache License 2.0 6 votes vote down vote up
private static boolean doesMaskHaveDay(int mask, int day)
{
  if (day == Calendar.SUNDAY)
    return (mask & RECUR_SUN_MASK) != 0;
  else if (day == Calendar.MONDAY)
    return (mask & RECUR_MON_MASK) != 0;
  else if (day == Calendar.TUESDAY)
    return (mask & RECUR_TUE_MASK) != 0;
  else if (day == Calendar.WEDNESDAY)
    return (mask & RECUR_WED_MASK) != 0;
  else if (day == Calendar.THURSDAY)
    return (mask & RECUR_THU_MASK) != 0;
  else if (day == Calendar.FRIDAY)
    return (mask & RECUR_FRI_MASK) != 0;
  else if (day == Calendar.SATURDAY)
    return (mask & RECUR_SAT_MASK) != 0;
  else return false;
}
 
Example 6
Source File: DateUtils.java    From bleYan with GNU General Public License v2.0 6 votes vote down vote up
public static String getWeekDayName(long milliseconds) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(milliseconds);
    int day_of_week = cal.get(Calendar.DAY_OF_WEEK);
    switch (day_of_week) {
        case Calendar.MONDAY:
            return WEEK_MONDAY;
        case Calendar.TUESDAY:
            return WEEK_TUESDAY;
        case Calendar.WEDNESDAY:
            return WEEK_WEDNESDAY;
        case Calendar.THURSDAY:
            return WEEK_THURSDAY;
        case Calendar.FRIDAY:
            return WEEK_FRIDAY;
        case Calendar.SATURDAY:
            return WEEK_SATURDAY;
        case Calendar.SUNDAY:
            return WEEK_SUNDAY;
        default:
            return "";
    }
}
 
Example 7
Source File: PrefHelper.java    From Easy_xkcd with Apache License 2.0 6 votes vote down vote up
public void setUpdated(int day, boolean found) {
    SharedPreferences.Editor editor = sharedPrefs.edit();
    switch (day) {
        case Calendar.MONDAY:
            editor.putBoolean(MONDAY_UPDATE, found);
            editor.putBoolean(WEDNESDAY_UPDATE, false);
            editor.putBoolean(FRIDAY_UPDATE, false);
            break;
        case Calendar.WEDNESDAY:
            editor.putBoolean(WEDNESDAY_UPDATE, found);
            editor.putBoolean(FRIDAY_UPDATE, false);
            editor.putBoolean(MONDAY_UPDATE, false);
            break;
        case Calendar.FRIDAY:
            editor.putBoolean(FRIDAY_UPDATE, found);
            editor.putBoolean(MONDAY_UPDATE, false);
            editor.putBoolean(WEDNESDAY_UPDATE, false);
            break;
    }
    editor.apply();
    Log.d("Update Status:", String.valueOf(sharedPrefs.getBoolean(MONDAY_UPDATE, false))
            + String.valueOf(sharedPrefs.getBoolean(WEDNESDAY_UPDATE, false))
            + String.valueOf(sharedPrefs.getBoolean(FRIDAY_UPDATE, false)));
}
 
Example 8
Source File: TimeUtil.java    From star-zone-android with Apache License 2.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 9
Source File: TimeWindowModel.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
protected int getCalendarDayFor(@NonNull DayOfWeek day) {
    switch (day) {
        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;

        default:
        case SUNDAY: return Calendar.SUNDAY;
    }
}
 
Example 10
Source File: PdfLegacyExamReport.java    From unitime with Apache License 2.0 5 votes vote down vote up
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 11
Source File: DateUtil.java    From xiaoV with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取一年开始的第一周的周一 第一周如果有四天或以上就算是该年的第一周, 否则就是上一年的最后一周(用于跨年判断第一周开始时间)
 *
 * @param year
 * @return
 */
public static Calendar getFirstDayOfWeek(int year) {
	Calendar c = new GregorianCalendar();
	c.set(year, Calendar.JANUARY, 1, 0, 0, 0);
	int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
	// 如果1月1日是周五,周六或者周日,那么这一周是上一年最后一周,重新计算今年的第一周开始的周一
	if (dayOfWeek == Calendar.FRIDAY || dayOfWeek == Calendar.SATURDAY
			|| dayOfWeek == Calendar.SUNDAY) {
		while (c.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
			c.add(Calendar.DAY_OF_YEAR, 1);
		}
	}
	return c;
}
 
Example 12
Source File: DateCalc.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static CalendarWeekVO getCalendarWeek(Date date) {
	GregorianCalendar cal = new GregorianCalendar();
	cal.setTime(date);
	int year = cal.get(Calendar.YEAR);
	int period;
	switch ((new GregorianCalendar(year, 0, 1)).get(Calendar.DAY_OF_WEEK)) {
		case Calendar.SUNDAY:
			period = -1;
			break;
		case Calendar.MONDAY:
			period = 0;
			break;
		case Calendar.TUESDAY:
			period = 1;
			break;
		case Calendar.WEDNESDAY:
			period = 2;
			break;
		case Calendar.THURSDAY:
			period = 3;
			break;
		case Calendar.FRIDAY:
			period = -3;
			break;
		case Calendar.SATURDAY:
			period = -2;
			break;
		default:
			period = 0;
	}
	int week = (int) ((cal.get(Calendar.DAY_OF_YEAR) - 1 + period) / 7d + 1);
	if (week > getWeeksOfYear(year)) {
		return new CalendarWeekVO(cal.getTime(), 1, year + 1);
	} else if (week == 0) {
		return new CalendarWeekVO(cal.getTime(), getWeeksOfYear(year - 1), year - 1);
	} else {
		return new CalendarWeekVO(cal.getTime(), week, year);
	}
}
 
Example 13
Source File: TimerHandler.java    From PowerSwitch_Android with GNU General Public License v3.0 5 votes vote down vote up
private static ArrayList<WeekdayTimer.Day> getExecutionDays(Long timerId) throws Exception {
    ArrayList<WeekdayTimer.Day> days = new ArrayList<>();

    String[] columns = {TimerWeekdayTable.COLUMN_EXECUTION_DAY};
    Cursor cursor = DatabaseHandler.database.query(TimerWeekdayTable.TABLE_NAME, columns,
            TimerWeekdayTable.COLUMN_TIMER_ID + "=" + timerId, null, null, null, null);

    cursor.moveToFirst();

    while (!cursor.isAfterLast()) {
        switch (cursor.getInt(0)) {
            case Calendar.MONDAY:
                days.add(WeekdayTimer.Day.MONDAY);
                break;
            case Calendar.TUESDAY:
                days.add(WeekdayTimer.Day.TUESDAY);
                break;
            case Calendar.WEDNESDAY:
                days.add(WeekdayTimer.Day.WEDNESDAY);
                break;
            case Calendar.THURSDAY:
                days.add(WeekdayTimer.Day.THURSDAY);
                break;
            case Calendar.FRIDAY:
                days.add(WeekdayTimer.Day.FRIDAY);
                break;
            case Calendar.SATURDAY:
                days.add(WeekdayTimer.Day.SATURDAY);
                break;
            case Calendar.SUNDAY:
                days.add(WeekdayTimer.Day.SUNDAY);
                break;
        }
        cursor.moveToNext();
    }

    cursor.close();
    return days;
}
 
Example 14
Source File: ConversionUtilsTest.java    From OpenRate with Apache License 2.0 5 votes vote down vote up
/**
 * Test of getDayOfWeek method, of class ConversionUtils.
 *
 * @throws java.text.ParseException
 */
@Test
public void testGetDayOfWeek() throws ParseException {
  long expResult;
  long result;
  long UTCDate;
  String amorphicDate;

  System.out.println("getDayOfWeek");

  // Test the standard date formats
  amorphicDate = "20120101000000";
  instance.setInputDateFormat("yyyyMMddhhmmss");
  UTCDate = instance.convertInputDateToUTC(amorphicDate);
  expResult = getUTCDateExpected(2012,1,1,0,0,0);
  Assert.assertEquals(expResult, expResult);

  result = instance.getDayOfWeek(UTCDate);

  // We expect 1 (Sunday)
  expResult = Calendar.SUNDAY;
  Assert.assertEquals(expResult, result);

  // now try rolling over
  amorphicDate = "20120106000000";
  UTCDate = instance.convertInputDateToUTC(amorphicDate);
  result = instance.getDayOfWeek(UTCDate);

  // We expect 6 (Friday)
  expResult = Calendar.FRIDAY;
  Assert.assertEquals(expResult, result);

  // now try rolling over
  UTCDate += 86400 * 2;
  result = instance.getDayOfWeek(UTCDate);

  // We expect 1 (Sunday)
  expResult = Calendar.SUNDAY;
  Assert.assertEquals(expResult, result);
}
 
Example 15
Source File: InstructorScheduleConnector.java    From unitime with Apache License 2.0 5 votes vote down vote up
protected static Date firstDate(DatePattern dp, int dayCode) {
   	if (dp == null) return null;
   	BitSet weekCode = dp.getPatternBitSet();
   	if (weekCode.isEmpty()) return null;
   	Calendar cal = Calendar.getInstance(Locale.US); cal.setLenient(true);
   	Date dpFirstDate = DateUtils.getDate(1, dp.getSession().getPatternStartMonth(), dp.getSession().getSessionStartYear());
   	cal.setTime(dpFirstDate);
   	int idx = weekCode.nextSetBit(0);
   	cal.add(Calendar.DAY_OF_YEAR, idx);
   	while (idx < weekCode.size()) {
   		if (weekCode.get(idx)) {
       		int dow = cal.get(Calendar.DAY_OF_WEEK);
       		switch (dow) {
       		case Calendar.MONDAY:
       			if ((dayCode & DayCode.MON.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.TUESDAY:
       			if ((dayCode & DayCode.TUE.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.WEDNESDAY:
       			if ((dayCode & DayCode.WED.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.THURSDAY:
       			if ((dayCode & DayCode.THU.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.FRIDAY:
       			if ((dayCode & DayCode.FRI.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.SATURDAY:
       			if ((dayCode & DayCode.SAT.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.SUNDAY:
       			if ((dayCode & DayCode.SUN.getCode()) != 0) return cal.getTime();
       			break;
       		}
       	}
   		cal.add(Calendar.DAY_OF_YEAR, 1); idx++;
   	}
   	return null;
}
 
Example 16
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 17
Source File: EditMeeting.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private void retrieveRecurrenceData(List<SignupMeeting> upTodateOrginMeetings) {
	/*to see if the recurring events have a 'Start_Now' type already*/
	this.isStartNowTypeForRecurEvents = Utilities.testSignupBeginStartNowType(upTodateOrginMeetings);
	 
	String repeatType = upTodateOrginMeetings.get(0).getRepeatType();
	if(repeatType !=null && !ONCE_ONLY.equals(repeatType)){
		int lSize = upTodateOrginMeetings.size();
		setLastRecurMeetingModifyDate(upTodateOrginMeetings.get(lSize - 1).getStartTime());
		setRecurringType(repeatType);
		return;
	}
		
	/*The following code is to make it old version backward compatible*/
	setFirstRecurMeetingModifyDate(null);
	setLastRecurMeetingModifyDate(null);
	if (upTodateOrginMeetings == null || upTodateOrginMeetings.isEmpty())
		return;

	setFirstRecurMeetingModifyDate(upTodateOrginMeetings.get(0).getStartTime());
	/* in case: it's the last one */
	setLastRecurMeetingModifyDate(upTodateOrginMeetings.get(0).getStartTime());

	int listSize = upTodateOrginMeetings.size();
	if (listSize > 1) {
		setLastRecurMeetingModifyDate(upTodateOrginMeetings.get(listSize - 1).getStartTime());
		Calendar calFirst = Calendar.getInstance();
		Calendar calSecond = Calendar.getInstance();
		/*
		 * we can only get approximate estimation by assuming it's a
		 * succession
		 */
		calFirst.setTime(upTodateOrginMeetings.get(listSize - 2).getStartTime());
		calFirst.set(Calendar.SECOND, 0);
		calFirst.set(Calendar.MILLISECOND, 0);
		calSecond.setTime(upTodateOrginMeetings.get(listSize - 1).getStartTime());
		calSecond.set(Calendar.SECOND, 0);
		calSecond.set(Calendar.MILLISECOND, 0);
		int tmp = calSecond.get(Calendar.DATE);
		int daysDiff = (int) (calSecond.getTimeInMillis() - calFirst.getTimeInMillis()) / DAY_IN_MILLISEC;
		if (daysDiff == perDay)
			setRecurringType(DAILY);
		else if (daysDiff == perWeek)
			setRecurringType(WEEKLY);
		else if (daysDiff == perBiweek)
			setRecurringType(BIWEEKLY);
		else if(daysDiff ==3 && calFirst.get(Calendar.DAY_OF_WEEK)== Calendar.FRIDAY)
			setRecurringType(WEEKDAYS);
	}
}
 
Example 18
Source File: TimetableGridSolutionHelper.java    From unitime with Apache License 2.0 4 votes vote down vote up
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 19
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;
    }

    switch (week) {
        case Calendar.MONDAY:
            weekDay = getString(R.string.one);
            break;
        case Calendar.TUESDAY:
            weekDay = getString(R.string.two);
            break;
        case Calendar.WEDNESDAY:
            weekDay = getString(R.string.three);
            break;
        case Calendar.THURSDAY:
            weekDay = getString(R.string.four);
            break;
        case Calendar.FRIDAY:
            weekDay = getString(R.string.five);
            break;
        case Calendar.SATURDAY:
            weekDay = getString(R.string.six);
            break;
        case Calendar.SUNDAY:
            weekDay = getString(R.string.sunday);
            break;
        default:
            weekDay = "";
            break;
    }

    mTimeText.setText(hour + ":" + minute);
    mDateText.setText(year + getString(R.string.year) + month
            + getString(R.string.month) + date + getString(R.string.day_and_week) + weekDay);
    mHandler.removeMessages(HANDLER_CODE_REFRESH_TIME);
    mHandler.sendEmptyMessageDelayed(HANDLER_CODE_REFRESH_TIME, 1000);
}
 
Example 20
Source File: Data.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
public List <String> getReduction () {
	List <String>	rc = new ArrayList <> ();
	
	if (maildropStatus.isAdminMailing () || maildropStatus.isTestMailing ()) {
		String	sql = maildropStatus.getAdminTestSQL ();
		
		if (sql != null) {
			rc.add (sql);
		}
	}
	if (maildropStatus.isWorldMailing () || maildropStatus.isRuleMailing () || maildropStatus.isOnDemandMailing ()) {
		String	expr = company.infoSubstituted ("fixed-target-clause", mailing.id ());
		
		if ((expr != null) && (! expr.equals ("-"))) {
			rc.add (expr);
		}
	}
	if (maildropStatus.isWorldMailing ()) {
		String	column = company.infoSubstituted ("column-restrict-sending-per-day", mailing.id ());
		
		if ((column != null) && (! column.equals ("-"))) {
			if (column.indexOf ('.') == -1) {
				column = "cust." + column;
			}

			StringBuffer	buf = new StringBuffer ();
			Calendar	now = Calendar.getInstance ();
			int		wday = now.get (Calendar.DAY_OF_WEEK);

			buf.append (column + " IS NULL OR " + column + " LIKE '");
			for (int day = 0; day < 7; ++day) {
				int	cmp = -1;
	
				switch (day) {
					case 0:
						cmp = Calendar.MONDAY;
						break;
					case 1:
						cmp = Calendar.TUESDAY;
						break;
					case 2:
						cmp = Calendar.WEDNESDAY;
						break;
					case 3:
						cmp = Calendar.THURSDAY;
						break;
					case 4:
						cmp = Calendar.FRIDAY;
						break;
					case 5:
						cmp = Calendar.SATURDAY;
						break;
					case 6:
						cmp = Calendar.SUNDAY;
						break;
					default:
						break;
				}
				buf.append (cmp == wday ? '1' : '_');
			}
			buf.append ("'");
			rc.add (buf.toString ());
		}
	}
	return rc;
}