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.onebusaway.webapp.actions.rss.TripProblemReportsAction.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(); TripProblemReportQueryBean query = new TripProblemReportQueryBean(); query.setAgencyId(_agencyId);//from w ww . j av a 2 s . c o m query.setTimeFrom(timeFrom); query.setTimeTo(timeTo); if (_status != null) query.setStatus(EProblemReportStatus.valueOf(_status)); query.setLabel(_label); ListBean<TripProblemReportBean> result = _transitDataService.getTripProblemReports(query); List<TripProblemReportBean> reports = result.getList(); _feed = new SyndFeedImpl(); StringBuilder title = new StringBuilder(); title.append(getText("rss.OneBusAwayTripProblemReports")); 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.UserSubmittedTripProblemReports", Arrays.asList((Object) agency.getName(), _days))); List<SyndEntry> entries = new ArrayList<SyndEntry>(); _feed.setEntries(entries); for (TripProblemReportBean report : reports) { StopBean stop = report.getStop(); TripBean trip = report.getTrip(); SyndEntry entry = new SyndEntryImpl(); StringBuilder entryTitle = new StringBuilder(); if (trip == null) { entryTitle.append("trip_id="); entryTitle.append(report.getTripId()); entryTitle.append(" (?)"); } else { entryTitle.append(RoutePresenter.getNameForRoute(trip)); entryTitle.append(" - "); entryTitle.append(trip.getTripHeadsign()); } if (stop == null) { entryTitle.append(" - stop_id="); entryTitle.append(report.getStopId()); entryTitle.append(" (?)"); } else { entryTitle.append(" - "); entryTitle.append(getText("StopNum", new String[] { stop.getCode() })); entryTitle.append(" - "); entryTitle.append(stop.getName()); if (stop.getDirection() != null) { entryTitle.append(" - "); entryTitle.append(getText("bound", new String[] { stop.getDirection() })); } } StringBuilder entryUrl = new StringBuilder(); entryUrl.append(baseUrl); entryUrl.append("/admin/problems/trip-problem-report.action?tripId="); entryUrl.append(report.getTripId()); 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:net.chaosserver.timelord.swingui.ChartingPanel.java
/** * Creates the dataset to be charted./*from w ww . ja va 2 s. com*/ * * @return the dataset to be charted. */ private CategoryDataset createDataset() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Calendar calendar = Calendar.getInstance(); DateUtil.trunc(calendar); calendar.add(Calendar.DATE, -FIRST_DATE); String series1 = "Total Hours"; for (int i = 0; i < FIRST_DATE; i++) { if (Calendar.SATURDAY != calendar.get(Calendar.DAY_OF_WEEK) && Calendar.SUNDAY != calendar.get(Calendar.DAY_OF_WEEK)) { TimelordDayView timelordDayView = new TimelordDayView(timelordData, calendar.getTime()); double totalTime = timelordDayView.getTotalTimeToday(false); if (log.isTraceEnabled()) { log.trace("Creating Value of totalTime [" + totalTime + "], series1 = " + series1 + " category [" + calendar.getTime() + "]"); } dataset.addValue(totalTime, series1, calendar.getTime()); timelordDayView.dispose(); } calendar.add(Calendar.DATE, 1); } return dataset; }
From source file:heigit.ors.routing.RoutingProfilesUpdater.java
public void start() { // parse time of the format: day of the week, time, period String strDateTime = m_config.Time; String[] splitValues = strDateTime.split(","); int dayOfWeek = Integer.valueOf(splitValues[0].trim()) + 1; // Sunday is 1. m_updatePeriod = Integer.valueOf(splitValues[2].trim()); splitValues = splitValues[1].trim().split(":"); int hours = Integer.valueOf(splitValues[0].trim()); int minutes = Integer.valueOf(splitValues[1].trim()); int seconds = Integer.valueOf(splitValues[2].trim()); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_WEEK, dayOfWeek); calendar.set(Calendar.HOUR_OF_DAY, hours); calendar.set(Calendar.MINUTE, minutes); calendar.set(Calendar.SECOND, seconds); Date firstUpdateTime = calendar.getTime(); TimerTask timerTask = new UpdateTask(this); m_timer = new Timer(true); m_timer.schedule(timerTask, firstUpdateTime, m_updatePeriod); m_nextUpdate = firstUpdateTime;//from ww w. ja v a 2s . c om LOGGER.info("Profile updater is started and scheduled at " + firstUpdateTime.toString() + "."); }
From source file:net.granoeste.commons.util.DateUtils.java
/** * ?????/* www .j a va2 s . c o m*/ * * @param cal * @param amount ex) last month : -1. the current month : 0. the next month : 1 */ public static void shiftDateOnMondayOfAWeekAtTheBeginningOfTheMonth(final Calendar cal, final int amount) { cal.set(Calendar.DATE, 1); cal.add(Calendar.MONTH, amount); if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { cal.add(Calendar.DATE, -6); } else { cal.add(Calendar.DATE, -cal.get(Calendar.DAY_OF_WEEK) + 2); } }
From source file:io.apiman.gateway.engine.jdbc.JdbcMetrics.java
/** * Process the next item in the queue./* w w w .jav a 2 s .co m*/ */ @SuppressWarnings("nls") protected void processQueue() { try { RequestMetric metric = queue.take(); QueryRunner run = new QueryRunner(ds); Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("UTC")); cal.setTime(metric.getRequestStart()); long rstart = cal.getTimeInMillis(); long rend = metric.getRequestEnd().getTime(); long duration = metric.getRequestDuration(); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); long minute = cal.getTimeInMillis(); cal.set(Calendar.MINUTE, 0); long hour = cal.getTimeInMillis(); cal.set(Calendar.HOUR_OF_DAY, 0); long day = cal.getTimeInMillis(); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); long week = cal.getTimeInMillis(); cal.set(Calendar.DAY_OF_MONTH, 1); long month = cal.getTimeInMillis(); String api_org_id = metric.getApiOrgId(); String api_id = metric.getApiId(); String api_version = metric.getApiVersion(); String client_org_id = metric.getClientOrgId(); String client_id = metric.getClientId(); String client_version = metric.getClientVersion(); String plan = metric.getPlanId(); String user_id = metric.getUser(); String rtype = null; if (metric.isFailure()) { rtype = "failure"; } else if (metric.isError()) { rtype = "error"; } long bytes_up = metric.getBytesUploaded(); long bytes_down = metric.getBytesDownloaded(); // Now insert a row for the metric. run.update("INSERT INTO gw_requests (" + "rstart, rend, duration, month, week, day, hour, minute, " + "api_org_id, api_id, api_version, " + "client_org_id, client_id, client_version, plan, " + "user_id, resp_type, bytes_up, bytes_down) VALUES (" + "?, ?, ?, ?, ?, ?, ?, ?," + "?, ?, ?," + "?, ?, ?, ?," + "?, ?, ?, ?)", rstart, rend, duration, month, week, day, hour, minute, api_org_id, api_id, api_version, client_org_id, client_id, client_version, plan, user_id, rtype, bytes_up, bytes_down); } catch (InterruptedException ie) { // This means that the thread was stopped. } catch (Exception e) { // TODO better logging of this unlikely error System.err.println("Error adding metric to database:"); //$NON-NLS-1$ e.printStackTrace(); return; } }
From source file:org.sharetask.service.StatisticsServiceImpl.java
private StatisticsDataDTO getStatisticsPerLastWeek() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek()); Date date = DateUtils.truncate(calendar.getTime(), Calendar.DATE); return new StatisticsDataDTO.Builder().usersCount(userInformationRepository.getCountCreatedAfter(date)) .workspacesCount(workspaceRepository.getCountCreatedAfter(date)) .tasksCount(taskRepository.getCountCreatedAfter(date)).build(); }
From source file:com.ozpathway.sw.erms.webapp.action.schedule.ScheduleBean.java
public void addSampleHoliday(ActionEvent event) { if (model instanceof SimpleScheduleModel) { SimpleScheduleModel ssm = (SimpleScheduleModel) model; Calendar calendar = GregorianCalendar.getInstance(); calendar.setTime(ssm.getSelectedDate()); calendar.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY); ssm.setHoliday(calendar.getTime(), "Poeperkesdag"); ssm.refresh();/* ww w . j a v a 2 s. c o m*/ } }
From source file:fr.paris.lutece.plugins.calendar.web.SmallMonthCalendar.java
/** * Provides a small HTML month calendar displaying days with links * @return The HTML code of the month.// w ww. j a v a 2s. c o m * @param options The options which contains displaying settings * @param strDate The code date defining the month to display * @param agenda An agenda to hilight some days. * @param bIsSelectedDay true if the date is the selected day, false * otherwise */ public static String getSmallMonthCalendar(String strDate, Agenda agenda, CalendarUserOptions options, boolean bIsSelectedDay) { Map<String, Object> model = new HashMap<String, Object>(); Calendar calendar = new GregorianCalendar(); calendar.set(Utils.getYear(strDate), Utils.getMonth(strDate), 1); Calendar firstDayOfMonth = new GregorianCalendar(); firstDayOfMonth.set(Utils.getYear(strDate), Utils.getMonth(strDate), calendar.getMinimum(Calendar.DAY_OF_MONTH)); Date dFirstDayOfMonth = firstDayOfMonth.getTime(); Calendar lastDayOfMonth = new GregorianCalendar(); lastDayOfMonth.set(Utils.getYear(strDate), Utils.getMonth(strDate), calendar.getMaximum(Calendar.DAY_OF_MONTH)); Date dLastDayOfMonth = lastDayOfMonth.getTime(); int nDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); if (nDayOfWeek == 1) { nDayOfWeek = 8; } StringBuffer sbWeeks = new StringBuffer(); boolean bDone = false; boolean bStarted = false; while (!bDone) { Map<String, Object> weekModel = new HashMap<String, Object>(); //HtmlTemplate tWeek = new HtmlTemplate( templateWeek ); StringBuffer sbDays = new StringBuffer(); for (int i = 0; i < 7; i++) { if ((((i + 2) != nDayOfWeek) && !bStarted) || bDone) { sbDays.append(AppTemplateService.getTemplate(TEMPLATE_EMPTY_DAY).getHtml()); continue; } bStarted = true; if (strDate.equals(Utils.getDate(calendar)) && bIsSelectedDay) { sbDays.append(getDay(calendar, agenda, options, true)); } else { sbDays.append(getDay(calendar, agenda, options, false)); } int nDay = calendar.get(Calendar.DAY_OF_MONTH); calendar.roll(Calendar.DAY_OF_MONTH, true); int nNewDay = calendar.get(Calendar.DAY_OF_MONTH); if (nNewDay < nDay) { bDone = true; } } weekModel.put(Constants.MARK_DAYS, sbDays.toString()); sbWeeks.append(AppTemplateService.getTemplate(TEMPLATE_WEEK, options.getLocale(), weekModel).getHtml()); } model.put(Constants.MARK_MONTH_LABEL, Utils.getMonthLabel(strDate, options.getLocale())); model.put(Constants.MARK_PREVIOUS, Utils.getPreviousMonth(strDate)); model.put(Constants.MARK_DATE, strDate); model.put(Constants.MARK_NEXT, Utils.getNextMonth(strDate)); model.put(Constants.MARK_DATE_START, dFirstDayOfMonth); model.put(Constants.MARK_DATE_END, dLastDayOfMonth); model.put(Constants.MARK_WEEKS, sbWeeks.toString()); model.put(Constants.MARK_JSP_URL, AppPropertiesService.getProperty(Constants.PROPERTY_RUNAPP_JSP_URL)); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_VIEW_MONTH, options.getLocale(), model); return template.getHtml(); }
From source file:com.ocs.dynamo.utils.DateUtils.java
/** * Translates a week code (yyyy-ww) to the starting day (this is taken to be a Monday) of that * week//from www.j a v a 2 s . co m * * @param weekCode * @return */ public static Date getStartDateOfWeek(String weekCode) { if (weekCode != null && weekCode.matches(WEEK_CODE_PATTERN)) { int year = getYearFromWeekCode(weekCode); int week = getWeekFromWeekCode(weekCode); Calendar calendar = new GregorianCalendar(DynamoConstants.DEFAULT_LOCALE); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.WEEK_OF_YEAR, week); calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); return truncate(calendar).getTime(); } return null; }
From source file:nl.surfnet.coin.teams.service.impl.TeamInviteServiceHibernateImplTest.java
@Test public void testFindAllInvitationById() throws Exception { Invitation invitation = new Invitation(email, team.getId()); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_WEEK, -20); invitation.setTimestamp(calendar.getTimeInMillis()); String hash = invitation.getInvitationHash(); assertNull(teamInviteService.findInvitationByInviteId(hash)); teamInviteService.saveOrUpdate(invitation); }