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:com.hurence.logisland.utils.DateUtils.java
/** * Check if the date parameter occurs during a weekend. * * @return Current time in ISO-8601 format, e.g. : "2012-07-03T07:59:09.206 UTC" *///from w ww .j a va2s. c om public static boolean isWeekend(Date date) { if (date != null) { Calendar calendar = Calendar.getInstance(); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(date); int dayOfTheWeek = calendar.get(Calendar.DAY_OF_WEEK); return dayOfTheWeek == Calendar.SATURDAY || dayOfTheWeek == Calendar.SUNDAY; } else { return false; } }
From source file:org.onebusaway.webapp.actions.rss.StopProblemReportsAction.java
@Override public String execute() { AgencyBean agency = _transitDataService.getAgency(_agencyId); if (agency == null) return INPUT; Calendar c = Calendar.getInstance(); long timeTo = c.getTimeInMillis(); c.add(Calendar.DAY_OF_WEEK, -_days); long timeFrom = c.getTimeInMillis(); StopProblemReportQueryBean query = new StopProblemReportQueryBean(); query.setAgencyId(_agencyId);//www.j av a 2 s. com query.setTimeFrom(timeFrom); query.setTimeTo(timeTo); if (_status != null) query.setStatus(EProblemReportStatus.valueOf(_status)); ListBean<StopProblemReportBean> result = _transitDataService.getStopProblemReports(query); List<StopProblemReportBean> reports = result.getList(); _feed = new SyndFeedImpl(); StringBuilder title = new StringBuilder(); title.append(getText("rss.OneBusAwayStopProblemReports")); title.append(" - "); title.append(agency.getName()); title.append(" - "); title.append(getText("rss.LastXDays", Arrays.asList((Object) _days))); HttpServletRequest request = ServletActionContext.getRequest(); StringBuilder b = new StringBuilder(); b.append("http://"); b.append(request.getServerName()); if (request.getServerPort() != 80) b.append(":").append(request.getServerPort()); if (request.getContextPath() != null) b.append(request.getContextPath()); String baseUrl = b.toString(); _feed.setTitle(title.toString()); _feed.setLink(baseUrl); _feed.setDescription( getText("rss.UserSubmittedStopProblemReports", Arrays.asList((Object) agency.getName(), _days))); List<SyndEntry> entries = new ArrayList<SyndEntry>(); _feed.setEntries(entries); for (StopProblemReportBean report : reports) { StopBean stop = report.getStop(); SyndEntry entry = new SyndEntryImpl(); StringBuilder entryTitle = new StringBuilder(); if (stop == null) { entryTitle.append("stopId="); entryTitle.append(report.getStopId()); entryTitle.append(" (?)"); } else { entryTitle.append(getText("StopNum", Arrays.asList(stop.getCode()))); entryTitle.append(" - "); entryTitle.append(stop.getName()); if (stop.getDirection() != null) entryTitle.append(" - ").append(getText("bound", Arrays.asList(stop.getDirection()))); } StringBuilder entryUrl = new StringBuilder(); entryUrl.append(baseUrl); entryUrl.append("/admin/problems/stop-problem-reports!edit.action?stopId="); entryUrl.append(report.getStopId()); entryUrl.append("&id="); entryUrl.append(report.getId()); StringBuilder entryDesc = new StringBuilder(); entryDesc.append(getText("Data")); entryDesc.append(": "); entryDesc.append(report.getData()); entryDesc.append("<br/>"); if (report.getUserComment() != null) { entryDesc.append(getText("Comment")); entryDesc.append(": "); entryDesc.append(report.getUserComment()); entryDesc.append("<br/>"); } if (report.getStatus() != null) { entryDesc.append(getText("Status")); entryDesc.append(": "); entryDesc.append(report.getStatus()); entryDesc.append("<br/>"); } entry = new SyndEntryImpl(); entry.setTitle(entryTitle.toString()); entry.setLink(entryUrl.toString()); entry.setPublishedDate(new Date(report.getTime())); SyndContent description = new SyndContentImpl(); description.setType("text/html"); description.setValue(entryDesc.toString()); entry.setDescription(description); entries.add(entry); } return SUCCESS; }
From source file:com.adobe.acs.commons.http.headers.impl.WeeklyExpiresHeaderFilterTest.java
@Test public void testAdjustExpiresSameDayPast() throws Exception { Calendar actual = Calendar.getInstance(); actual.set(Calendar.SECOND, 0); actual.set(Calendar.MILLISECOND, 0); Calendar expected = Calendar.getInstance(); expected.setTime(actual.getTime());/*from ww w.j a v a 2 s .c om*/ expected.add(Calendar.DAY_OF_WEEK, 7); int dayOfWeek = expected.get(Calendar.DAY_OF_WEEK); properties.put(WeeklyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_WEEK, dayOfWeek); filter.doActivate(componentContext); filter.adjustExpires(actual); assertTrue(DateUtils.isSameInstant(expected, actual)); assertEquals(dayOfWeek, actual.get(Calendar.DAY_OF_WEEK)); }
From source file:de.micmun.android.workdaystarget.DayCalculator.java
/** * Returns the number of days between today and target, skipped days in * appliance of checkedDays.//from ww w .j a v a 2 s . c om * * @param t Date of the target, to which to calculate the working days. * @param checkedDays Array with boolean flags, which says if a weekday should count * or not. * @return days to target. * @throws JSONException if an error occurs while getting the holidays from web service. */ public int getDaysLeft(Date t, boolean[] checkedDays) throws JSONException { // sets target time at midnight target.setTime(t); setMidnight(target); int sign = 1; if (target.getTimeInMillis() < today.getTimeInMillis()) { Calendar tmp = Calendar.getInstance(); tmp.setTimeInMillis(target.getTimeInMillis()); target.setTimeInMillis(today.getTimeInMillis()); today.setTimeInMillis(tmp.getTimeInMillis()); sign = -1; // negative days in the past } // Holidays ArrayList<Date> holidays = getHolidays(); // current time Calendar curr = Calendar.getInstance(); curr.setTime(today.getTime()); int count = 0; while (curr.getTimeInMillis() != target.getTimeInMillis()) { curr.add(Calendar.DAY_OF_MONTH, 1); int dayOfWeek = curr.get(Calendar.DAY_OF_WEEK); if (!checkedDays[POS_HOLIDAY] && holidays.contains(curr.getTime())) { continue; } else if (!checkedDays[POS_SUNDAY] && dayOfWeek == Calendar.SUNDAY) { continue; } else if (dayOfWeek != Calendar.SUNDAY && !checkedDays[dayOfWeek - Calendar.MONDAY]) { continue; } count++; } count *= sign; // if target is in the past, sign == -1 return count; }
From source file:net.chrisrichardson.foodToGo.domain.hibernate.HibernateRestaurantRepositoryImplMockTest.java
private Date makeDeliveryTime(int dayOfWeek, int hour, int minute) { Calendar c = Calendar.getInstance(); c.set(Calendar.DAY_OF_WEEK, dayOfWeek); c.set(Calendar.HOUR_OF_DAY, hour); c.set(Calendar.MINUTE, minute); return c.getTime(); }
From source file:ai.ilikeplaces.logic.sits9.SubscriberNotifications.java
@Override public void startTimer() { final int timeout = TGIF_TIMING == 0 ? 7 //Days of Week * 24 //Hour of Day * 60 //Minutes of Hour * 60 //Seconds of Minute * 1000 //Milliseconds of Second : TGIF_TIMING;/*from w w w.j a v a2s . com*/ final SmartLogger sl = SmartLogger.start(Loggers.LEVEL.INFO, Loggers.CODE_MEMC + "HELLO, STARTING " + this.getClass().getSimpleName() + " TIMER WITH TIMER INTERVAL:" + timeout, 60000, null, true); final Calendar _calendar = Calendar.getInstance(); final int todayDay = _calendar.get(Calendar.DAY_OF_WEEK); if (todayDay != Calendar.FRIDAY) { _calendar.add(Calendar.DAY_OF_YEAR, (Calendar.SATURDAY - todayDay + 6) % 7); } if (TGIF_TIMING == 0) { final Date _time = _calendar.getTime(); timerService.createTimer(_time, timeout, null); String format = new SimpleDateFormat("yyyy/MM/dd").format(_time); sl.appendToLogMSG("Starting timer on " + format); } else { timerService.createTimer(0, timeout, null); } if (TGIF_ON_STARTUP == 1) { final Calendar now = Calendar.getInstance(); now.add(Calendar.SECOND, 30); timerService.createTimer(now.getTime(), timeout, null); } sl.complete(Loggers.LEVEL.INFO, Loggers.DONE); }
From source file:org.davidmendoza.esu.service.impl.InicioServiceImpl.java
@Cacheable(value = "diaCache") @Transactional(readOnly = true)//from w w w .ja v a2s. c om @Override public Inicio inicio(Calendar hoy) { log.debug("Hoy: {}", hoy.getTime()); if (hoy.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY && hoy.get(Calendar.HOUR_OF_DAY) < 12) { hoy.add(Calendar.DAY_OF_WEEK, -1); } Trimestre trimestre = trimestreService.obtiene(hoy.getTime()); if (trimestre != null) { DateTime a = new DateTime(trimestre.getInicia()); DateTime b = new DateTime(hoy); Weeks c = Weeks.weeksBetween(a, b); int weeks = c.getWeeks() + 1; log.debug("Weeks: {}", weeks); StringBuilder leccion = new StringBuilder(); leccion.append("l").append(dosDigitos.format(weeks)); Inicio inicio = new Inicio(); inicio.setAnio(trimestre.getNombre().substring(0, 4)); inicio.setTrimestre(trimestre.getNombre().substring(4)); inicio.setLeccion(leccion.toString()); inicio.setDia(obtieneDia(hoy.get(Calendar.DAY_OF_WEEK))); return inicio; } else { return null; } }
From source file:strat.mining.multipool.stats.builder.MiddlecoinStatsBuilder.java
/** * Clean the stats all 10 minutes. Clean the stats that are older than 5 * days./* ww w .j a v a2 s. co m*/ */ @Scheduled(cron = "0 5/10 * * * *") public void cleanStats() { LOGGER.debug("Clean the stats."); Calendar calendar = GregorianCalendar.getInstance(); calendar.add(Calendar.DAY_OF_WEEK, -7); long startTime = System.currentTimeMillis(); int nbDeleted = globalStatsDAO.deleteGlobalStatsBefore(calendar.getTime()); PERF_LOGGER.info("{} Global Stats cleaned done in {} ms.", nbDeleted, System.currentTimeMillis() - startTime); startTime = System.currentTimeMillis(); nbDeleted = addressStatsDAO.deleteAddressStatsBefore(calendar.getTime()); PERF_LOGGER.info("{} Addresses Stats cleaned done in {} ms.", nbDeleted, System.currentTimeMillis() - startTime); }
From source file:net.firejack.platform.core.utils.DateUtils.java
/** * Truncates the date to week level/*w ww.j a v a 2s.c om*/ * @param date - date to be truncated * @return truncated date */ public static Date truncateDateToWeek(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(DateUtils.truncate(date, Calendar.DAY_OF_MONTH)); while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) { cal.add(Calendar.DAY_OF_MONTH, -1); } return cal.getTime(); }
From source file:JapaneseCalendar.java
public void paintComponent(Graphics g) { int width = 400; int height = 400; Calendar cal = Calendar.getInstance(locale); cal.setTime(new Date()); String header = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, locale); header += " " + cal.get(Calendar.YEAR); FontMetrics fm = g.getFontMetrics(); Insets insets = getInsets();//from w w w . ja va 2 s . co m g.setColor(Color.black); g.drawString(header, (width - fm.stringWidth(header)) / 2, insets.top + fm.getHeight()); DateFormatSymbols dfs = new DateFormatSymbols(locale); String[] weekdayNames = dfs.getShortWeekdays(); int fieldWidth = (width - insets.left - insets.right) / 7; g.drawString(weekdayNames[Calendar.SUNDAY], insets.left + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.SUNDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.MONDAY], insets.left + fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.MONDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.TUESDAY], insets.left + 2 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.TUESDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.WEDNESDAY], insets.left + 3 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.WEDNESDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.THURSDAY], insets.left + 4 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.THURSDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.FRIDAY], insets.left + 5 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.FRIDAY])) / 2, insets.top + 3 * fm.getHeight()); g.drawString(weekdayNames[Calendar.SATURDAY], insets.left + 6 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.SATURDAY])) / 2, insets.top + 3 * fm.getHeight()); int dom = cal.get(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, 1); int col = 0; switch (cal.get(Calendar.DAY_OF_WEEK)) { case Calendar.MONDAY: col = 1; break; case Calendar.TUESDAY: col = 2; break; case Calendar.WEDNESDAY: col = 3; break; case Calendar.THURSDAY: col = 4; break; case Calendar.FRIDAY: col = 5; break; case Calendar.SATURDAY: col = 6; } cal.set(Calendar.DAY_OF_MONTH, dom); int row = 5 * fm.getHeight(); for (int i = 1; i <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); i++) { g.drawString("" + i, insets.left + fieldWidth * col + (fieldWidth - fm.stringWidth("" + i)) / 2, row); if (++col > 6) { col = 0; row += fm.getHeight(); } } }