List of usage examples for java.util Calendar SATURDAY
int SATURDAY
To view the source code for java.util Calendar SATURDAY.
Click Source Link
From source file:org.davidmendoza.esu.service.impl.InicioServiceImpl.java
private Integer obtieneDia(String dia) { switch (dia) { case "domingo": return Calendar.SUNDAY; case "lunes": return Calendar.MONDAY; case "martes": return Calendar.TUESDAY; case "miercoles": return Calendar.WEDNESDAY; case "jueves": return Calendar.THURSDAY; case "viernes": return Calendar.FRIDAY; default:/*www .j ava 2 s .c o m*/ return Calendar.SATURDAY; } }
From source file:com.netflix.simianarmy.basic.BasicCalendar.java
private boolean isWeekend(Calendar calendar) { int dow = calendar.get(Calendar.DAY_OF_WEEK); return dow == Calendar.SATURDAY || dow == Calendar.SUNDAY; }
From source file:com.xumpy.timesheets.services.implementations.JobsSrvImpl.java
public static boolean jobInWeekend(Jobs jobs) { Date date = jobs.getJobDate(); Calendar cal = Calendar.getInstance(); cal.setTime(date);//from ww w. ja v a 2s .c om if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) { return true; } return false; }
From source file:voldemort.scheduled.DataCleanupJobTest.java
public void testCleanupStartTime() { // Make sure the default is always the next day. GregorianCalendar cal = new GregorianCalendar(); assertEquals("Default is not tomorrow", Utils.getDayOfTheWeekFromNow(1), (cal.get(Calendar.DAY_OF_WEEK) + 1) % 7); // When starting the server any day in the week from SUN to FRI and // targeting a saturday, should always start on the next saturday GregorianCalendar expectedStart = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 29, 0, 0, 0); Random rand = new Random(); for (int day = Calendar.SUNDAY; day <= Calendar.FRIDAY; day++) { GregorianCalendar serverStartTime = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 22 + day, rand.nextInt(24), rand.nextInt(60), rand.nextInt(60)); GregorianCalendar computedStart = Utils.getCalendarForNextRun(serverStartTime, Calendar.SATURDAY, 0); assertEquals(//from ww w . j a v a 2 s. co m "Expected :" + expectedStart.getTimeInMillis() + " Computed: " + computedStart.getTimeInMillis(), expectedStart.getTimeInMillis(), computedStart.getTimeInMillis()); } // Targeting saturday, 00:00 and starting on a friday 23:59:59 should // start the next saturday GregorianCalendar serverStartTime = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 28, 23, 59, 59); GregorianCalendar computedStart = Utils.getCalendarForNextRun(serverStartTime, Calendar.SATURDAY, 0); assertEquals( "Expected :" + expectedStart.getTimeInMillis() + " Computed: " + computedStart.getTimeInMillis(), expectedStart.getTimeInMillis(), computedStart.getTimeInMillis()); // If we start past the start hour on the target day, it should start // the next week serverStartTime = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 29, 1, 0, 1); computedStart = Utils.getCalendarForNextRun(serverStartTime, Calendar.SATURDAY, 0); assertEquals(Calendar.SATURDAY, computedStart.get(Calendar.DAY_OF_WEEK)); assertEquals(serverStartTime.get(Calendar.DAY_OF_YEAR) + 7, computedStart.get(Calendar.DAY_OF_YEAR)); }
From source file:com.autentia.tnt.manager.holiday.UserHolidaysStateManager.java
public UserHolidaysState calcUserHolidaysState(User usuario, Date chargeYear) { UserHolidaysState uhs = new UserHolidaysState(); uhs.setUser(usuario);// w w w . j a v a 2s. co m // WorkingAgreement attribute is an HB proxy not initialized, we need to get it from DB WorkingAgreementDAO workingAgreementDao = WorkingAgreementDAO.getDefault(); WorkingAgreement agreement = workingAgreementDao.getById(usuario.getAgreement().getId()); // and refresh the user instance agreement attribute usuario.setAgreement(agreement); uhs.setTotalYear(agreement.getHolidays()); int acceptedHolidays = 0; if (chargeYear != null) { HolidayManager fiestasManager = HolidayManager.getDefault(); // We must take in account previous year holidays and next year holidays Calendar calMin = Calendar.getInstance(); calMin.setTime(chargeYear); calMin.set(Calendar.MONTH, calMin.getMinimum(Calendar.MONTH)); calMin.set(Calendar.DAY_OF_MONTH, calMin.getMinimum(Calendar.DAY_OF_MONTH)); calMin.set(Calendar.HOUR_OF_DAY, calMin.getMinimum(Calendar.HOUR_OF_DAY)); calMin.set(Calendar.MINUTE, calMin.getMinimum(Calendar.MINUTE)); calMin.set(Calendar.SECOND, calMin.getMinimum(Calendar.SECOND)); calMin.set(Calendar.MILLISECOND, calMin.getMinimum(Calendar.MILLISECOND)); Calendar calMax = Calendar.getInstance(); calMax.setTime(chargeYear); calMax.set(Calendar.MONTH, calMax.getMaximum(Calendar.MONTH)); calMax.set(Calendar.DAY_OF_MONTH, calMax.getMaximum(Calendar.DAY_OF_MONTH)); calMax.set(Calendar.HOUR_OF_DAY, calMax.getMaximum(Calendar.HOUR_OF_DAY)); calMax.set(Calendar.MINUTE, calMax.getMaximum(Calendar.MINUTE)); calMax.set(Calendar.SECOND, calMax.getMaximum(Calendar.SECOND)); calMax.set(Calendar.MILLISECOND, calMax.getMaximum(Calendar.MILLISECOND)); calMin.add(Calendar.YEAR, -1); calMax.add(Calendar.YEAR, 1); HolidaySearch fiestaSearch = new HolidaySearch(); fiestaSearch.setStartDate(calMin.getTime()); fiestaSearch.setEndDate(calMax.getTime()); List<Holiday> listFiestas = fiestasManager.getAllEntities(fiestaSearch, null); calMin.setTime(chargeYear); calMin.set(Calendar.MONTH, calMin.getMinimum(Calendar.MONTH)); calMin.set(Calendar.DAY_OF_MONTH, calMin.getMinimum(Calendar.DAY_OF_MONTH)); calMin.set(Calendar.HOUR_OF_DAY, calMin.getMinimum(Calendar.HOUR_OF_DAY)); calMin.set(Calendar.MINUTE, calMin.getMinimum(Calendar.MINUTE)); calMin.set(Calendar.SECOND, calMin.getMinimum(Calendar.SECOND)); calMin.set(Calendar.MILLISECOND, calMin.getMinimum(Calendar.MILLISECOND)); calMax.setTime(chargeYear); calMax.set(Calendar.MONTH, calMax.getMaximum(Calendar.MONTH)); calMax.set(Calendar.DAY_OF_MONTH, calMax.getMaximum(Calendar.DAY_OF_MONTH)); calMax.set(Calendar.HOUR_OF_DAY, calMax.getMaximum(Calendar.HOUR_OF_DAY)); calMax.set(Calendar.MINUTE, calMax.getMaximum(Calendar.MINUTE)); calMax.set(Calendar.SECOND, calMax.getMaximum(Calendar.SECOND)); calMax.set(Calendar.MILLISECOND, calMax.getMaximum(Calendar.MILLISECOND)); RequestHolidayManager holyManager = RequestHolidayManager.getDefault(); RequestHolidaySearch holSearch = new RequestHolidaySearch(); holSearch.setUserRequest(uhs.getUser()); holSearch.setState(HolidayState.ACCEPT); holSearch.setStartChargeYear(calMin.getTime()); holSearch.setEndChargeYear(calMax.getTime()); List<RequestHoliday> listH = holyManager.getAllEntities(holSearch, null); for (RequestHoliday rH : listH) { Calendar cActual = Calendar.getInstance(); cActual.setTime(rH.getBeginDate()); while (!cActual.getTime().after(rH.getFinalDate())) { if (cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) { boolean isFiesta = false; for (Holiday fiest : listFiestas) { Calendar cFiesta = Calendar.getInstance(); cFiesta.setTime(fiest.getDate()); if (cFiesta.get(Calendar.YEAR) == cActual.get(Calendar.YEAR) && cFiesta.get(Calendar.MONTH) == cActual.get(Calendar.MONTH) && cFiesta.get(Calendar.DAY_OF_MONTH) == cActual.get(Calendar.DAY_OF_MONTH)) { isFiesta = true; } } if (!isFiesta) { acceptedHolidays++; } } cActual.add(Calendar.DAY_OF_MONTH, 1); } } uhs.setTotalAccepted(acceptedHolidays); Calendar calAuxCont = Calendar.getInstance(); calAuxCont.setTime(uhs.getUser().getStartDate()); Calendar calAux = Calendar.getInstance(); calAux.setTime(chargeYear); int yearCharge = calAux.get(Calendar.YEAR); int yearContract = calAuxCont.get(Calendar.YEAR); if (yearCharge == yearContract) { // Dividimos los das de cada usuario entre los meses del ao. double ratio = uhs.getUser().getAgreement().getHolidays() / 12.0; int monthContract = calAuxCont.get(Calendar.MONTH); int meses = (Calendar.DECEMBER - monthContract); double diasVacaciones = meses * ratio; double aux = Math.ceil(diasVacaciones); uhs.setTotalYear((int) aux); } } return uhs; }
From source file:com.autentia.jsf.component.ocupation.HtmlOcupationCalendarRenderer.java
private static String[] mapShortWeekdays(DateFormatSymbols symbols) { String[] weekdays = new String[7]; String[] localeWeekdays = symbols.getShortWeekdays(); weekdays[0] = localeWeekdays[Calendar.MONDAY]; weekdays[1] = localeWeekdays[Calendar.TUESDAY]; weekdays[2] = localeWeekdays[Calendar.WEDNESDAY]; weekdays[3] = localeWeekdays[Calendar.THURSDAY]; weekdays[4] = localeWeekdays[Calendar.FRIDAY]; weekdays[5] = localeWeekdays[Calendar.SATURDAY]; weekdays[6] = localeWeekdays[Calendar.SUNDAY]; return weekdays; }
From source file:com.discovery.darchrow.date.DateUtil.java
/** * date <span style="color:red">?()</span> <code>23:59:59.999</code> . * //from w ww . j av a 2 s. c om * <p> * ?:,<span style="color:red">,?</span><br> * ?:,? * </p> * * <pre> * 2012-10-11 17:10:30.701 (), * return 2012-10-13 23:59:59.999 * * * getLastDateOfThisWeek(2014-12-31 05:00:00) * return 2015-01-03 23:59:59.999 * </pre> * * @param date * ?date * @return date ? <code>23:59:59.999</code> * @see #toCalendar(Date) * @see Calendar#set(int, int) * @see CalendarUtil#resetDayEnd(Calendar) * @see Calendar#getTime() * @since 1.0.1 */ public static Date getLastDateOfThisWeek(Date date) { Calendar calendar = toCalendar(date); calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); CalendarUtil.resetDayEnd(calendar); return CalendarUtil.toDate(calendar); }
From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java
/** * Test times near midnight./*from ww w . j a v a2s . c o m*/ * * @throws Exception */ @Test public void testCreateBlocksExample3() throws Exception { SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat(); Date startDate = dateFormat.parse("20080624"); Date endDate = dateFormat.parse("20080630"); Set<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("12:00 AM", "12:59 AM", "MTWRF", startDate, endDate); assertEquals(5, blocks.size()); for (AvailableBlock block : blocks) { assertEquals(59, block.getDurationInMinutes()); Calendar cal = Calendar.getInstance(); cal.setTime(block.getStartTime()); assertEquals(0, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(0, cal.get(Calendar.MINUTE)); cal.setTime(block.getEndTime()); assertEquals(0, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(59, cal.get(Calendar.MINUTE)); assertNotSame(Calendar.SATURDAY, cal.get(Calendar.DAY_OF_WEEK)); assertNotSame(Calendar.SUNDAY, cal.get(Calendar.DAY_OF_WEEK)); assertEquals(1, block.getVisitorLimit()); } blocks = AvailableBlockBuilder.createBlocks("12:00 AM", "12:59 AM", "MTWRF", startDate, endDate, 27); assertEquals(5, blocks.size()); for (AvailableBlock block : blocks) { assertEquals(59, block.getDurationInMinutes()); Calendar cal = Calendar.getInstance(); cal.setTime(block.getStartTime()); assertEquals(0, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(0, cal.get(Calendar.MINUTE)); cal.setTime(block.getEndTime()); assertEquals(0, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(59, cal.get(Calendar.MINUTE)); assertNotSame(Calendar.SATURDAY, cal.get(Calendar.DAY_OF_WEEK)); assertNotSame(Calendar.SUNDAY, cal.get(Calendar.DAY_OF_WEEK)); assertEquals(27, block.getVisitorLimit()); } }
From source file:org.sakaiproject.util.CalendarUtil.java
/** * Get the day of the week/* w ww. ja v a 2s .co m*/ * * @param useLocale return locale specific day of week * e.g. <code>SUNDAY = 1, MONDAY = 2, ...</code> in the U.S., * <code>MONDAY = 1, TUESDAY = 2, ...</code> in France. * @return the day of the week. */ public int getDay_Of_Week(boolean useLocale) { int dayofweek = m_calendar.get(Calendar.DAY_OF_WEEK); if (useLocale) { if (dayofweek >= m_calendar.getFirstDayOfWeek()) dayofweek = dayofweek - (m_calendar.getFirstDayOfWeek() - Calendar.SUNDAY); else dayofweek = dayofweek + Calendar.SATURDAY - (m_calendar.getFirstDayOfWeek() - Calendar.SUNDAY); } return dayofweek; }
From source file:br.msf.commons.util.AbstractDateUtils.java
public static boolean isBusinessDay(final Object date, final Collection<? extends Object> holidays) { if (date == null) { return false; }/*from w w w . ja v a 2 s .c o m*/ int dayOfWeek = castToCalendar(date).get(Calendar.DAY_OF_WEEK); return dayOfWeek != Calendar.SATURDAY && dayOfWeek != Calendar.SUNDAY && !isHoliday(date, holidays); }