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:org.openmrs.module.pharmacyapi.api.prescription.util.NewPrescriptionItemGenerator.java
private Date getExpirationDateMinus2Days(final PrescriptionItem item) { final Calendar calendar = Calendar.getInstance(); calendar.setTime(item.getDrugOrder().getEncounter().getDateCreated()); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.add(Calendar.DAY_OF_MONTH, 10); while ((calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) || (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)) { calendar.add(Calendar.DAY_OF_MONTH, 1); }//from ww w.j a v a2s .co m return calendar.getTime(); }
From source file:com.krawler.common.util.SchedulingUtilities.java
public static String getNextWorkingDay(String currDate, int[] NWD, String[] CH) { Calendar c1 = Calendar.getInstance(); Date stdate = c1.getTime();//from ww w . j a va 2 s . c om java.text.SimpleDateFormat sdfLong = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd"); int n = 1; try { c1.setTime(sdfLong.parse(currDate)); while (n > 0) { c1.add(Calendar.DATE, 1); if (Arrays.binarySearch(NWD, (c1.get(Calendar.DAY_OF_WEEK) - 1)) > -1 || Arrays.binarySearch(CH, sdf.format(c1.getTime())) > -1) { n++; } else { n = 0; } stdate = c1.getTime(); } } catch (Exception e) { throw ServiceException.FAILURE("Exception while calculating next working day : " + e.getMessage(), e); } finally { return sdfLong.format(stdate); } }
From source file:lineage2.gameserver.model.entity.events.impl.ClanHallAuctionEvent.java
/** * Method reCalcNextTime.//from w w w . ja v a 2 s. c o m * @param onStart boolean */ @Override public void reCalcNextTime(boolean onStart) { clearActions(); _onTimeActions.clear(); Clan owner = getResidence().getOwner(); _endSiegeDate.setTimeInMillis(0); if ((getResidence().getAuctionLength() == 0) && (owner == null)) { getResidence().getSiegeDate().setTimeInMillis(System.currentTimeMillis()); getResidence().getSiegeDate().set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); getResidence().getSiegeDate().set(Calendar.HOUR_OF_DAY, 15); getResidence().getSiegeDate().set(Calendar.MINUTE, 0); getResidence().getSiegeDate().set(Calendar.SECOND, 0); getResidence().getSiegeDate().set(Calendar.MILLISECOND, 0); getResidence().setAuctionLength(7); getResidence().setAuctionMinBid(getResidence().getBaseMinBid()); getResidence().setJdbcState(JdbcEntityState.UPDATED); getResidence().update(); _onTimeActions.clear(); addOnTimeAction(0, new StartStopAction(EVENT, true)); addOnTimeAction(getResidence().getAuctionLength() * 86400, new StartStopAction(EVENT, false)); _endSiegeDate.setTimeInMillis(getResidence().getSiegeDate().getTimeInMillis() + (getResidence().getAuctionLength() * 86400000L)); registerActions(); } else if ((getResidence().getAuctionLength() == 0) && (owner != null)) { } else { long endDate = getResidence().getSiegeDate().getTimeInMillis() + (getResidence().getAuctionLength() * 86400000L); if (endDate <= System.currentTimeMillis()) { getResidence().getSiegeDate().setTimeInMillis(System.currentTimeMillis()); } _endSiegeDate.setTimeInMillis(getResidence().getSiegeDate().getTimeInMillis() + (getResidence().getAuctionLength() * 86400000L)); _onTimeActions.clear(); addOnTimeAction(0, new StartStopAction(EVENT, true)); addOnTimeAction(getResidence().getAuctionLength() * 86400, new StartStopAction(EVENT, false)); registerActions(); } }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartTimeSeriesGraphSourceTestCase.java
public void testBadTimeResolution() { Calendar c = Calendar.getInstance(); Map<String, Object> params = new HashMap<String, Object>(); c.set(Calendar.DAY_OF_WEEK, 1); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 5);/* www . j a va2 s . com*/ List<TimePoint> series = new LinkedList<TimePoint>(); series.add(new TimePoint(c.getTime(), 5, params)); c.set(Calendar.MINUTE, 12); series.add(new TimePoint(c.getTime(), 8, params)); Map<String, Object> seriesParams = new HashMap<String, Object>(); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.HOURLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected } series.clear(); for (int i = 1; i < 5; i += 1) { c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.DAY_OF_WEEK, i); series.add(new TimePoint(c.getTime(), i, params)); } c.set(Calendar.DAY_OF_WEEK, 2); c.set(Calendar.HOUR_OF_DAY, 3); series.add(new TimePoint(c.getTime(), 2, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.HOURLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through okay } catch (GraphException e) { fail(); } series.clear(); c.set(Calendar.DAY_OF_WEEK, 1); series.add(new TimePoint(c.getTime(), 5, params)); c.set(Calendar.DAY_OF_WEEK, 3); series.add(new TimePoint(c.getTime(), 12, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through on a daily resolution } catch (GraphException e) { fail(); } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.WEEKLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected failure for weekly } series.clear(); c.set(Calendar.DAY_OF_WEEK, 1); c.set(Calendar.WEEK_OF_MONTH, 2); series.add(new TimePoint(c.getTime(), 5, params)); c.set(Calendar.WEEK_OF_MONTH, 3); series.add(new TimePoint(c.getTime(), 8, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.WEEKLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through on a weekly resolution } catch (GraphException e) { fail(); } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.MONTHLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected failure for monthly } series.clear(); c.set(Calendar.DAY_OF_WEEK, 1); c.set(Calendar.WEEK_OF_MONTH, 2); c.set(Calendar.MONTH, 2); series.add(new TimePoint(c.getTime(), 8, params)); c.set(Calendar.MONTH, 3); series.add(new TimePoint(c.getTime(), 12, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.MONTHLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through on a monthly resolution } catch (GraphException e) { fail(); } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.YEARLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected failure for yearly } series.clear(); c.set(Calendar.DAY_OF_WEEK, 1); c.set(Calendar.WEEK_OF_MONTH, 2); c.set(Calendar.MONTH, 2); series.add(new TimePoint(c.getTime(), 8, params)); c.add(Calendar.YEAR, 1); series.add(new TimePoint(c.getTime(), 18, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.YEARLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through on a yearly resolution } catch (GraphException e) { fail(); } }
From source file:net.chaosserver.timelord.swingui.PreviousDayPanel.java
/** * Constructs a new previous day panel./*from w w w .j a v a 2 s . c o m*/ * * @param timelordData the timelord data to pull information from. */ public PreviousDayPanel(TimelordData timelordData) { this.timelordData = timelordData; setLayout(new BorderLayout()); JButton pickDayButton = new JButton("Select Day"); pickDayButton.setActionCommand(ACTION_PICK_DAY); pickDayButton.addActionListener(this); add(pickDayButton, BorderLayout.NORTH); Calendar calendarDay = Calendar.getInstance(); calendarDay.add(Calendar.DAY_OF_WEEK, -1); setDisplayDate(DateUtil.trunc(calendarDay.getTime())); }
From source file:com.pivotal.gfxd.demo.loader.Loader.java
public void insertBatch(final List<String[]> lines, final long timestamp) { String sql = "insert into raw_sensor (id, timestamp, value, property, plug_id, household_id, house_id, weekday, time_slice) values (?,?,?,?,?,?,?,?,?)"; final Calendar cal = Calendar.getInstance(); getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() { @Override/* w ww . j av a 2 s. co m*/ public void setValues(PreparedStatement ps, int i) throws SQLException { final String[] split = lines.get(i); int plugId = Integer.parseInt(split[4]); int householdId = Integer.parseInt(split[5]); int houseId = Integer.parseInt(split[6]); ps.setLong(1, Long.parseLong(split[0])); ps.setLong(2, timestamp); float value = Float.parseFloat(split[2]); ps.setFloat(3, value + value * disturbance); ps.setInt(4, Integer.parseInt(split[3])); ps.setInt(5, computePlugId(plugId, householdId, houseId)); ps.setInt(6, householdId); ps.setInt(7, houseId); cal.setTimeInMillis(timestamp * 1000L); int weekDay = cal.get(Calendar.DAY_OF_WEEK); int timeSlice = (cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE)) / MINUTES_PER_INTERVAL; ps.setInt(8, weekDay); // weekday ps.setInt(9, timeSlice); // time_slice } @Override public int getBatchSize() { return lines.size(); } }); cal.setTimeInMillis(timestamp * 1000L); int weekDay = cal.get(Calendar.DAY_OF_WEEK); int timeSlice = (cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE)) / MINUTES_PER_INTERVAL; LOG.debug("rows=" + lines.size() + " weekday=" + weekDay + " slice=" + timeSlice + " stamp=" + timestamp + " now=" + (int) (System.currentTimeMillis() / 1000)); rowsInserted += lines.size(); }
From source file:com.autentia.tnt.manager.holiday.UserHolidaysStateManager.java
/** * @return Indica si un da es festivo// w w w. jav a 2 s . com */ private boolean isHoliday(List<Holiday> fiestas, Date date) { // Es fin de semana ? Calendar cActual = Calendar.getInstance(); cActual.setTime(date); if ((cActual.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) || (cActual.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) { return true; } Iterator<Holiday> ite = fiestas.iterator(); Holiday current; while (ite.hasNext()) { current = ite.next(); if (DateUtils.isSameDay(current.getDate(), date)) { return true; } } return false; }
From source file:com.chortitzer.web.fps.controller.VaporBean.java
/** * @param selectedRango the selectedRango to set */// w w w .ja v a2 s. co m public void setSelectedRango(int selectedRango) { this.selectedRango = selectedRango; if (selectedRango != 0) { setFechaHasta(new Date()); switch (selectedRango) { case 1: setFechaDesde(DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH)); break; case 2: fechaDesde = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH); setFechaDesde(DateUtils.addDays(fechaDesde, -1)); fechaHasta = DateUtils.addDays(fechaDesde, 1); setFechaHasta(DateUtils.addMilliseconds(fechaHasta, -1)); break; case 3: calendar = DateUtils.truncate(calendar, Calendar.DAY_OF_MONTH); calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek()); setFechaDesde(calendar.getTime()); break; case 4: setFechaDesde(DateUtils.truncate(new Date(), Calendar.MONTH)); break; case 5: setFechaDesde(DateUtils.truncate(new Date(), Calendar.YEAR)); break; } } createDataModel(); }
From source file:com.spoiledmilk.cykelsuperstier.break_rote.LocalTrainData.java
public static ArrayList<ITransportationInfo> getNext3Arrivals(String fromStation, String toStation, String line, Context context) {/*from ww w .j a v a2 s.c om*/ ArrayList<ITransportationInfo> ret = new ArrayList<ITransportationInfo>(); String lineNumber = line.split(" ")[0]; String jsonStr = Util.stringFromJsonAssets(context, "stations/local-trains-timetable.json"); JsonNode root = Util.stringToJsonNode(jsonStr); JsonNode lines = root.get("local-trains"); for (int i = 0; i < lines.size(); i++) { if (lines.get(i).get("line").asText().trim().equalsIgnoreCase(lineNumber.trim())) { JsonNode stationsArray = lines.get(i).get("stations"); int direction = -1, index1 = -1, index2 = -1; for (int j = 0; j < stationsArray.size(); j++) { if (stationsArray.get(j).asText().trim().equalsIgnoreCase(fromStation.trim()) && index1 < 0) { index1 = j; if (direction < 0) direction = DEPARTURE; else break; } if (stationsArray.get(j).asText().trim().equalsIgnoreCase(toStation.trim()) && index2 < 0) { index2 = j; if (direction < 0) direction = ARRIVAL; else break; } } if (direction < 0 || index1 < 0 || index2 < 0) break; JsonNode timetableNodeContainer = direction == DEPARTURE ? lines.get(i).get("departure") : lines.get(i).get("arrival"); Calendar calendar = Calendar.getInstance(); int day = calendar.get(Calendar.DAY_OF_WEEK); if (day == 1) day = 6; else day -= 2; int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); JsonNode timeTableNode; if (day >= 0 && day <= 4) { timeTableNode = timetableNodeContainer.get("weekdays"); if (timeTableNode != null) getTimesForWeekdays(hour, minute, ret, timeTableNode, index1, index2, stationsArray.size()); } else if (day == 5) { // Saturday timeTableNode = timetableNodeContainer.get("weekend").get("saturday"); if (timeTableNode != null) { JsonNode dataNodeArray = timetableNodeContainer.get("weekend").get("data-table"); getTimesForWeekend(hour, minute, ret, timeTableNode, index1, index2, stationsArray.size(), dataNodeArray); } } else { // Saturday timeTableNode = timetableNodeContainer.get("weekend").get("sunday"); if (timeTableNode != null) { JsonNode dataNodeArray = timetableNodeContainer.get("weekend").get("data-table"); getTimesForWeekend(hour, minute, ret, timeTableNode, index1, index2, stationsArray.size(), dataNodeArray); } } if (timeTableNode == null) break; break; } } return ret; }
From source file:net.rrm.ehour.ui.timesheet.export.excel.part.ExportReportBody.java
private boolean isFirstDayOfWeek(Date date) { Calendar cal = GregorianCalendar.getInstance(); cal.setTime(date);//w w w .j av a2 s . c o m return cal.get(Calendar.DAY_OF_WEEK) == getConfig().getFirstDayOfWeek(); }