List of usage examples for java.util Calendar DAY_OF_WEEK
int DAY_OF_WEEK
To view the source code for java.util Calendar DAY_OF_WEEK.
Click Source Link
get
and set
indicating the day of the week. From source file:at.diamonddogs.util.Utils.java
/** * Converts input values to a {@link Calendar} * * @param dayOfWeek/*from w w w . j a va 2 s . c om*/ * @param hourOfDay * @param minute * @param second * @return a {@link Calendar}r with the provided date */ public static final Calendar getScheduledDate(int dayOfWeek, int hourOfDay, int minute, int second) { Calendar c = Calendar.getInstance(); int weekDay = c.get(Calendar.DAY_OF_WEEK); int days = dayOfWeek - weekDay; if (days < 0) { days += 7; } c.add(Calendar.DAY_OF_YEAR, days); c.set(Calendar.HOUR_OF_DAY, hourOfDay); c.set(Calendar.MINUTE, minute); c.set(Calendar.SECOND, second); return c; }
From source file:com.mirth.connect.server.migration.Migrate3_3_0.java
private void migrateDataPrunerConfiguration() { boolean enabled = true; String time = ""; String interval = ""; String dayOfWeek = ""; String dayOfMonth = "1"; ResultSet results = null;//from ww w . jav a2 s. c o m PreparedStatement statement = null; Connection connection = null; try { connection = getConnection(); try { statement = connection .prepareStatement("SELECT NAME, VALUE FROM CONFIGURATION WHERE CATEGORY = 'Data Pruner'"); results = statement.executeQuery(); while (results.next()) { String name = results.getString(1); String value = results.getString(2); if (name.equals("interval")) { interval = value; } else if (name.equals("time")) { time = value; } else if (name.equals("dayOfWeek")) { dayOfWeek = value; } else if (name.equals("dayOfMonth")) { dayOfMonth = value; } } } catch (SQLException e) { logger.error("Failed to read Data Pruner configuration properties.", e); } finally { DbUtils.closeQuietly(statement); DbUtils.closeQuietly(results); } enabled = !interval.equals("disabled"); String pollingType = "INTERVAL"; String pollingHour = "12"; String pollingMinute = "0"; boolean weekly = !StringUtils.equals(interval, "monthly"); boolean[] activeDays = new boolean[] { true, true, true, true, true, true, true, true }; if (enabled && !StringUtils.equals(interval, "hourly")) { SimpleDateFormat timeDateFormat = new SimpleDateFormat("hh:mm aa"); DateFormatter timeFormatter = new DateFormatter(timeDateFormat); Date timeDate = null; try { timeDate = (Date) timeFormatter.stringToValue(time); Calendar timeCalendar = Calendar.getInstance(); timeCalendar.setTime(timeDate); pollingType = "TIME"; pollingHour = String.valueOf(timeCalendar.get(Calendar.HOUR_OF_DAY)); pollingMinute = String.valueOf(timeCalendar.get(Calendar.MINUTE)); if (StringUtils.equals(interval, "weekly")) { SimpleDateFormat dayDateFormat = new SimpleDateFormat("EEEEEEEE"); DateFormatter dayFormatter = new DateFormatter(dayDateFormat); Date dayDate = (Date) dayFormatter.stringToValue(dayOfWeek); Calendar dayCalendar = Calendar.getInstance(); dayCalendar.setTime(dayDate); activeDays = new boolean[] { false, false, false, false, false, false, false, false }; activeDays[dayCalendar.get(Calendar.DAY_OF_WEEK)] = true; } } catch (Exception e) { logger.error("Failed to get Data Pruner time properties", e); } } DonkeyElement pollingProperties = new DonkeyElement( "<com.mirth.connect.donkey.model.channel.PollConnectorProperties/>"); pollingProperties.setAttribute("version", "3.3.0"); pollingProperties.addChildElementIfNotExists("pollingType", pollingType); pollingProperties.addChildElementIfNotExists("pollOnStart", "false"); pollingProperties.addChildElementIfNotExists("pollingFrequency", "3600000"); pollingProperties.addChildElementIfNotExists("pollingHour", pollingHour); pollingProperties.addChildElementIfNotExists("pollingMinute", pollingMinute); pollingProperties.addChildElementIfNotExists("cronJobs"); DonkeyElement advancedProperties = pollingProperties .addChildElementIfNotExists("pollConnectorPropertiesAdvanced"); advancedProperties.addChildElementIfNotExists("weekly", weekly ? "true" : "false"); DonkeyElement inactiveDays = advancedProperties.addChildElementIfNotExists("inactiveDays"); if (inactiveDays != null) { for (int index = 0; index < 8; ++index) { inactiveDays.addChildElement("boolean", activeDays[index] ? "false" : "true"); } } advancedProperties.addChildElementIfNotExists("dayOfMonth", dayOfMonth); advancedProperties.addChildElementIfNotExists("allDay", "true"); advancedProperties.addChildElementIfNotExists("startingHour", "8"); advancedProperties.addChildElementIfNotExists("startingMinute", "0"); advancedProperties.addChildElementIfNotExists("endingHour", "17"); advancedProperties.addChildElementIfNotExists("endingMinute", "0"); PreparedStatement inputStatement = null; try { inputStatement = connection .prepareStatement("INSERT INTO CONFIGURATION (CATEGORY, NAME, VALUE) VALUES (?, ?, ?)"); inputStatement.setString(1, "Data Pruner"); inputStatement.setString(2, "pollingProperties"); inputStatement.setString(3, pollingProperties.toXml()); inputStatement.executeUpdate(); } catch (Exception e) { logger.error("Failed to insert Data Pruner configuration pollingProperties.", e); } finally { DbUtils.closeQuietly(inputStatement); } PreparedStatement updateStatement = null; try { updateStatement = connection.prepareStatement( "UPDATE CONFIGURATION SET NAME = ?, VALUE = ? WHERE CATEGORY = ? AND NAME = ?"); updateStatement.setString(1, "enabled"); updateStatement.setString(2, enabled ? "true" : "false"); updateStatement.setString(3, "Data Pruner"); updateStatement.setString(4, "interval"); updateStatement.executeUpdate(); } finally { DbUtils.closeQuietly(updateStatement); } PreparedStatement deleteStatement = null; try { deleteStatement = connection .prepareStatement("DELETE FROM CONFIGURATION WHERE CATEGORY = ? AND NAME IN (?, ?, ?)"); deleteStatement.setString(1, "Data Pruner"); deleteStatement.setString(2, "time"); deleteStatement.setString(3, "dayOfWeek"); deleteStatement.setString(4, "dayOfMonth"); deleteStatement.executeUpdate(); } finally { DbUtils.closeQuietly(deleteStatement); } } catch (Exception e) { logger.error("Failed to modify Data Pruner configuration properties", e); } }
From source file:fr.paris.lutece.plugins.appointment.modules.resource.web.AppointmentResourceJspBean.java
/** * Get the resource calendar for a week/*from w ww . j a v a 2s. co m*/ * @param request The request * @param resource The resource * @param nOffsetWeek The week offset * @param locale The locale * ...) * @return The HTML content to display */ public static String getResourceCalendar(HttpServletRequest request, IResource resource, int nOffsetWeek, Locale locale) { AppointmentService appointmentService = AppointmentService.getService(); Map<String, Object> model = new HashMap<String, Object>(); model.put(MARK_RESOURCE, resource); Date dateMonday = appointmentService.getDateMonday(nOffsetWeek); Calendar calendar = new GregorianCalendar(); calendar.setTime(dateMonday); calendar.add(Calendar.DAY_OF_WEEK, 7); Date dateMax = new Date(calendar.getTimeInMillis()); List<Integer> listIdAppointments = AppointmentResourceHome.findIdAppointmentsByResourceAndDate( resource.getIdResource(), resource.getResourceType(), dateMonday, dateMax); List<Appointment> listAppointment = new ArrayList<Appointment>(listIdAppointments.size()); Map<Integer, List<CalendarAppointmentResourceDTO>> mapCalendarAppointmentResourceByDayOfWeek = new HashMap<Integer, List<CalendarAppointmentResourceDTO>>(); int nStartingHour = 0; int nStartingMinute = 0; int nEndingHour = 0; int nEndingMinute = 0; int nMinGlobalStartingTime = 9999; int nMaxGlobalEndingTime = 0; int nMinDuration = -1; for (int i = 1; i < 8; i++) { mapCalendarAppointmentResourceByDayOfWeek.put(i, new ArrayList<CalendarAppointmentResourceDTO>()); } for (int nIdAppointment : listIdAppointments) { Appointment appointment = AppointmentHome.findByPrimaryKey(nIdAppointment); listAppointment.add(appointment); AppointmentSlot slot = AppointmentSlotHome.findByPrimaryKey(appointment.getIdSlot()); CalendarAppointmentResourceDTO calendarAppointmentResource = new CalendarAppointmentResourceDTO( appointment.getIdAppointment(), slot.getStartingHour(), slot.getStartingMinute(), slot.getEndingHour(), slot.getEndingMinute(), getAppointmentRecap(appointment, locale)); int nStartingTimeSlot = (slot.getStartingHour() * 60) + slot.getStartingMinute(); if (nStartingTimeSlot < nMinGlobalStartingTime) { nMinGlobalStartingTime = nStartingTimeSlot; nStartingHour = slot.getStartingHour(); nStartingMinute = slot.getStartingMinute(); } int nEndingTimeSlot = (slot.getEndingHour() * 60) + slot.getEndingMinute(); if (nEndingTimeSlot > nMaxGlobalEndingTime) { nMaxGlobalEndingTime = nEndingTimeSlot; nEndingHour = slot.getEndingHour(); nEndingMinute = slot.getEndingMinute(); } if ((calendarAppointmentResource.getDuration() < nMinDuration) || (nMinDuration == -1)) { nMinDuration = calendarAppointmentResource.getDuration(); } int nDayOfWeek = appointmentService.getDayOfWeek(appointment.getDateAppointment()); List<CalendarAppointmentResourceDTO> listCalendar = mapCalendarAppointmentResourceByDayOfWeek .get(nDayOfWeek); listCalendar.add(calendarAppointmentResource); } List<CalendarDayDTO> listDays = new ArrayList<CalendarDayDTO>(7); for (Entry<Integer, List<CalendarAppointmentResourceDTO>> entry : mapCalendarAppointmentResourceByDayOfWeek .entrySet()) { CalendarDayDTO day = new CalendarDayDTO(); Calendar calendarDay = new GregorianCalendar(); calendarDay.setTime(dateMonday); calendarDay.add(Calendar.DAY_OF_WEEK, entry.getKey() - 1); day.setDate(calendarDay.getTime()); List<CalendarAppointmentResourceDTO> listCalendarApp = entry.getValue(); Collections.sort(listCalendarApp); day.setListAppointmentResourceDTO(listCalendarApp); listDays.add(day); } Collections.sort(listDays); List<AppointmentForm> listAppointmentForm = AppointmentFormHome.getActiveAppointmentFormsList(); for (AppointmentForm appointmentForm : listAppointmentForm) { int nOpeningTime = (appointmentForm.getOpeningHour() * 60) + appointmentForm.getOpeningMinutes(); if (nOpeningTime < nMinGlobalStartingTime) { nMinGlobalStartingTime = nOpeningTime; nStartingHour = appointmentForm.getOpeningHour(); nStartingMinute = appointmentForm.getOpeningMinutes(); } int nClosingTime = (appointmentForm.getClosingHour() * 60) + appointmentForm.getClosingMinutes(); if (nClosingTime > nMaxGlobalEndingTime) { nMaxGlobalEndingTime = nClosingTime; nEndingHour = appointmentForm.getClosingHour(); nEndingMinute = appointmentForm.getClosingMinutes(); } if ((appointmentForm.getDurationAppointments() < nMinDuration) || (nMinDuration < 0)) { nMinDuration = appointmentForm.getDurationAppointments(); } } model.put(MARK_LIST_DAYS, listDays); model.put(PARAMETER_OFFSET_WEEK, nOffsetWeek); model.put(MARK_LIST_DAYS_OF_WEEK, MESSAGE_LIST_DAYS_OF_WEEK); model.put(MARK_STARTING_TIME, nMinGlobalStartingTime); model.put(MARK_ENDING_TIME, nMaxGlobalEndingTime); model.put(MARK_DURATION, nMinDuration); model.put(MARK_STARTING_HOUR, nStartingHour); model.put(MARK_STARTING_MINUTE, nStartingMinute); model.put(MARK_ENDING_HOUR, nEndingHour); model.put(MARK_ENDING_MINUTE, nEndingMinute); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_RESOURCE_CALENDAR, locale, model); return template.getHtml(); }
From source file:de.codesourcery.eve.skills.ui.utils.CalendarWidget.java
private String getWeekDayName(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from w ww.ja v a2 s. c o m*/ return calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()); }
From source file:org.motechproject.server.event.MessageProgramDateStateChangeTest.java
private Date determinePreferredMessageDate(Date messageDate, Date currentDate) { Calendar calendar = Calendar.getInstance(); calendar.setTime(messageDate);/* ww w .j av a 2 s . co m*/ calendar.set(Calendar.HOUR_OF_DAY, 18); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); DayOfWeek day = DayOfWeek.MONDAY; if (day != null) { calendar.set(Calendar.DAY_OF_WEEK, day.getCalendarValue()); } return calendar.getTime(); }
From source file:org.davidmendoza.esu.service.impl.InicioServiceImpl.java
@Override public Inicio manana(Inicio inicio) { Inicio manana = new Inicio(); Integer anio = new Integer(inicio.getAnio()); String trimestre = inicio.getTrimestre(); String leccion = inicio.getLeccion(); String dia = inicio.getDia(); if (StringUtils.isBlank(dia)) { dia = obtieneDia(new GregorianCalendar(Locale.ENGLISH).get(Calendar.DAY_OF_WEEK)); }/*from w ww .ja v a 2 s . c om*/ Trimestre t = trimestreService.obtiene(anio + trimestre); if (t != null) { try { Calendar cal = new GregorianCalendar(Locale.ENGLISH); cal.setTime(t.getInicia()); cal.add(Calendar.SECOND, 1); cal.set(Calendar.DAY_OF_WEEK, obtieneDia(dia)); int weeks = ((Long) nf.parse(leccion.substring(1))).intValue(); if (dia.equals("sabado")) { weeks--; } cal.add(Calendar.WEEK_OF_YEAR, weeks); cal.add(Calendar.DAY_OF_MONTH, +1); Date hoy = cal.getTime(); manana.setHoy(hoy); t = trimestreService.obtiene(hoy); DateTime a = new DateTime(t.getInicia()); DateTime b = new DateTime(hoy); Weeks c = Weeks.weeksBetween(a, b); weeks = c.getWeeks(); weeks++; leccion = "l" + dosDigitos.format(weeks); manana.setAnio(t.getNombre().substring(0, 4)); manana.setTrimestre(t.getNombre().substring(4)); manana.setLeccion(leccion); manana.setDia(obtieneDia(cal.get(Calendar.DAY_OF_WEEK))); return manana; } catch (ParseException e) { log.error("No pude poner la fecha de manana", e); } } return null; }
From source file:it.drwolf.ridire.session.JobManager.java
private String calculateCronString() { String cronString = ""; Calendar startDate = Calendar.getInstance(); if (this.job.getFirstDate() == null) { return cronString; }// ww w .ja v a2 s.c om startDate.setTime(this.job.getFirstDate()); if (this.job.getPeriodFrequency().equals("yearly")) { cronString = startDate.get(Calendar.SECOND) + " " + startDate.get(Calendar.MINUTE) + " " + startDate.get(Calendar.HOUR_OF_DAY) + " " + startDate.get(Calendar.DAY_OF_MONTH) + " " + startDate.get(Calendar.MONTH) + 1 + " ?"; } else if (this.job.getPeriodFrequency().equals("monthly")) { cronString = startDate.get(Calendar.SECOND) + " " + startDate.get(Calendar.MINUTE) + " " + startDate.get(Calendar.HOUR_OF_DAY) + " " + startDate.get(Calendar.DAY_OF_MONTH) + " * ?"; } else if (this.job.getPeriodFrequency().equals("weekly")) { cronString = startDate.get(Calendar.SECOND) + " " + startDate.get(Calendar.MINUTE) + " " + startDate.get(Calendar.HOUR_OF_DAY) + " ? * " + startDate.get(Calendar.DAY_OF_WEEK); } else if (this.job.getPeriodFrequency().equals("daily")) { cronString = startDate.get(Calendar.SECOND) + " " + startDate.get(Calendar.MINUTE) + " " + startDate.get(Calendar.HOUR_OF_DAY) + " * * ?"; } else if (this.job.getPeriodFrequency().equals("dummy5")) { cronString = startDate.get(Calendar.SECOND) + " " + startDate.get(Calendar.MINUTE) + "/5 " + "* * * ?"; } else if (this.job.getPeriodFrequency().equals("dummy2")) { cronString = startDate.get(Calendar.SECOND) + " " + startDate.get(Calendar.MINUTE) + "/2 " + "* * * ?"; } else if (this.job.getPeriodFrequency().equals("dummy1")) { cronString = startDate.get(Calendar.SECOND) + " " + startDate.get(Calendar.MINUTE) + "/1 " + "* * * ?"; } return cronString; }
From source file:com.greenline.guahao.biz.util.DateUtils.java
/** * ?//from w ww. ja v a 2 s. c o m * * @param date * @return */ public static String getWeekDayString(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); return dayNames[dayOfWeek - 1]; }
From source file:com.clican.pluto.common.calendar.BusinessCalendar.java
protected BusinessDay findDay(Date date) { Calendar calendar = createCalendar(); calendar.setTime(date);/*from www .j av a 2s . c om*/ int weekDayIndex = calendar.get(Calendar.DAY_OF_WEEK); return days[weekDayIndex]; }
From source file:com.baidu.rigel.biplatform.tesseract.meta.impl.TimeDimensionMemberServiceImpl.java
/** * ??/* w ww . j av a 2s.c om*/ * * @param date * @return */ private Date getFirstDayOfWeek(Date date) { Calendar cal = Calendar.getInstance(); cal.setFirstDayOfWeek(Calendar.MONDAY); cal.setTime(date); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); return cal.getTime(); }