List of usage examples for java.util Calendar MONDAY
int MONDAY
To view the source code for java.util Calendar MONDAY.
Click Source Link
From source file:com.espertech.esper.regression.pattern.TestCronParameter.java
private int getLastWeekDayOfMonth(Integer day, int year) { int computeDay = (day == null) ? getLastDayOfMonth(year) : day; setTime(year);/*from w w w . j a v a 2 s . c o m*/ if (!checkDayValidInMonth(computeDay, calendar.get(Calendar.MONTH), calendar.get(Calendar.YEAR))) { throw new IllegalArgumentException("Invalid day for " + calendar.get(Calendar.MONTH)); } calendar.set(Calendar.DAY_OF_MONTH, computeDay); int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); if ((dayOfWeek >= Calendar.MONDAY) && (dayOfWeek <= Calendar.FRIDAY)) { return computeDay; } if (dayOfWeek == Calendar.SATURDAY) { if (computeDay == 1) { calendar.add(Calendar.DAY_OF_MONTH, +2); } else { calendar.add(Calendar.DAY_OF_MONTH, -1); } } if (dayOfWeek == Calendar.SUNDAY) { if ((computeDay == 28) || (computeDay == 29) || (computeDay == 30) || (computeDay == 31)) { calendar.add(Calendar.DAY_OF_MONTH, -2); } else { calendar.add(Calendar.DAY_OF_MONTH, +2); } } return calendar.get(Calendar.DAY_OF_MONTH); }
From source file:Time.java
/** * Get default locale name of this day ("Monday", "Tuesday", etc. * //from ww w.j av a 2 s .c o m * @return Name of day. */ public String getDayName() { switch (getDayOfWeek()) { case Calendar.MONDAY: return "Monday"; case Calendar.TUESDAY: return "Tuesday"; case Calendar.WEDNESDAY: return "Wednesday"; case Calendar.THURSDAY: return "Thursday"; case Calendar.FRIDAY: return "Friday"; case Calendar.SATURDAY: return "Saturday"; case Calendar.SUNDAY: return "Sunday"; } // This will never happen return null; }
From source file:org.sakaiproject.tool.section.jsf.backingbean.AddSectionsBean.java
public String getMonday() { return daysOfWeek[Calendar.MONDAY]; }
From source file:com.frey.repo.DateUtil.java
/***************************************** * @ ??//from w w w . j ava2 s. c om ****************************************/ public static String getYearWeekFirstDay(Date curDate) { Calendar cal = Calendar.getInstance(); cal.setTime(curDate); if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { cal.set(Calendar.WEEK_OF_YEAR, cal.get(Calendar.WEEK_OF_YEAR) - 1); } else { cal.set(Calendar.WEEK_OF_YEAR, cal.get(Calendar.WEEK_OF_YEAR)); } cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); String tempYear = Integer.toString(cal.get(Calendar.YEAR)); String tempMonth = Integer.toString(cal.get(Calendar.MONTH) + 1); String tempDay = Integer.toString(cal.get(Calendar.DATE)); String tempDate = tempYear + "-" + tempMonth + "-" + tempDay; return setDateFormat(tempDate, "yyyy-MM-dd"); }
From source file:org.jasig.schedassist.model.AvailableBlockBuilder.java
/** * Returns a {@link List} of {@link Date} objects that fall between startDate and endDate and * exist on the days specified by daysOfWeekPhrase. * //ww w . j a v a 2 s.c om * For instance, passing "MWF", a start Date of June 30 2008, and an end Date of July 04 2008, this * method will return a list of 3 Date objects (one for Monday June 30, one for Wednesday July 2, and * one for Friday July 4). * * The time values for returned {@link Date}s will always be 00:00:00 (in the JVM's default timezone). * * @param daysOfWeekPhrase * @param startDate * @param endDate * @return a {@link List} of {@link Date} objects that fall between startDate and endDate and * exist on the days specified by daysOfWeekPhrase. */ protected static List<Date> matchingDays(final String daysOfWeekPhrase, final Date startDate, final Date endDate) { List<Date> matchingDays = new ArrayList<Date>(); Set<Integer> daysOfWeek = new HashSet<Integer>(); for (char character : daysOfWeekPhrase.toUpperCase().toCharArray()) { switch (character) { case 'N': daysOfWeek.add(Calendar.SUNDAY); break; case 'M': daysOfWeek.add(Calendar.MONDAY); break; case 'T': daysOfWeek.add(Calendar.TUESDAY); break; case 'W': daysOfWeek.add(Calendar.WEDNESDAY); break; case 'R': daysOfWeek.add(Calendar.THURSDAY); break; case 'F': daysOfWeek.add(Calendar.FRIDAY); break; case 'S': daysOfWeek.add(Calendar.SATURDAY); break; } } Calendar current = Calendar.getInstance(); current.setTime(startDate); // set the time to 00:00:00 to insure the time doesn't affect our comparison) // (because there may be a valid time window on endDate) current = CommonDateOperations.zeroOutTimeFields(current); while (current.getTime().compareTo(endDate) < 0) { if (daysOfWeek.contains(current.get(Calendar.DAY_OF_WEEK))) { matchingDays.add(current.getTime()); } // increment currentDate +1 day current.add(Calendar.DATE, 1); } return matchingDays; }
From source file:org.kuali.student.r2.core.scheduling.service.impl.TestSchedulingServiceImpl.java
@Test public void testgetTimeSlotsByIds() throws Exception { // test case: all valid ids List<String> valid_ids = new ArrayList<String>(); valid_ids.add("ts102"); valid_ids.add("ts115"); List<TimeSlotInfo> l_valid_ts = schedulingService.getTimeSlotsByIds(valid_ids, contextInfo); assertEquals(2, valid_ids.size());/*from w ww. ja v a2s .c o m*/ TimeSlot ts2 = null, ts15 = null; // ensure the list has only time slots with ids 2 and 15 for (TimeSlotInfo ts : l_valid_ts) { assertTrue(valid_ids.contains(ts.getId())); if (ts.getId().equals("ts102")) { ts2 = ts; } else { ts15 = ts; } } assertNotNull(ts2); assertEquals("ts102", ts2.getId()); List<Integer> dow = ts2.getWeekdays(); // should contain Monday, Wednesday, Friday assertTrue(dow.contains(Calendar.MONDAY)); assertTrue(dow.contains(Calendar.WEDNESDAY)); assertTrue(dow.contains(Calendar.FRIDAY)); // should not contain Tuesday or Thursday assertFalse(dow.contains(Calendar.TUESDAY)); assertFalse(dow.contains(Calendar.THURSDAY)); assertEquals(ts2.getStartTime(), TOD_8_AM); assertEquals(ts2.getEndTime(), TOD_9_10_AM); assertNotNull(ts15); assertEquals("ts115", ts15.getId()); dow = ts15.getWeekdays(); // should not contain Monday, Wednesday, Friday assertFalse(dow.contains(Calendar.MONDAY)); assertFalse(dow.contains(Calendar.WEDNESDAY)); assertFalse(dow.contains(Calendar.FRIDAY)); // should contain Tuesday or Thursday assertTrue(dow.contains(Calendar.TUESDAY)); assertTrue(dow.contains(Calendar.THURSDAY)); assertEquals(ts15.getStartTime(), TOD_3_PM); assertEquals(ts15.getEndTime(), TOD_3_50_PM); // test case: all invalid ids List<String> invalid_ids = new ArrayList<String>(); invalid_ids.add("bad1"); invalid_ids.add("bad2"); try { schedulingService.getTimeSlotsByIds(invalid_ids, contextInfo); fail("Should not be here - test invalid_ids"); } catch (DoesNotExistException e) { assertNotNull(e.getMessage()); assertEquals("No data was found for : bad1, bad2", e.getMessage()); } // test case: mixture of valid and invalid List<String> mix_ids = new ArrayList<String>(); mix_ids.add("ts110"); mix_ids.add("bad1"); try { schedulingService.getTimeSlotsByIds(mix_ids, contextInfo); fail("Should not be here - test mix_ids"); } catch (DoesNotExistException e) { assertNotNull(e.getMessage()); assertEquals("Missing data for : bad1", e.getMessage()); } }
From source file:com.espertech.esper.schedule.ScheduleComputeHelper.java
private static boolean isWeekday(Calendar cal) { int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); return !(dayOfWeek < Calendar.MONDAY || dayOfWeek > Calendar.FRIDAY); }
From source file:org.ejbca.ui.web.admin.certprof.CertProfileBean.java
public boolean isExpirationRestrictionMonday() throws AuthorizationDeniedException { return getCertificateProfile().getExpirationRestrictionWeekday(Calendar.MONDAY); }
From source file:com.embeddedlog.LightUpDroid.LightUpPiSync.java
private Alarm alarmFromJson(JSONObject aJson) { // If mSelectedAlarm is null then we're creating a new alarm. Alarm alarm = new Alarm(); alarm.alert = RingtoneManager.getActualDefaultRingtoneUri(mActivityContext, RingtoneManager.TYPE_ALARM); if (alarm.alert == null) { alarm.alert = Uri.parse("content://settings/system/alarm_alert"); }//from w w w. j a v a2 s.c o m // Setting the vibrate option to always true, as there is no attribute in LightUpPi alarm.vibrate = true; // Setting the 'delete after use' option to always false, as there is no such feature in // the LightUpPi alarm system and all alarms are repeatable alarm.deleteAfterUse = false; // Parsing the JSON data try { alarm.hour = aJson.getInt("hour"); alarm.minutes = aJson.getInt("minute"); alarm.enabled = aJson.getBoolean("enabled"); alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("monday"), Calendar.MONDAY); alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("tuesday"), Calendar.TUESDAY); alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("wednesday"), Calendar.WEDNESDAY); alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("thursday"), Calendar.THURSDAY); alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("friday"), Calendar.FRIDAY); alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("saturday"), Calendar.SATURDAY); alarm.daysOfWeek.setDaysOfWeek(aJson.getBoolean("sunday"), Calendar.SUNDAY); alarm.label = aJson.getString("label"); alarm.lightuppiId = aJson.getLong("id"); alarm.timestamp = aJson.getLong("timestamp"); } catch (JSONException e) { Log.w(LOG_TAG + " JSONException: " + e.toString()); alarm = null; } return alarm; }
From source file:org.power.commons.lang.util.time.DateUtils.java
/** * ??//from www . j a va2s . com * * @param date * @return * @author yang_yun */ public static Date getFirstDayOfLastWeek(Date date) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(date.getTime() - 604800000L); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); Date lastWeekDate = c.getTime(); c = new GregorianCalendar(); c.setFirstDayOfWeek(Calendar.MONDAY); c.setTime(new Date(lastWeekDate.getTime())); c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); // Monday return c.getTime(); }