List of usage examples for java.util Calendar DAY_OF_YEAR
int DAY_OF_YEAR
To view the source code for java.util Calendar DAY_OF_YEAR.
Click Source Link
get
and set
indicating the day number within the current year. From source file:org.pentaho.telemetry.TelemetryEventSender.java
@Override public void run() { //Delete everything in lastSubmission folder File[] submittedFiles = this.getLastSubmissionDir().listFiles(); for (File f : submittedFiles) { f.delete();//from w w w . j a va2 s .c o m } //Get all requests in telemetryPath File[] unsubmittedRequests = this.getTelemetryDir().listFiles(new FilenameFilter() { @Override public boolean accept(File file, String name) { return name.endsWith(FILE_EXT); } }); File[] block = new File[BLOCK_SIZE]; int blockIndex = 0; Calendar cld = Calendar.getInstance(); cld.add(Calendar.DAY_OF_YEAR, -DAYS_TO_KEEP_FILES); for (File f : unsubmittedRequests) { //Check if file was created more than 5 days ago. If so, dismiss it if (f.lastModified() < cld.getTime().getTime()) { f.delete(); continue; } //Create blocks of BLOCK_SIZE if (blockIndex > 0 && blockIndex % BLOCK_SIZE == 0) { sendRequest(block); block = new File[BLOCK_SIZE]; blockIndex = 0; } else { block[blockIndex] = f; blockIndex++; } } if (blockIndex > 0) { sendRequest(block); } }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.group.AddBookingRoomViewParamsController.java
@Override public Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { Map map = new HashMap<String, Object>(); int filterGroup = Integer.parseInt(request.getParameter("filterGroup")); String filterDate = request.getParameter("filterDate"); if (filterDate.compareTo("") == 0) filterDate = null;/*from w ww.j a v a 2 s .c om*/ int repType = Integer.parseInt(request.getParameter("repType")); int repCount = Integer.parseInt(request.getParameter("repCount")); String date = request.getParameter("date"); String startStr = request.getParameter("startTime"); String endStr = request.getParameter("endTime"); GregorianCalendar cal = BookingRoomUtils.getCalendar(startStr); boolean collisions = false; //reservations in not visible time period if (repCount > 0) { GregorianCalendar nextS = BookingRoomUtils.getCalendar(startStr); GregorianCalendar nextE = BookingRoomUtils.getCalendar(endStr); List<Reservation> coll = BookingRoomUtils.getCollisions(reservationDao, repCount, repType, nextS, nextE); map.put("collisionsInNext", coll); map.put("collisionsInNextCount", coll.size()); if (coll.size() > 0) collisions = true; } //reservations in currently visible time period cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); GregorianCalendar weekStart = BookingRoomUtils.getCalendar(BookingRoomUtils.getDate(cal) + " 00:00:00"); GregorianCalendar weekEnd = (GregorianCalendar) weekStart.clone(); weekEnd.add(Calendar.DAY_OF_YEAR, 7); weekEnd.add(Calendar.SECOND, -1); map.put("reservations", reservationDao.getReservationsBetween(weekStart, weekEnd, filterDate, filterGroup)); map.put("timerange", date + " " + BookingRoomUtils.getHoursAndMinutes(startStr) + " - " + BookingRoomUtils.getHoursAndMinutes(endStr)); String displayed = String.format( messageSource.getMessage("bookRoom.displayed.week", null, RequestContextUtils.getLocale(request)), BookingRoomUtils.getDate(weekStart), BookingRoomUtils.getDate(weekEnd)); boolean filtered = false; if (filterDate != null) {//filter of date filtered = true; displayed = messageSource.getMessage("bookRoom.displayed.day", null, RequestContextUtils.getLocale(request)) + " " + filterDate; } if (filterGroup > 0) { filtered = true; displayed += (filterDate == null ? "," : " and") + " " + messageSource.getMessage("bookRoom.displayed.group", null, RequestContextUtils.getLocale(request)) + " " + getResearchGroup(filterGroup).getTitle(); } if (filtered) {//we must verify that there are no reservations in selected range GregorianCalendar start = BookingRoomUtils.getCalendar(startStr); GregorianCalendar end = BookingRoomUtils.getCalendar(endStr); List<Reservation> coll = reservationDao.getReservationsBetween(start, end); if (coll.size() > 0) { //if the collision exists collisions = true; map.put("collisions", coll); map.put("collisionsCount", coll.size()); } } map.put("displayed", displayed); map.put("collisionsExist", (collisions) ? "1" : "0"); /* -- JSP can get this from params object -- map.put("repCount", repCount); map.put("repType", repType); map.put("group", group); map.put("date", date);*/ map.put("startTime", BookingRoomUtils.getHoursAndMinutes(startStr).replaceAll(":", "")); map.put("endTime", BookingRoomUtils.getHoursAndMinutes(endStr).replaceAll(":", "")); map.put("loggedUser", personDao.getLoggedPerson()); GroupMultiController.setPermissionToRequestGroupRole(map, personDao.getLoggedPerson()); return map; }
From source file:cz.zcu.kiv.eegdatabase.logic.pdf.ReservationPDF.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { try {/*from w ww. j a v a 2 s. c o m*/ if (request.getParameter("type").compareTo("single") == 0) { int id = Integer.parseInt(request.getParameter("reservationId")); Reservation reservation = reservationDao.getReservationById(id); response.setHeader("Content-Type", "application/pdf"); response.setHeader("Content-Disposition", "attachment;filename=reservation-" + id + ".pdf"); Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); document.open(); PDFUtils utils = new PDFUtils(getServletContext().getRealPath("/")); document.add(utils.setHeader(document, "Reservation listing")); /*Paragraph paragraph = new Paragraph("Reservation #" + id, FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, BaseColor.BLACK)); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.setSpacingBefore(10); paragraph.setSpacingAfter(10); document.add(paragraph);*/ document.add(formatReservation(reservation)); document.close(); response.flushBuffer(); return null; } if (request.getParameter("type").compareTo("range") == 0) { String date = request.getParameter("date") + " 00:00:00"; GregorianCalendar rangeStart = BookingRoomUtils.getCalendar(date); int length = Integer.parseInt(request.getParameter("length")); GregorianCalendar rangeEnd = (GregorianCalendar) rangeStart.clone(); rangeEnd.add(Calendar.DAY_OF_YEAR, length); response.setHeader("Content-Type", "application/pdf"); response.setHeader("Content-Disposition", "attachment;filename=reservations.pdf"); Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); document.open(); PDFUtils utils = new PDFUtils(getServletContext().getRealPath("/")); document.add(utils.setHeader(document, "Reservations listing")); java.util.List<Reservation> reservations = reservationDao.getReservationsBetween(rangeStart, rangeEnd, "", 0); int count = 0; for (Reservation reservation : reservations) { document.add(formatReservation(reservation)); if (++count % 6 == 0) { document.newPage(); document.add(utils.setHeader(document, "Reservations listing")); } } document.close(); response.flushBuffer(); return null; } return null; } catch (Exception e) { ModelAndView mav = new ModelAndView(getFormView()); Map data = new HashMap<String, Object>(); data.put("error", e.getMessage()); mav.addAllObjects(data); return mav; } }
From source file:com.netflix.simianarmy.resources.chaos.ChaosMonkeyResource.java
/** * Gets the chaos events. Creates GET /api/v1/chaos api which outputs the chaos events in json. Users can specify * cgi query params to filter the results and use "since" query param to set the start of a timerange. "since" will * number of milliseconds since the epoch. * * @param uriInfo//from w w w. j a v a 2s. c o m * the uri info * @return the chaos events json response * @throws IOException * Signals that an I/O exception has occurred. */ @GET public Response getChaosEvents(@Context UriInfo uriInfo) throws IOException { Map<String, String> query = new HashMap<String, String>(); Date date = null; for (Map.Entry<String, List<String>> pair : uriInfo.getQueryParameters().entrySet()) { if (pair.getValue().isEmpty()) { continue; } if (pair.getKey().equals("since")) { date = new Date(Long.parseLong(pair.getValue().get(0))); } else { query.put(pair.getKey(), pair.getValue().get(0)); } } // if "since" not set, default to 24 hours ago if (date == null) { Calendar now = monkey.context().calendar().now(); now.add(Calendar.DAY_OF_YEAR, -1); date = now.getTime(); } List<Event> evts = monkey.context().recorder().findEvents(ChaosMonkey.Type.CHAOS, ChaosMonkey.EventTypes.CHAOS_TERMINATION, query, date); ByteArrayOutputStream baos = new ByteArrayOutputStream(); JsonGenerator gen = JSON_FACTORY.createJsonGenerator(baos, JsonEncoding.UTF8); gen.writeStartArray(); for (Event evt : evts) { gen.writeStartObject(); gen.writeStringField("monkeyType", evt.monkeyType().name()); gen.writeStringField("eventType", evt.eventType().name()); gen.writeNumberField("eventTime", evt.eventTime().getTime()); gen.writeStringField("region", evt.region()); for (Map.Entry<String, String> pair : evt.fields().entrySet()) { gen.writeStringField(pair.getKey(), pair.getValue()); } gen.writeEndObject(); } gen.writeEndArray(); gen.close(); return Response.status(Response.Status.OK).entity(baos.toString("UTF-8")).build(); }
From source file:org.jrecruiter.service.system.impl.SystemSetupServiceImpl.java
/** {@inheritDoc} */ @Override/*from w w w .j a v a2 s. c om*/ public void createDemoJobs(final User user, final Integer numberOfJobsToCreate) { final LoremIpsum loremIpsum = new LoremIpsum(); Random random = new Random(); final Industry demoIndustry = industryDao.get(1L); if (demoIndustry == null) { throw new IllegalStateException(String.format("No industry found for Id %s", 1L)); } final Region demoRegion = regionDao.get(1L); if (demoRegion == null) { throw new IllegalStateException(String.format("No regions found for Id %s", 2L)); } for (int i = 0; i <= numberOfJobsToCreate; i++) { final Job job = new Job(); job.setBusinessAddress1(loremIpsum.getWords(2)); job.setBusinessAddress2(loremIpsum.getWords(3)); job.setBusinessCity(loremIpsum.getWords(2)); job.setBusinessEmail(loremIpsum.getWords(1) + "@" + loremIpsum.getWords(1) + ".com"); job.setBusinessName(loremIpsum.getWords(2)); job.setBusinessPhone("111-111-1111"); job.setBusinessPhoneExtension("111-111-1111"); job.setBusinessState(loremIpsum.getWords(1)); job.setBusinessZip(loremIpsum.getWords(1)); job.setDescription(loremIpsum.getParagraphs(2)); job.setIndustry(demoIndustry); job.setJobRestrictions(loremIpsum.getWords(30)); job.setJobTitle(loremIpsum.getWords(2)); job.setLatitude(BigDecimal.TEN); job.setLongitude(BigDecimal.TEN); job.setOfferedBy(OfferedBy.RECRUITER); if (i % 2 == 0) { job.setRegion(demoRegion); } else { job.setRegionOther("Some Other Region"); } Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_YEAR, random.nextInt(200)); job.setRegistrationDate(cal.getTime()); job.setUpdateDate(cal.getTime()); job.setSalary("100000.50"); job.setStatus(JobStatus.ACTIVE); job.setUser(user); job.setUsesMap(Boolean.TRUE); job.setWebsite("http://www.google.com/"); this.jobDao.save(job); } }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java
/** * Decrease the actual chosen view. (DAY / MONTH / WEEK/ YEAR) *//*w w w . ja v a 2 s. c o m*/ protected final void decrement() { switch (actualView) { case DAY: actualDay.add(Calendar.DAY_OF_YEAR, -1); break; case WEEK: actualDay.add(Calendar.WEEK_OF_YEAR, -1); break; case MONTH: actualDay.add(Calendar.MONTH, -1); break; case YEAR: actualDay.add(Calendar.YEAR, -1); break; default: break; } changeView(actualView); }
From source file:it.infn.mw.iam.test.repository.IamTokenRepositoryTests.java
@Test public void testExpiredTokensAreNotReturned() { OAuth2AccessTokenEntity at = buildAccessToken(loadTestClient(), TEST_347_USER); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, -1); Date yesterday = cal.getTime(); at.setExpiration(yesterday);/*from w w w. j a v a 2s .co m*/ at.getRefreshToken().setExpiration(yesterday); tokenService.saveAccessToken(at); tokenService.saveRefreshToken(at.getRefreshToken()); Date currentTimestamp = new Date(); assertThat(accessTokenRepo.findValidAccessTokensForUser(TEST_347_USER, currentTimestamp), hasSize(0)); assertThat(refreshTokenRepo.findValidRefreshTokensForUser(TEST_347_USER, currentTimestamp), hasSize(0)); }
From source file:net.audumla.climate.bom.BOMSimpleClimateForcastObserver.java
public void loadLatestForcast() { try {/*from w ww . j a v a 2 s . co m*/ CSVReader reader = new CSVReader(BOMDataLoader.instance().getData(BOMDataLoader.FTP, BOMDataLoader.BOMFTP, getLatestForcastFile())); String[] line = reader.readNext(); Matcher m = forcastDatePattern.matcher(line[0]); if (m.find()) { Date forcastDate = forcastDateFormat.parse(m.group(1)); while ((line = reader.readNext()) != null) { if (source.getId().equals(line[0].replace("\"", ""))) { for (int c = 0; c < line.length; ++c) { line[c] = line[c].replace("-9999", "error").trim(); } // stn[7] , per, evap, amax, amin, gmin, suns, rain, prob WritableClimateData bforcast = ClimateDataFactory.newWritableClimateData(this, getSource()); int day = Integer.parseInt(line[1]); Calendar c = GregorianCalendar.getInstance(); c.setTime(new Date(forcastDate.getTime())); c.set(Calendar.DAY_OF_YEAR, c.get(Calendar.DAY_OF_YEAR) + day); bforcast.setTime(c.getTime()); try { bforcast.setEvaporation(Double.parseDouble(line[2])); } catch (Exception ignored) { } try { bforcast.setMaximumTemperature(Double.parseDouble(line[3])); } catch (Exception ignored) { } try { bforcast.setMinimumTemperature(Double.parseDouble(line[4])); } catch (Exception ignored) { } try { bforcast.setSunshineHours(Double.parseDouble(line[6])); } catch (Exception ignored) { } try { bforcast.setRainfall(Double.parseDouble(line[7])); } catch (Exception ignored) { } try { bforcast.setRainfallProbability(Double.parseDouble(line[8])); } catch (Exception ignored) { } forcastData.put(c.getTime(), bforcast); } } } else { throw new UnsupportedOperationException("Cannot find forecast date in file"); } } catch (Exception e) { throw new UnsupportedOperationException("Error reading BOM forcast", e); } }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.DateUtils.java
/** * Return the next day from the given day (the next day at 00:00) * * @param day the day to calculate the next day for * @return the next day from the given day *///from w ww. j av a 2 s . c o m public static Calendar getNextDayFrom(final Calendar day) { day.set(Calendar.HOUR_OF_DAY, 0); day.set(Calendar.MINUTE, 0); day.set(Calendar.SECOND, 0); day.set(Calendar.MILLISECOND, 0); // Next day day.add(Calendar.DAY_OF_YEAR, 1); return day; }
From source file:io.github.sparta.helpers.date.DateUtil.java
/** * Add days on date./*from w ww. j a v a2s .com*/ * * @param date * base date * @param days * days to be added. * @return added Date */ public static Date addDay(Date date, int days) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.DAY_OF_YEAR, days); return cal.getTime(); }