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.craftercms.commerce.client.itest.data.SolrTestDataService.java
public TestProduct testProduct(int i) { Calendar cal = new GregorianCalendar(); cal.setTime(SolrTestDataService.START_TIME); cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + i); cal.set(Calendar.DAY_OF_YEAR, Calendar.DAY_OF_YEAR + i); cal.set(Calendar.HOUR_OF_DAY, 1); cal.set(Calendar.MINUTE, 1);//from w w w.j av a 2 s .co m cal.set(Calendar.SECOND, 1); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 1); TestProduct product = new TestProduct(); product.setId("product-" + i); product.setName("product-" + i + "-name"); product.setCreatedBy("product-" + i + "-created-by"); product.setCreationDate(cal.getTime()); product.setLastModifiedBy("product-" + i + "-modified-by"); product.setLastModifiedDate(cal.getTime()); product.setDescription("product-" + i + "-description"); if (i < 20) { // 0-19 product.category_s = "A"; product.size_i = 1; product.listPrice_f = (float) 15.99; cal.set(Calendar.DAY_OF_YEAR, Calendar.DAY_OF_YEAR + 10); product.expirationDate_d = cal.getTime(); product.inStock_b = true; product.tags_s_mv[0] = "abc"; product.tags_s_mv[1] = "def"; product.tags_s_mv[2] = "efg"; product.sizes_i_mv[0] = 12; product.sizes_i_mv[1] = 13; product.sizes_i_mv[2] = 14; product.sizes_i_mv[3] = 15; product.listPrices_f_mv[0] = (float) 2.3; product.listPrices_f_mv[1] = (float) 3.2; cal.set(Calendar.DAY_OF_YEAR, 1); product.launchDate_d_mv[0] = cal.getTime(); product.booleanMulti_b_mv[0] = true; product.booleanMulti_b_mv[1] = true; product.booleanMulti_b_mv[2] = false; } else if (i < 50) { // 20-49 product.category_s = "B"; product.size_i = 2; product.listPrice_f = (float) 20.99; cal.set(Calendar.DAY_OF_YEAR, Calendar.DAY_OF_YEAR + 20); product.expirationDate_d = cal.getTime(); product.inStock_b = false; product.tags_s_mv[0] = "hij"; product.tags_s_mv[1] = "klm"; product.tags_s_mv[2] = "nop"; product.sizes_i_mv[0] = 8; product.sizes_i_mv[1] = 10; product.sizes_i_mv[2] = 12; product.sizes_i_mv[3] = 14; product.listPrices_f_mv[0] = (float) 18.34; product.listPrices_f_mv[1] = (float) 39.21; cal.set(Calendar.DAY_OF_YEAR, 2); product.launchDate_d_mv[0] = cal.getTime(); product.booleanMulti_b_mv[0] = false; product.booleanMulti_b_mv[1] = true; product.booleanMulti_b_mv[2] = false; } else if (i < 90) { // 50-89 product.category_s = "C"; product.size_i = 3; product.listPrice_f = (float) 25.99; cal.set(Calendar.DAY_OF_YEAR, Calendar.DAY_OF_YEAR + 30); product.expirationDate_d = cal.getTime(); product.inStock_b = true; product.tags_s_mv[0] = "qrs"; product.tags_s_mv[1] = "tuv"; product.tags_s_mv[2] = "xyz"; product.sizes_i_mv[0] = 21; product.sizes_i_mv[1] = 9; product.sizes_i_mv[2] = 3; product.sizes_i_mv[3] = 18; product.listPrices_f_mv[0] = (float) 12.3; product.listPrices_f_mv[1] = (float) 32.2; cal.set(Calendar.DAY_OF_YEAR, 3); product.launchDate_d_mv[0] = cal.getTime(); product.booleanMulti_b_mv[0] = true; product.booleanMulti_b_mv[1] = true; product.booleanMulti_b_mv[2] = true; } else { // 90-99 product.category_s = "D"; product.size_i = 4; product.listPrice_f = (float) 30.99; cal.set(Calendar.DAY_OF_YEAR, Calendar.DAY_OF_YEAR + 40); product.expirationDate_d = cal.getTime(); product.inStock_b = false; product.tags_s_mv[0] = "bcd"; product.tags_s_mv[1] = "efg"; product.tags_s_mv[2] = "hij"; product.sizes_i_mv[0] = 41; product.sizes_i_mv[1] = 12; product.sizes_i_mv[2] = 1; product.sizes_i_mv[3] = 19; product.listPrices_f_mv[0] = (float) 32.33; product.listPrices_f_mv[1] = (float) 42.21; cal.set(Calendar.DAY_OF_YEAR, 4); product.launchDate_d_mv[0] = cal.getTime(); product.booleanMulti_b_mv[0] = false; product.booleanMulti_b_mv[1] = false; product.booleanMulti_b_mv[2] = false; } return product; }
From source file:com.ms.app.web.commons.tools.DateViewTools.java
public static boolean isSameDay(Calendar cal1, Calendar cal2) { return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR); }
From source file:com.redhat.rhn.frontend.action.errata.ErrataSearchAction.java
protected ActionForward doExecute(HttpServletRequest request, ActionMapping mapping, DynaActionForm form) throws MalformedURLException, XmlRpcFault { RequestContext ctx = new RequestContext(request); String search = form.getString(SEARCH_STR); String viewmode = form.getString(VIEW_MODE); Boolean fineGrained = (Boolean) form.get(FINE_GRAINED); List searchOptions = new ArrayList(); // setup the option list for select box (view_mode). addOption(searchOptions, OPT_ALL_FIELDS, OPT_ALL_FIELDS); addOption(searchOptions, OPT_ADVISORY, OPT_ADVISORY); addOption(searchOptions, OPT_PKG_NAME, OPT_PKG_NAME); addOption(searchOptions, OPT_CVE, OPT_CVE); request.setAttribute(SEARCH_STR, search); request.setAttribute(VIEW_MODE, viewmode); request.setAttribute(SEARCH_OPT, searchOptions); request.setAttribute(FINE_GRAINED, fineGrained); // Process the dates, default the start date to yesterday // and end date to today. Calendar today = Calendar.getInstance(); today.setTime(new Date()); Calendar yesterday = Calendar.getInstance(); yesterday.setTime(new Date()); yesterday.add(Calendar.DAY_OF_YEAR, -1); DateRangePicker picker = new DateRangePicker(form, request, yesterday.getTime(), today.getTime(), DatePicker.YEAR_RANGE_NEGATIVE, "erratasearch.jsp.start_date", "erratasearch.jsp.end_date"); DatePickerResults dates = null;/*from w ww . ja v a2 s . c om*/ Boolean dateSearch = getOptionIssueDateSearch(request); /* * If search/viewmode aren't null, we need to search and set * pageList to the resulting DataResult. * * NOTE: There is a special case when called from rhn/Search.do * (header search bar) * that we will be coming into this action and running the * performSearch on the first run through this action, i.e. * we'll never have been called with search being blank, * therefore normal setup of the form vars will not have happened. */ if (!StringUtils.isBlank(search) || dateSearch) { // If doing a dateSearch use the DatePicker values from the // request params otherwise use the defaults. dates = picker.processDatePickers(dateSearch, true); if (LOG.isDebugEnabled()) { LOG.debug("search is NOT blank"); LOG.debug("Issue Start Date = " + dates.getStart().getDate()); LOG.debug("End Start Date = " + dates.getEnd().getDate()); } List results = performSearch(request, ctx.getWebSession().getId(), search, viewmode, form); request.setAttribute(RequestContext.PAGE_LIST, results != null ? results : Collections.EMPTY_LIST); } else { // Reset info on date pickers dates = picker.processDatePickers(false, true); if (LOG.isDebugEnabled()) { LOG.debug("search is blank"); LOG.debug("Issue Start Date = " + dates.getStart().getDate()); LOG.debug("End Start Date = " + dates.getEnd().getDate()); } request.setAttribute(RequestContext.PAGE_LIST, Collections.EMPTY_LIST); } ActionMessages dateErrors = dates.getErrors(); addErrors(request, dateErrors); return mapping.findForward(RhnHelper.DEFAULT_FORWARD); }
From source file:com.netflix.simianarmy.basic.BasicCalendar.java
/** * Checks if is holiday.// ww w. jav a 2 s . c o m * * @param now * the current time * @return true, if is holiday */ protected boolean isHoliday(Calendar now) { if (!holidays.contains(now.get(Calendar.YEAR))) { loadHolidays(now.get(Calendar.YEAR)); } return holidays.contains(now.get(Calendar.DAY_OF_YEAR)); }
From source file:org.oscarehr.common.service.E2ESchedulerJob.java
@Override public void run() { DemographicDao demographicDao = SpringUtils.getBean(DemographicDao.class); OscarLogDao oscarLogDao = SpringUtils.getBean(OscarLogDao.class); StringBuilder sb = new StringBuilder(255); int success = 0; int failure = 0; int skipped = 0; int diffDays = 14; List<Integer> ids = null; try {/*w w w. j ava 2 s .co m*/ // Gather demographic numbers for specified mode of operation if (diffMode) { if (e2eDiffDays != null && StringUtils.isNumeric(e2eDiffDays)) { diffDays = Integer.parseInt(e2eDiffDays); } Calendar cal = GregorianCalendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, -diffDays); ids = oscarLogDao.getDemographicIdsOpenedSinceTime(cal.getTime()); } else { ids = demographicDao.getActiveDemographicIds(); } if (ids != null) Collections.sort(ids); // Log Start Header StringBuilder sbStart = reuseStringBuilder(sb); sbStart.append("Starting E2E export job\nE2E Target URL: ").append(e2eUrl); if (diffMode) { sbStart.append("\nExport Mode: Differential - Days: ").append(diffDays); } else { sbStart.append("\nExport Mode: Full"); } logger.info(sbStart.toString()); StringBuilder sbStartRec = reuseStringBuilder(sb); sbStartRec.append(ids.size()).append(" records pending"); if (ids.size() > 0) { sbStartRec.append("\nRange: ").append(ids.get(0)).append(" - ").append(ids.get(ids.size() - 1)); sbStartRec.append(", Median: ").append(ids.get((ids.size() - 1) / 2)); } logger.info(sbStartRec.toString()); long startJob = System.currentTimeMillis(); long endJob = startJob; for (Integer id : ids) { // Select Template E2EVelocityTemplate t = new E2EVelocityTemplate(); // Create and load Patient data long startLoad = System.currentTimeMillis(); E2EPatientExport patient = new E2EPatientExport(); patient.setExAllTrue(); long endLoad = startLoad; long startTemplate = 0; long endTemplate = startTemplate; // Load patient data and merge to template String output = ""; if (patient.loadPatient(id.toString())) { endLoad = System.currentTimeMillis(); if (patient.isActive()) { startTemplate = System.currentTimeMillis(); output = t.export(patient); endTemplate = System.currentTimeMillis(); } else { logger.info("[Demo: ".concat(id.toString()).concat("] Not active - skipped")); skipped++; continue; } } else { endLoad = System.currentTimeMillis(); logger.error("[Demo: ".concat(id.toString()).concat("] Failed to load")); failure++; continue; } long startPost = System.currentTimeMillis(); long endPost = startPost; // Attempt to perform HTTP POST request try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(e2eUrl); // Assemble Multi-part Request StringBuilder sbFile = reuseStringBuilder(sb); sbFile.append("output_").append(id).append(".xml"); ByteArrayBody body = new ByteArrayBody(output.getBytes(), "text/xml", sbFile.toString()); MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("content", body); httpPost.setEntity(reqEntity); // Send HTTP POST request HttpResponse response = httpclient.execute(httpPost); if (response != null && response.getStatusLine().getStatusCode() == 201) { success++; } else { logger.warn(response.getStatusLine()); failure++; } } catch (HttpHostConnectException e) { logger.error("Connection to ".concat(e2eUrl).concat(" refused")); failure++; } catch (NoRouteToHostException e) { logger.error("Can't resolve route to ".concat(e2eUrl)); failure++; } catch (Exception e) { logger.error("Error", e); failure++; } finally { endPost = System.currentTimeMillis(); } // Log Record completion + benchmarks StringBuilder sbTimer = reuseStringBuilder(sb); sbTimer.append("[Demo: ").append(id); sbTimer.append("] L:").append((endLoad - startLoad) / 1000.0); sbTimer.append(" T:").append((endTemplate - startTemplate) / 1000.0); sbTimer.append(" P:").append((endPost - startPost) / 1000.0); logger.info(sbTimer.toString()); } endJob = System.currentTimeMillis(); logger.info("Done E2E export job (" + convertTime(endJob - startJob) + ")"); } catch (Throwable e) { logger.error("Error", e); logger.info("E2E export job aborted"); } finally { // Log final record counts int unaccounted = ids.size() - success - failure - skipped; sb = reuseStringBuilder(sb); sb.append(success).append(" records processed"); if (failure > 0) sb.append("\n").append(failure).append(" records failed"); if (skipped > 0) sb.append("\n").append(skipped).append(" records skipped"); if (unaccounted > 0) sb.append("\n").append(unaccounted).append(" records unaccounted"); logger.info(sb.toString()); DbConnectionFilter.releaseAllThreadDbResources(); } }
From source file:net.audumla.climate.bom.BOMStatisticalClimateDataObserver.java
private WritableClimateObservation getObservation(WritableClimateData bomdata, int hour) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(0);// w w w .j av a 2 s. co m c.set(Calendar.HOUR_OF_DAY, hour); Date requiredTime = c.getTime(); WritableClimateObservation obs = null; try { obs = ClimateDataFactory.convertToWritableClimateObservation( bomdata.getObservation(requiredTime, ClimateData.ObservationMatch.CLOSEST)); if (obs != null && DateUtils.getFragmentInHours(obs.getTime(), Calendar.DAY_OF_YEAR) == hour) { return obs; } } catch (Exception ignored) { logger.error(ignored); ignored.printStackTrace(); } obs = ClimateDataFactory.newWritableClimateObservation(this, getSource()); obs.setTime(requiredTime); bomdata.addObservation(obs); return obs; }
From source file:de.tbuchloh.kiskis.persistence.importer.CSVImportTest.java
/** * Test fr ImportExample/*from www . j a v a2 s. c o m*/ * * @throws Exception * wenn unvorhergesehene Fehler auftreten. */ public void testImportExample() throws Exception { final TPMDocument doc = StandardDocumentFactory.createStandardDocument(new File("")); final int initialSize = 10; final Group rootNode = doc.getGroups(); assertEquals(initialSize, rootNode.preOrder().size()); final TestMessageListener msg = new TestMessageListener(); final CSVImport cvs = new CSVImport(msg, doc); cvs.doImport(new File("xml/example-import.csv"), ','); assertEquals(2, msg.getMessages().size()); final int accounts = 11, groups = 5; assertEquals(initialSize + accounts + groups, rootNode.preOrder().size()); assertUsername(rootNode, "Amazon", "amazon.foo"); assertEmail(rootNode, "Amazon", "mail@bar.de"); assertUrl(rootNode, "Amazon", "http://www.amazon.de"); assertCreatedOn(rootNode, "Enterprise Password", "2009-12-24"); assertCreatedOn(rootNode, "Amazon", ModelConstants.SHORT.format(new Date())); assertCreatedOn(rootNode, "Wrong creation date", ModelConstants.SHORT.format(new Date())); assertExpiresOn(rootNode, "Enterprise Password", "2010-11-23"); final Calendar expiresOn = DateUtils.getCurrentDate(); expiresOn.add(Calendar.DAY_OF_YEAR, Settings.getDefaultPwdExpiryDays()); assertExpiresOn(rootNode, "Wrong Expiration date", ModelConstants.SHORT.format(expiresOn.getTime())); assertPassword(rootNode, "Account placed to the root", "hhsgww2l"); assertComment(rootNode, "Enterprise Password", "That is just a comment.\nWith\nMultiple lines\nImported"); }
From source file:org.webcat.grader.graphs.StackedAreaChart.java
@Override protected JFreeChart generateChart(WCChartTheme chartTheme) { JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, xAxisLabel(), yAxisLabel(), tableXYDataset(), orientation(), true, false, false); XYPlot plot = chart.getXYPlot();/*from www. ja va 2s .c o m*/ long diff = (long) tableXYDataset().getXValue(0, tableXYDataset().getItemCount() - 1) - (long) tableXYDataset().getXValue(0, 0); GregorianCalendar calDiff = new GregorianCalendar(); calDiff.setTime(new NSTimestamp(diff)); // Set the time axis PeriodAxis axis = new PeriodAxis(null); // ( "Date" ); PeriodAxisLabelInfo labelinfo[] = new PeriodAxisLabelInfo[2]; if (calDiff.get(Calendar.DAY_OF_YEAR) > 1) { axis.setTimeZone(TimeZone.getTimeZone(user().timeZoneName())); axis.setAutoRangeTimePeriodClass(org.jfree.data.time.Day.class); axis.setMajorTickTimePeriodClass(org.jfree.data.time.Week.class); labelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("d"), PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true, PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT); labelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class, new SimpleDateFormat("MMM"), PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true, PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT); } else { axis.setAutoRangeTimePeriodClass(org.jfree.data.time.Hour.class); labelinfo[0] = new PeriodAxisLabelInfo(org.jfree.data.time.Day.class, new SimpleDateFormat("ha"), PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true, PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT); labelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Month.class, new SimpleDateFormat("MMM-d"), PeriodAxisLabelInfo.DEFAULT_INSETS, chartTheme.smallFont(), chartTheme.textColor(), true, PeriodAxisLabelInfo.DEFAULT_DIVIDER_STROKE, PeriodAxisLabelInfo.DEFAULT_DIVIDER_PAINT); } axis.setLabelInfo(labelinfo); plot.setDomainAxis(axis); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); NumberTickUnit tickUnit = new NumberTickUnit(5); rangeAxis.setTickUnit(tickUnit); XYAreaRenderer2 renderer = (XYAreaRenderer2) plot.getRenderer(); renderer.setOutline(true); renderer.setAutoPopulateSeriesOutlinePaint(true); plot.setDomainMinorGridlinesVisible(false); plot.setRangeMinorGridlinesVisible(false); if (markValue != null) { plot.setDomainCrosshairVisible(true); plot.setDomainCrosshairValue(markValue.doubleValue()); plot.setDomainCrosshairPaint(Color.red); plot.setDomainCrosshairStroke(MARKER_STROKE); } chart.getLegend().setBorder(0, 0, 0, 0); return chart; }
From source file:com.antsdb.saltedfish.sql.vdm.FuncDateFormat.java
private String format(String format, Timestamp time) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < format.length(); i++) { char ch = format.charAt(i); if (ch != '%') { buf.append(ch);//from ww w . j ava2 s .c om continue; } if (i >= (format.length() - 1)) { buf.append(ch); continue; } char specifier = format.charAt(++i); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time.getTime()); if (specifier == 'a') { throw new NotImplementedException(); } else if (specifier == 'b') { throw new NotImplementedException(); } else if (specifier == 'c') { buf.append(calendar.get(Calendar.MONTH + 1)); } else if (specifier == 'd') { int day = calendar.get(Calendar.DAY_OF_MONTH); if (day < 10) { buf.append('0'); } buf.append(day); } else if (specifier == 'D') { throw new NotImplementedException(); } else if (specifier == 'e') { buf.append(calendar.get(Calendar.DAY_OF_MONTH)); } else if (specifier == 'f') { buf.append(calendar.get(Calendar.MILLISECOND * 1000)); } else if (specifier == 'H') { buf.append(calendar.get(Calendar.HOUR)); } else if (specifier == 'h') { buf.append(calendar.get(Calendar.HOUR) % 13); } else if (specifier == 'i') { buf.append(calendar.get(Calendar.MINUTE)); } else if (specifier == 'I') { buf.append(calendar.get(Calendar.HOUR) % 13); } else if (specifier == 'j') { buf.append(calendar.get(Calendar.DAY_OF_YEAR)); } else if (specifier == 'k') { buf.append(calendar.get(Calendar.HOUR)); } else if (specifier == 'l') { buf.append(calendar.get(Calendar.HOUR) % 13); } else if (specifier == 'm') { int month = calendar.get(Calendar.MONTH) + 1; if (month < 10) { buf.append('0'); } buf.append(calendar.get(Calendar.MONTH) + 1); } else if (specifier == 'M') { buf.append(calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault())); } else if (specifier == 'p') { int hour = calendar.get(Calendar.HOUR); buf.append(hour < 12 ? "AM" : "PM"); } else if (specifier == 'r') { int hour = calendar.get(Calendar.HOUR); hour = hour % 13; if (hour < 10) { buf.append('0'); } buf.append(hour); buf.append(':'); int minute = calendar.get(Calendar.MINUTE); if (minute < 10) { buf.append('0'); } buf.append(minute); buf.append(':'); int second = calendar.get(Calendar.SECOND); if (second < 10) { buf.append('0'); } buf.append(second); buf.append(hour < 12 ? " AM" : " PM"); } else if (specifier == 's') { buf.append(calendar.get(Calendar.SECOND)); } else if (specifier == 'S') { buf.append(calendar.get(Calendar.SECOND)); } else if (specifier == 'T') { throw new NotImplementedException(); } else if (specifier == 'u') { buf.append(calendar.get(Calendar.WEEK_OF_YEAR)); } else if (specifier == 'U') { throw new NotImplementedException(); } else if (specifier == 'v') { throw new NotImplementedException(); } else if (specifier == 'V') { throw new NotImplementedException(); } else if (specifier == 'w') { throw new NotImplementedException(); } else if (specifier == 'W') { throw new NotImplementedException(); } else if (specifier == 'x') { throw new NotImplementedException(); } else if (specifier == 'X') { throw new NotImplementedException(); } else if (specifier == 'y') { buf.append(calendar.get(Calendar.YEAR) % 100); } else if (specifier == 'Y') { buf.append(calendar.get(Calendar.YEAR)); } else if (specifier == '%') { buf.append('%'); } else { buf.append(specifier); } } return buf.toString(); }