List of usage examples for java.util Calendar WEEK_OF_MONTH
int WEEK_OF_MONTH
To view the source code for java.util Calendar WEEK_OF_MONTH.
Click Source Link
get
and set
indicating the week number within the current month. From source file:com.milos.neo4j.services.impl.ScoreboardServiceImpl.java
@Transactional(readOnly = true) @Override// ww w. j a v a2 s .c om public Iterable<Scoreboard> getDailyScoreboard(Long points) { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Long now = calendar.getTimeInMillis(); calendar.add(Calendar.WEEK_OF_MONTH, -1); Iterable<Scoreboard> scoreboards = scoreboardDAO.getFullScoreboard(calendar.getTimeInMillis(), now, points); return scoreboards; }
From source file:net.larry1123.elec.util.logger.FileManager.java
public static long getSplitTime() { long set = System.currentTimeMillis(); try {//from ww w.j a v a2 s . c o m Date currentTime = DateUtils.parseDate(getDateFormatFromMilli(System.currentTimeMillis()), DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern()); Date currentSplit = DateUtils.parseDate(getDateFormatFromMilli(getConfig().getCurrentSplit()), DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern()); Date test; switch (getConfig().getSplit()) { case HOUR: test = DateUtils.addHours(currentTime, 1); test = DateUtils.setMinutes(test, 0); test = DateUtils.setSeconds(test, 0); test = DateUtils.setMilliseconds(test, 0); if (test.after(currentSplit)) { set = getConfig().getCurrentSplit(); } break; case DAY: if (!DateUtils.isSameDay(currentTime, currentSplit)) { set = getConfig().getCurrentSplit(); } break; case WEEK: test = DateUtils.ceiling(currentTime, Calendar.WEEK_OF_MONTH); if (test.after(currentSplit)) { set = getConfig().getCurrentSplit(); } break; case MONTH: test = DateUtils.ceiling(currentTime, Calendar.MONTH); if (test.after(currentSplit)) { set = getConfig().getCurrentSplit(); } break; case NONE: default: set = 0; break; } } catch (ParseException e) { set = 0; } return set; }
From source file:com.linuxbox.enkive.teststats.StatsWeekGrainTest.java
@BeforeClass public static void setUp() throws ParseException, GathererException { coll = TestHelper.GetTestCollection(); client = TestHelper.BuildClient();/*from www . j a v a2s . c om*/ grain = new WeekConsolidator(client); List<Map<String, Object>> stats = (new DayConsolidator(client)).consolidateData(); Map<String, Object> timeMap = createMap(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.HOUR, 0); for (int i = 0; i < 10; i++) { if (i == 5) { cal.add(Calendar.WEEK_OF_MONTH, -1); } timeMap.put(CONSOLIDATION_MAX, cal.getTime()); timeMap.put(CONSOLIDATION_MIN, cal.getTime()); for (Map<String, Object> data : stats) { data.put(STAT_TIMESTAMP, timeMap); } client.storeData(stats); } dataCount = coll.count(); }
From source file:srvmonitor.thGetAgendas.java
@Override public void run() { /*/*from w w w . ja va 2s .c o m*/ Recupera Parametros Fecha Actual */ logger.info("Buscando Agendas Activas"); String[] ids = TimeZone.getAvailableIDs(-4 * 60 * 60 * 1000); String clt = ids[0]; SimpleTimeZone tz = new SimpleTimeZone(-4 * 60 * 60 * 1000, clt); tz.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); tz.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(tz); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); // Jan = 0, dec = 11 int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR); int weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH); int hour = calendar.get(Calendar.HOUR); // 12 hour clock int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY); // 24 hour clock int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); int millisecond = calendar.get(Calendar.MILLISECOND); int findHour = 12; int findMinutes = 5; /* calendar.add(Calendar.HOUR_OF_DAY, -1); int hourBefore = calendar.get(Calendar.HOUR_OF_DAY); calendar.add(Calendar.HOUR_OF_DAY, 2); int hourAfter = calendar.get(Calendar.HOUR_OF_DAY); */ String posmonth = String.valueOf(month + 1); String posdayOfMonth = String.valueOf(dayOfMonth); String posdayOfWeek = String.valueOf(dayOfWeek); String posweekOfYear = String.valueOf(weekOfYear); String posweekOfMonth = String.valueOf(weekOfMonth); String poshourOfDay = String.valueOf(hourOfDay); String posminute = String.valueOf(minute); String possecond = String.valueOf(second); String posmillisecond = String.valueOf(millisecond); Calendar iteratorCalendar; String vSQL; String iteratorHour; String iteratorMinute; Statement stm; JSONObject jData; JSONObject jDataMinute; JSONArray jArray = new JSONArray(); JSONArray jArrayMinute = new JSONArray(); String posIteratorHour; String posIteratorMinute; /* Inicializa Lista de Agendas */ gDatos.getLstShowAgendas().clear(); gDatos.getLstActiveAgendas().clear(); for (int i = -findHour; i <= findHour; i++) { iteratorCalendar = new GregorianCalendar(tz); iteratorCalendar.add(Calendar.HOUR_OF_DAY, i); iteratorHour = String.valueOf(iteratorCalendar.get(Calendar.HOUR_OF_DAY)); posIteratorHour = String.valueOf(Integer.valueOf(iteratorHour) + 1); vSQL = "select " + iteratorHour + " horaAgenda,ageID, month, dayOfMonth, dayOfWeek, weekOfYear, weekOfMonth, hourOfDay from process.tb_agenda where " + " ageEnable=1 " + " and substr(month," + posmonth + ",1) = '1'" + " and substr(dayOfMonth," + posdayOfMonth + ",1) = '1'" + " and substr(dayOfWeek," + posdayOfWeek + ",1) = '1'" + " and substr(weekOfYear," + posweekOfYear + ",1) = '1'" + " and substr(weekOfMonth," + posweekOfMonth + ",1) = '1'" + " and substr(hourOfDay," + posIteratorHour + ",1) = '1'"; logger.debug("i: " + i + " vSQL: " + vSQL); try { stm = gDatos.getServerStatus().getMetadataConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); jData = new JSONObject(); ResultSet rs = stm.executeQuery(vSQL); if (rs != null) { while (rs.next()) { jData = new JSONObject(); jData.put("horaAgenda", rs.getString("horaAgenda")); jData.put("ageID", rs.getString("ageID")); jData.put("month", rs.getString("month")); jData.put("dayOfMonth", rs.getString("dayOfMonth")); jData.put("weekOfYear", rs.getString("weekOfYear")); jData.put("weekOfMonth", rs.getString("weekOfMonth")); jData.put("hourOfDay", rs.getString("hourOfDay")); jArray.put(jData); gDatos.getLstShowAgendas().add(jData); } } else { jData.put("horaAgenda", iteratorHour); jData.put("ageID", ""); jData.put("month", ""); jData.put("dayOfMonth", ""); jData.put("weekOfYear", ""); jData.put("weekOfMonth", ""); jData.put("hourOfDay", ""); jArray.put(jData); gDatos.getLstShowAgendas().add(jData); System.out.println("No hay registros"); } stm.close(); } catch (SQLException | JSONException e) { logger.error(e.getMessage()); } } iteratorCalendar = new GregorianCalendar(tz); iteratorHour = String.valueOf(iteratorCalendar.get(Calendar.HOUR_OF_DAY)); posIteratorHour = String.valueOf(Integer.valueOf(iteratorHour) + 1); for (int i = -findMinutes; i <= 0; i++) { iteratorCalendar = new GregorianCalendar(tz); iteratorCalendar.add(Calendar.MINUTE, i); iteratorMinute = String.valueOf(iteratorCalendar.get(Calendar.MINUTE)); posIteratorMinute = String.valueOf(Integer.valueOf(iteratorMinute) + 1); vSQL = "select " + iteratorMinute + " horaAgenda,ageID, month, dayOfMonth, dayOfWeek, weekOfYear, weekOfMonth, hourOfDay from process.tb_agenda where " + " ageEnable=1 " + " and substr(month," + posmonth + ",1) = '1'" + " and substr(dayOfMonth," + posdayOfMonth + ",1) = '1'" + " and substr(dayOfWeek," + posdayOfWeek + ",1) = '1'" + " and substr(weekOfYear," + posweekOfYear + ",1) = '1'" + " and substr(weekOfMonth," + posweekOfMonth + ",1) = '1'" + " and substr(hourOfDay," + posIteratorHour + ",1) = '1'" + " and substr(minute," + posIteratorMinute + ",1) = '1'"; logger.debug("i: " + i + " vSQL: " + vSQL); try { stm = gDatos.getServerStatus().getMetadataConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stm.executeQuery(vSQL); if (rs != null) { while (rs.next()) { jDataMinute = new JSONObject(); jDataMinute.put("horaAgenda", rs.getString("horaAgenda")); jDataMinute.put("ageID", rs.getString("ageID")); jDataMinute.put("month", rs.getString("month")); jDataMinute.put("dayOfMonth", rs.getString("dayOfMonth")); jDataMinute.put("weekOfYear", rs.getString("weekOfYear")); jDataMinute.put("weekOfMonth", rs.getString("weekOfMonth")); jDataMinute.put("hourOfDay", rs.getString("hourOfDay")); jArrayMinute.put(jDataMinute); gDatos.getLstActiveAgendas().add(jDataMinute); } } stm.close(); } catch (SQLException | JSONException e) { logger.error(e.getMessage()); } } for (int i = 0; i < gDatos.getLstShowAgendas().size(); i++) { logger.debug(gDatos.getLstShowAgendas().get(i).toString()); } for (int i = 0; i < gDatos.getLstActiveAgendas().size(); i++) { logger.debug(gDatos.getLstActiveAgendas().get(i).toString()); } logger.info("Finaliza busquenda agendas activas..."); }
From source file:com.milos.neo4j.services.impl.ScoreboardServiceImpl.java
@Transactional(readOnly = true) @Override/*from ww w.j av a2 s . c o m*/ public Iterable<Scoreboard> getWeeklyScoreboard(Long points) { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Long now = calendar.getTimeInMillis(); calendar.add(Calendar.WEEK_OF_MONTH, -1); return scoreboardDAO.getFullScoreboard(calendar.getTimeInMillis(), now, points); }
From source file:org.fire.platform.util.DateUtil.java
/** * ??//from w w w. ja v a 2s . c o m * * @param week * @return */ public static Date addWeek(Integer week) { Date nowDate = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(nowDate); calendar.add(Calendar.WEEK_OF_MONTH, week); return calendar.getTime(); }
From source file:net.firejack.platform.core.utils.DateUtils.java
/** * Decrements the date by one week//from ww w .j a v a 2 s. c o m * @param date - date to be decremented * @return decremented date */ public static Date decDateByWeek(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.WEEK_OF_MONTH, -1); date.setTime(cal.getTimeInMillis()); return date; }
From source file:com.binary_machinery.avalonschedule.view.schedule.SchedulePagerAdapter.java
private Calendar getWeekBeginning(int position) { Calendar calendar = Calendar.getInstance(); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(m_minDate);/*from w w w .j a v a 2 s . c o m*/ calendar.add(Calendar.WEEK_OF_MONTH, position); calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; }
From source file:org.mifos.calendar.CalendarUtils.java
public static DateTime getFirstDayForMonthUsingWeekRankAndWeekday(final DateTime startDate, final int calendarWeekOfMonth, final int dayOfWeek) { /*/*from www . j a v a2 s.c o m*/ * In Joda time MONDAY=1 and SUNDAY=7, so shift these to SUNDAY=1, SATURDAY=7 to match this class */ int calendarDayOfWeek = (dayOfWeek % 7) + 1; final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate.toDate()); DateTime scheduleDate = null; // if current weekday is after the weekday on which schedule has to // lie, move to next week if (gc.get(Calendar.DAY_OF_WEEK) > calendarDayOfWeek) { gc.add(Calendar.WEEK_OF_MONTH, 1); } // set the weekday on which schedule has to lie gc.set(Calendar.DAY_OF_WEEK, calendarDayOfWeek); // if week rank is First, Second, Third or Fourth, Set the // respective week. // if current week rank is after the weekrank on which schedule has // to lie, move to next month if (!RankOfDay.getRankOfDay(calendarWeekOfMonth).equals(RankOfDay.LAST)) { if (gc.get(Calendar.DAY_OF_WEEK_IN_MONTH) > calendarWeekOfMonth) { gc.add(GregorianCalendar.MONTH, 1); gc.set(GregorianCalendar.DATE, 1); } // set the weekrank on which schedule has to lie gc.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, calendarWeekOfMonth); scheduleDate = new DateTime(gc.getTime().getTime()); } else {// scheduleData.getWeekRank()=Last int M1 = gc.get(GregorianCalendar.MONTH); // assumption: there are 5 weekdays in the month gc.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, 5); int M2 = gc.get(GregorianCalendar.MONTH); // if assumption fails, it means there exists 4 weekdays in a // month, return last weekday date // if M1==M2, means there exists 5 weekdays otherwise 4 weekdays // in a month if (M1 != M2) { gc.set(GregorianCalendar.MONTH, gc.get(GregorianCalendar.MONTH) - 1); gc.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, 4); } scheduleDate = new DateTime(gc.getTime().getTime()); } return scheduleDate; }
From source file:com.binary_machinery.avalonschedule.view.schedule.SchedulePagerAdapter.java
private Calendar getWeekEnd(int position) { Calendar calendar = Calendar.getInstance(); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(m_minDate);/*from w w w . j a v a 2 s .c o m*/ calendar.add(Calendar.WEEK_OF_MONTH, position); calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); calendar.set(Calendar.HOUR, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); calendar.set(Calendar.MILLISECOND, 999); return calendar; }