Java Code Examples for java.util.Calendar.SUNDAY

The following are Jave code examples for showing how to use SUNDAY 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: 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 2
Project: unitimes   File: Event.java   View Source Code Vote up 7 votes
public String getDays(String[] dayNames, String[] shortDyNames) {
    int nrDays = 0;
    int dayCode = 0;
    for (Meeting meeting : getMeetings()) {
        int dc = 0;
        switch (meeting.getDayOfWeek()) {
           case Calendar.MONDAY    : dc = Constants.DAY_CODES[Constants.DAY_MON]; break;
           case Calendar.TUESDAY   : dc = Constants.DAY_CODES[Constants.DAY_TUE]; break;
           case Calendar.WEDNESDAY : dc = Constants.DAY_CODES[Constants.DAY_WED]; break;
           case Calendar.THURSDAY  : dc = Constants.DAY_CODES[Constants.DAY_THU]; break;
           case Calendar.FRIDAY    : dc = Constants.DAY_CODES[Constants.DAY_FRI]; break;
           case Calendar.SATURDAY  : dc = Constants.DAY_CODES[Constants.DAY_SAT]; break;
           case Calendar.SUNDAY    : dc = Constants.DAY_CODES[Constants.DAY_SUN]; break;
        }
        if ((dayCode & dc)==0) nrDays++;
        dayCode |= dc;
    }
       String ret = "";
    for (int i=0;i<Constants.DAY_CODES.length;i++) {
        if ((dayCode & Constants.DAY_CODES[i])!=0)
            ret += (nrDays==1?dayNames:shortDyNames)[i];
    }
       return ret;
}
 
Example 3
Project: unitimes   File: Constants.java   View Source Code Vote up 7 votes
public static int getDayOfWeek(Date date) {
  	Calendar c = Calendar.getInstance(Locale.US);
  	c.setTime(date);
switch (c.get(Calendar.DAY_OF_WEEK)) {
case Calendar.MONDAY:
	return DAY_MON;
case Calendar.TUESDAY:
	return DAY_TUE;
case Calendar.WEDNESDAY:
	return DAY_WED;
case Calendar.THURSDAY:
	return DAY_THU;
case Calendar.FRIDAY:
	return DAY_FRI;
case Calendar.SATURDAY:
	return DAY_SAT;
case Calendar.SUNDAY:
	return DAY_SUN;
default:
	return DAY_MON;
}
  }
 
Example 4
Project: wisebite_android   File: GetRestaurantActivity.java   View Source Code Vote up 7 votes
/**
 * Get text view regarding a date
 * @param date date 
 * @return text view
 */
private int getTextView(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    switch (calendar.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.MONDAY:
            return R.id.monday_open_time;
        case Calendar.TUESDAY:
            return R.id.tuesday_open_time;
        case Calendar.WEDNESDAY:
            return R.id.wednesday_open_time;
        case Calendar.THURSDAY:
            return R.id.thursday_open_time;
        case Calendar.FRIDAY:
            return R.id.friday_open_time;
        case Calendar.SATURDAY:
            return R.id.saturday_open_time;
        case Calendar.SUNDAY:
            return R.id.sunday_open_time;
    }
    return 0;
}
 
Example 5
Project: MyFire   File: TimeUtil.java   View Source Code Vote up 7 votes
/**
 * 描述:获取本周的某一天.
 *
 * @param format        the format
 * @param calendarField the calendar field
 * @return String String类型日期时间
 */
private static String getDayOfWeek(String format, int calendarField) {
    String strDate = null;
    try {
        Calendar c = new GregorianCalendar();
        SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
        int week = c.get(Calendar.DAY_OF_WEEK);
        if (week == calendarField) {
            strDate = mSimpleDateFormat.format(c.getTime());
        } else {
            int offectDay = calendarField - week;
            if (calendarField == Calendar.SUNDAY) {
                offectDay = 7 - Math.abs(offectDay);
            }
            c.add(Calendar.DATE, offectDay);
            strDate = mSimpleDateFormat.format(c.getTime());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return strDate;
}
 
Example 6
Project: wisebite_android   File: Utils.java   View Source Code Vote up 7 votes
public static int parseViewIdToDayOfWeek(Integer viewId) {
    switch (viewId) {
        case R.id.monday_date_picker:
            return Calendar.MONDAY;
        case R.id.tuesday_date_picker:
            return Calendar.TUESDAY;
        case R.id.wednesday_date_picker:
            return Calendar.WEDNESDAY;
        case R.id.thursday_date_picker:
            return Calendar.THURSDAY;
        case R.id.friday_date_picker:
            return Calendar.FRIDAY;
        case R.id.saturday_date_picker:
            return Calendar.SATURDAY;
        case R.id.sunday_date_picker:
            return Calendar.SUNDAY;
        default:
            return 0;
    }
}
 
Example 7
Project: workdays   File: BridgeDayFilter.java   View Source Code Vote up 7 votes
@Override
protected boolean checkWorkday(Calendar cal) {
    Calendar dayBefore = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
    dayBefore.add(Calendar.DATE, -1);

    Calendar dayAfter = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
    dayAfter.add(Calendar.DATE, 1);

    // if day before cal is a holiday and the day after cal is saturday
    // then cal is a bridge day (means: no work day)
    if(this.holidayProvider.isHoliday(dayBefore) && dayAfter.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
        return false;
    }

    // if day before cal is a sunday and the day after cal is a holiday
    // then cal is a bridge day (means: no work day)
    if(dayBefore.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY && this.holidayProvider.isHoliday(dayAfter)) {
        return false;
    }

    return true;
}
 
Example 8
Project: openjdk-jdk10   File: DateTimeTextProvider.java   View Source Code Vote up 6 votes
private static int toWeekDay(int calWeekDay) {
    if (calWeekDay == Calendar.SUNDAY) {
        return 7;
    } else {
        return calWeekDay - 1;
    }
}
 
Example 9
Project: xxpay-master   File: DateUtil.java   View Source Code Vote up 6 votes
/**
 * 根据日期,返回其星期数,周一为1,周日为7
 * @param date
 * @return
 */
public static int getWeekDay(Date date) {
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(date);
	int w = calendar.get(Calendar.DAY_OF_WEEK);
	int ret;
	if (w == Calendar.SUNDAY)
		ret = 7;
	else
		ret = w - 1;
	return ret;
}
 
Example 10
Project: MyCalendar   File: WeekLesson.java   View Source Code Vote up 6 votes
/**
 * Full params constructor
 */
public WeekLesson(int week_lesson_id, @Nonnull String subject_id, int repeat_id, @Nonnegative int week_lesson_day_start,
                  @Nonnegative int week_lesson_day_end, @Nonnegative int week_lesson_day_index) {
    if (week_lesson_id > 0) {
        this.week_lesson_id = week_lesson_id;
    } else {
        this.week_lesson_id = Constant.INT_NONE_VALUE;
    }
    this.subject_id = subject_id;
    if (repeat_id > 0) {
        this.repeat_id = repeat_id;
    } else {
        this.repeat_id = Constant.INT_NONE_VALUE;
    }
    if (week_lesson_day_start >= 0) {
        this.week_lesson_day_start = week_lesson_day_start;
    }else {
        this.week_lesson_day_start = 0;
    }
    if (!(week_lesson_day_end >= this.week_lesson_day_start)) {
        this.week_lesson_day_end = week_lesson_day_end;
    }else {
        this.week_lesson_day_end = this.week_lesson_day_start;
    }
    if (week_lesson_day_index >= Calendar.SUNDAY && week_lesson_day_index <= Calendar.SATURDAY) {
        this.week_lesson_day_index = week_lesson_day_index;
    }
}
 
Example 11
Project: pay-xxpay-master   File: DateUtil.java   View Source Code Vote up 6 votes
/**
 * 根据日期,返回其星期数,周一为1,周日为7
 * @param date
 * @return
 */
public static int getWeekDay(Date date) {
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(date);
	int w = calendar.get(Calendar.DAY_OF_WEEK);
	int ret;
	if (w == Calendar.SUNDAY)
		ret = 7;
	else
		ret = w - 1;
	return ret;
}
 
Example 12
Project: android-bluetooth-current-time-service   File: TimeData.java   View Source Code Vote up 6 votes
static byte[] exactTime256WithUpdateReason(Calendar time, byte updateReason) {
    // See https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.current_time.xml

    // Calendar: January = 0
    // CTS: January = 1
    int month = time.get(Calendar.MONTH) + 1;

    // Calendar: Monday = 2, Sunday = 1
    // CTS: Monday = 1, Sunday = 7
    int dayOfWeek = time.get(Calendar.DAY_OF_WEEK);
    if (dayOfWeek == Calendar.SUNDAY) {
        dayOfWeek = 7;
    } else {
        dayOfWeek = dayOfWeek - 1;
    }

    // 256ths of a second
    int fractionsOfSecond = (int)((time).get(Calendar.MILLISECOND) * 0.255F);

    return ByteBuffer.allocate(10)
            .order(ByteOrder.LITTLE_ENDIAN)
            .putShort((short) time.get(Calendar.YEAR))
            .put((byte) month)
            .put((byte) time.get(Calendar.DAY_OF_MONTH))
            .put((byte) time.get(Calendar.HOUR_OF_DAY))
            .put((byte) time.get(Calendar.MINUTE))
            .put((byte) time.get(Calendar.SECOND))
            .put((byte) dayOfWeek)
            .put((byte) fractionsOfSecond)
            .put(updateReason)
            .array();
}
 
Example 13
Project: OSchina_resources_android   File: DatePickerDialog.java   View Source Code Vote up 6 votes
public void setFirstDayOfWeek(int startOfWeek) {
    if (startOfWeek < Calendar.SUNDAY || startOfWeek > Calendar.SATURDAY) {
        throw new IllegalArgumentException(
                "Value must be between Calendar.SUNDAY and "
                        + "Calendar.SATURDAY");
    }
    mWeekStart = startOfWeek;
    if (mDayPickerView != null) {
        mDayPickerView.onChange();
    }
}
 
Example 14
Project: AlipayWechatPlatform   File: DateUtil.java   View Source Code Vote up 6 votes
/**
 * 根据日期,返回其星期数,周一为1,周日为7
 * @param date
 * @return
 */
public static int getWeekDay(Date date) {
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(date);
	int w = calendar.get(Calendar.DAY_OF_WEEK);
	int ret;
	if (w == Calendar.SUNDAY)
		ret = 7;
	else
		ret = w - 1;
	return ret;
}
 
Example 15
Project: OpenJSharp   File: DateTimeTextProvider.java   View Source Code Vote up 6 votes
private static int toWeekDay(int calWeekDay) {
    if (calWeekDay == Calendar.SUNDAY) {
        return 7;
    } else {
        return calWeekDay - 1;
    }
}
 
Example 16
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 17
Project: LucaHome-MediaServer   File: MainService.java   View Source Code Vote up 6 votes
private void checkCurrentTime() {
    Calendar now = Calendar.getInstance();

    int second = now.get(Calendar.SECOND);
    int minute = now.get(Calendar.MINUTE);
    int hour = now.get(Calendar.HOUR_OF_DAY);
    int weekday = now.get(Calendar.DAY_OF_WEEK);

    boolean isWeekend = weekday == Calendar.SUNDAY || weekday == Calendar.SATURDAY;

    _logger.Debug(String.format(Locale.GERMAN,
            "checkCurrentTime at %02d:%02d:%02d on %d",
            hour, minute, second, weekday));

    if ((second >= 0 && second < 5) && minute == 0) {
        for (AutomaticSettings entry : AutomaticSettings.values()) {
            if (entry.GetEnableHour() == hour) {
                if ((entry.IsWeekend() && isWeekend) || (!entry.IsWeekend() && !isWeekend)) {
                    int maxVolume = _mediaVolumeController.GetMaxVolume();
                    double currentVolume = (entry.GetSoundVolumePercentage() / 100) * maxVolume;
                    setSettings(currentVolume, (int) entry.GetScreenBrightnessPercentage());
                    break;
                }
            }
        }
    }
}
 
Example 18
Project: EsperantoRadio   File: RepeatPreference.java   View Source Code Vote up 6 votes
public RepeatPreference(Context context, AttributeSet attrs) {
  super(context, attrs);

  String[] weekdays = new DateFormatSymbols().getWeekdays();
  String[] values = new String[]{
      weekdays[Calendar.MONDAY],
      weekdays[Calendar.TUESDAY],
      weekdays[Calendar.WEDNESDAY],
      weekdays[Calendar.THURSDAY],
      weekdays[Calendar.FRIDAY],
      weekdays[Calendar.SATURDAY],
      weekdays[Calendar.SUNDAY],};
  setEntries(values);
  setEntryValues(values);
}
 
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: 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;
}