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:com.wildplot.android.ankistats.CollectionData.java
private void _updateCutoff() { // calculate days since col created and store in mToday mToday = 0;//from w w w.j a v a 2 s. c o m Calendar crt = GregorianCalendar.getInstance(); crt.setTimeInMillis(mCrt * 1000); // creation time (from crt as stored in database) Calendar fromNow = GregorianCalendar.getInstance(); // decremented towards crt // code to avoid counting years worth of days int yearSpan = fromNow.get(Calendar.YEAR) - crt.get(Calendar.YEAR); if (yearSpan > 1) { // at least one full year has definitely lapsed since creation int toJump = 365 * (yearSpan - 1); fromNow.add(Calendar.YEAR, -toJump); if (fromNow.compareTo(crt) < 0) { // went too far, reset and do full count fromNow = GregorianCalendar.getInstance(); } else { mToday += toJump; } } // count days backwards while (fromNow.compareTo(crt) > 0) { fromNow.add(Calendar.DAY_OF_MONTH, -1); if (fromNow.compareTo(crt) >= 0) { mToday++; } } crt.add(Calendar.DAY_OF_YEAR, mToday + 1); mDayCutoff = crt.getTimeInMillis() / 1000; }
From source file:com.autodomum.daylight.algorithm.DaylightAlgorithm.java
@Override public Date sunset(final Coordinate coordinate, final Date date) { final Calendar calendar = GregorianCalendar.getInstance(); calendar.setTime(date);//from w w w . j av a 2 s .c o m final int day = calendar.get(Calendar.DAY_OF_YEAR); final double total = length(coordinate.getLatitude(), day); final int hours = (int) total; final int minutes = (int) ((((double) total) - ((double) hours)) * 60d); calendar.set(Calendar.HOUR_OF_DAY, 12); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.add(Calendar.HOUR_OF_DAY, hours / 2); calendar.add(Calendar.MINUTE, minutes / 2); calendar.add(Calendar.MINUTE, (int) localSolarTime(day)); final TimeZone timeZone = TimeZone.getDefault(); if (timeZone.inDaylightTime(date)) { calendar.add(Calendar.MILLISECOND, timeZone.getDSTSavings()); } return calendar.getTime(); }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java
/** * Increase the actual chosen view. (DAY / MONTH / WEEK/ YEAR) *///from w w w . j av a 2 s .c o m protected final void increment() { 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:jp.co.opentone.bsol.linkbinder.view.servlet.WebResourceServlet.java
protected void setHeader(HttpServletResponse response, String path) { response.setDateHeader("Last-Modified", System.currentTimeMillis()); Calendar expires = Calendar.getInstance(); expires.add(Calendar.DAY_OF_YEAR, 7); response.setDateHeader("Expires", expires.getTimeInMillis()); //12 hours: 43200 = 60s * 60 * 12 response.setHeader("Cache-Control", "max-age=43200"); response.setHeader("Pragma", ""); String contentType = getContentType(path); if (StringUtils.isNotEmpty(contentType)) { response.setContentType(contentType); }/* www . j ava 2 s. c om*/ }
From source file:net.chrisrichardson.foodToGo.domain.hibernate.HibernateOrderRepositoryImplTests.java
public void testFindOrders_since() throws Exception { Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_YEAR, -20); criteria.setDeliveryTime(c.getTime()); PagedQueryResult results = repository.findOrdersInline(0, 10, criteria); assertFalse(results.getResults().isEmpty()); }
From source file:asl.util.PlotMaker.java
public void plotZNE_3x3(ArrayList<double[]> channelData, double[] xsecs, int nstart, int nend, String eventString, String plotString) { // Expecting 9 channels packed like: Panel Trace1 Trace2 Trace3 // channels[0] = 00-LHZ 1 00-LHZ 10-LHZ 20-LHZ // channels[1] = 00-LHND 2 00-LHND 10-LHND 20-LHND // channels[2] = 00-LHED 3 00-LHED 10-LHED 20-LHED // channels[3] = 10-LHZ // channels[4] = 10-LHND // channels[5] = 10-LHED // channels[6] = 20-LHZ // channels[7] = 20-LHND // channels[8] = 20-LHED final String plotTitle = String.format("%04d%03d [Stn:%s] [Event:%s] %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, eventString, plotString); final String pngName = String.format("%s/%s.%s.%s.png", outputDir, eventString, station, plotString); File outputFile = new File(pngName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format("== plotZNE_3x3: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return;//from w w w. j av a 2 s .co m } if (channelData.size() != channels.length) { System.out.format("== plotZNE_3x3: Error: We have [%d channels] but [%d channelData]\n", channels.length, channelData.size()); return; } XYSeries[] series = new XYSeries[channels.length]; for (int i = 0; i < channels.length; i++) { series[i] = new XYSeries(channels[i].toString()); double[] data = channelData.get(i); //for (int k = 0; k < xsecs.length; k++){ for (int k = 0; k < data.length; k++) { series[i].add(xsecs[k], data[k]); } } // I. Panel I = Verticals // Use the first data array, within the plotted range (nstart - nend) to scale the plots: double[] data = channelData.get(0); double ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Paint[] paints = new Paint[] { Color.red, Color.blue, Color.green }; for (int i = 0; i < paints.length; i++) { renderer.setSeriesPaint(i, paints[i]); renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, false); } final NumberAxis verticalAxis = new NumberAxis("Displacement (m)"); verticalAxis.setRange(new Range(-ymax, ymax)); //verticalAxis.setTickUnit( new NumberTickUnit(5) ); final NumberAxis horizontalAxis = new NumberAxis("Time (s)"); horizontalAxis.setRange(new Range(nstart, nend)); //horizontalAxis.setRange( new Range(0.00009 , 110) ); final NumberAxis hAxis = new NumberAxis("Time (s)"); hAxis.setRange(new Range(nstart, nend)); final XYSeriesCollection seriesCollection1 = new XYSeriesCollection(); seriesCollection1.addSeries(series[0]); seriesCollection1.addSeries(series[3]); seriesCollection1.addSeries(series[6]); //final XYPlot xyplot1 = new XYPlot((XYDataset)seriesCollection1, null, verticalAxis, renderer); //final XYPlot xyplot1 = new XYPlot((XYDataset)seriesCollection1, horizontalAxis, verticalAxis, renderer); final XYPlot xyplot1 = new XYPlot((XYDataset) seriesCollection1, hAxis, verticalAxis, renderer); double x = .95 * xsecs[nend]; double y = .90 * ymax; XYTextAnnotation annotation1 = new XYTextAnnotation("Vertical", x, y); annotation1.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot1.addAnnotation(annotation1); // II. Panel II = North // Use the first data array, within the plotted range (nstart - nend) to scale the plots: data = channelData.get(1); ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final NumberAxis verticalAxisN = new NumberAxis("Displacement (m)"); verticalAxisN.setRange(new Range(-ymax, ymax)); final XYSeriesCollection seriesCollection2 = new XYSeriesCollection(); seriesCollection2.addSeries(series[1]); seriesCollection2.addSeries(series[4]); seriesCollection2.addSeries(series[7]); final XYPlot xyplot2 = new XYPlot((XYDataset) seriesCollection2, null, verticalAxisN, renderer); XYTextAnnotation annotation2 = new XYTextAnnotation("North-South", x, y); annotation2.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot2.addAnnotation(annotation2); // III. Panel III = East // Use the first data array, within the plotted range (nstart - nend) to scale the plots: data = channelData.get(2); ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final NumberAxis verticalAxisE = new NumberAxis("Displacement (m)"); verticalAxisE.setRange(new Range(-ymax, ymax)); final XYSeriesCollection seriesCollection3 = new XYSeriesCollection(); seriesCollection3.addSeries(series[2]); seriesCollection3.addSeries(series[5]); seriesCollection3.addSeries(series[8]); final XYPlot xyplot3 = new XYPlot((XYDataset) seriesCollection3, null, verticalAxisE, renderer); XYTextAnnotation annotation3 = new XYTextAnnotation("East-West", x, y); annotation3.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot3.addAnnotation(annotation3); //CombinedXYPlot combinedPlot = new CombinedXYPlot( horizontalAxis, CombinedXYPlot.VERTICAL ); CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis); combinedPlot.add(xyplot1, 1); combinedPlot.add(xyplot2, 1); combinedPlot.add(xyplot3, 1); combinedPlot.setGap(15.); final JFreeChart chart = new JFreeChart(combinedPlot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 800); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:com.redhat.rhn.frontend.action.systems.monitoring.ProbeDetailsAction.java
/** {@inheritDoc} */ public ActionForward execute(ActionMapping mapping, ActionForm formIn, HttpServletRequest req, HttpServletResponse resp) {// ww w. ja va2 s . c o m RequestContext rctx = new RequestContext(req); ServerProbe probe = (ServerProbe) rctx.lookupProbe(); if (probe.getTemplateProbe() != null) { req.setAttribute(IS_SUITE_PROBE, Boolean.TRUE); } else { req.setAttribute(IS_SUITE_PROBE, Boolean.FALSE); } Server server = rctx.lookupAndBindServer(); DynaActionForm form = (DynaActionForm) formIn; boolean showGraph = BooleanUtils.toBoolean((Boolean) form.get(SHOW_GRAPH)); boolean showLog = BooleanUtils.toBoolean((Boolean) form.get(SHOW_LOG)); // 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, req, yesterday.getTime(), today.getTime(), DatePicker.YEAR_RANGE_NEGATIVE, "probedetails.jsp.start_date", "probedetails.jsp.end_date"); DatePickerResults dates = picker.processDatePickers(isSubmitted(form), false); ActionMessages errors = dates.getErrors(); // Setup the Metrics array Map l10nmetrics = new HashMap(); Metric[] marray = (Metric[]) probe.getCommand().getMetrics().toArray(new Metric[0]); LabelValueBean[] metrics = new LabelValueBean[marray.length]; for (int i = 0; i < marray.length; i++) { String label = LocalizationService.getInstance().getMessage("metrics." + marray[i].getLabel()); metrics[i] = new LabelValueBean(label, marray[i].getMetricId()); l10nmetrics.put(marray[i].getMetricId(), label); } form.set(METRICS, metrics); req.setAttribute(METRICS, metrics); // Setup and deal with selected metrics. // Always have the 1st one selected String[] selectedMetrics = new String[0]; if (marray.length > 0) { if (form.get(SELECTED_METRICS) == null || ((String[]) form.get(SELECTED_METRICS)).length <= 0) { selectedMetrics = new String[1]; selectedMetrics[0] = marray[0].getMetricId(); form.set(SELECTED_METRICS, selectedMetrics); } else { selectedMetrics = (String[]) form.get(SELECTED_METRICS); } } req.setAttribute(SELECTED_METRICS, selectedMetrics); if (showLog || showGraph) { boolean valid = errors.isEmpty(); if (valid && showGraph) { // Setup the graphing specific parameters so we can // fill out the URL on details.jsp to the ProbeGraphAction StringBuilder ssString = new StringBuilder(); // We also need to localize the labels so we can // pass them into ProbeGraphAction so it can localize // the metric lables within the graph itself. StringBuilder l10nString = new StringBuilder(); // Here we concat together the selected metrics // so we don't have to do this in the JSP. The graphing // Action can take multiple metrics so we just concat them together for (int i = 0; i < selectedMetrics.length; i++) { ssString.append("metrics="); ssString.append(selectedMetrics[i]); ssString.append("&"); l10nString.append(L10NKEY + selectedMetrics[i]); l10nString.append("="); l10nString.append(StringUtil.urlEncode((String) l10nmetrics.get(selectedMetrics[i]))); l10nString.append("&"); } req.setAttribute(SELECTED_METRICS_STRING, ssString.toString()); req.setAttribute(L10NED_SELECTED_METRICS_STRING, l10nString.toString()); req.setAttribute(STARTTS, new Long(dates.getStart().getCalendar().getTimeInMillis())); req.setAttribute(ENDTS, new Long(dates.getEnd().getCalendar().getTimeInMillis())); } if (valid && showLog) { DataResult dr = MonitoringManager.getInstance().getProbeStateChangeData(probe, new Timestamp(dates.getStart().getCalendar().getTimeInMillis()), new Timestamp(dates.getEnd().getCalendar().getTimeInMillis())); req.setAttribute(ListHelper.LIST, dr); ListHelper helper = new ListHelper(this, req); helper.execute(); } } if (!errors.isEmpty()) { addErrors(req, errors); } req.setAttribute("probe", probe); req.setAttribute("system", server); if (probe.getState() == null || probe.getState().getOutput() == null) { req.setAttribute("status", LocalizationService.getInstance().getMessage("probe.empty.status")); } else { ProbeState state = probe.getState(); String statusString = LocalizationService.getInstance().getMessage(state.getState()); if (!StringUtils.isBlank(state.getOutput())) { statusString = statusString + ", " + state.getOutput(); } statusString = StringUtil.htmlifyText(statusString); req.setAttribute("status", statusString); if (probe.getState().getState().equals(MonitoringConstants.PROBE_STATE_UNKNOWN)) { req.setAttribute("status_class", "probe-status-unknown"); } else if (probe.getState().getState().equals(MonitoringConstants.PROBE_STATE_CRITICAL)) { req.setAttribute("status_class", "probe-status-critical"); } } req.setAttribute(SHOW_GRAPH, Boolean.valueOf(showGraph)); req.setAttribute(SHOW_LOG, Boolean.valueOf(showLog)); return mapping.findForward(RhnHelper.DEFAULT_FORWARD); }
From source file:de.csdev.ebus.command.datatypes.ext.EBusTypeDate.java
@Override public EBusDateTime decodeInt(byte[] data) throws EBusTypeException { if (data == null) { // TODO replace value return null; }//from ww w .j ava 2s . co m IEBusType<BigDecimal> bcdType = types.getType(EBusTypeBCD.TYPE_BCD); IEBusType<BigDecimal> wordType = types.getType(EBusTypeWord.TYPE_WORD); IEBusType<BigDecimal> charType = types.getType(EBusTypeChar.TYPE_CHAR); Calendar calendar = new GregorianCalendar(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); BigDecimal day = null; BigDecimal month = null; BigDecimal year = null; if (data.length != getTypeLength()) { throw new EBusTypeException( String.format("Input byte array must have a length of %d bytes!", getTypeLength())); } if (StringUtils.equals(variant, SHORT)) { day = bcdType.decode(new byte[] { data[0] }); month = bcdType.decode(new byte[] { data[1] }); year = bcdType.decode(new byte[] { data[2] }); } else if (StringUtils.equals(variant, DEFAULT)) { day = bcdType.decode(new byte[] { data[0] }); month = bcdType.decode(new byte[] { data[1] }); year = bcdType.decode(new byte[] { data[3] }); } else if (StringUtils.equals(variant, HEX_SHORT)) { day = charType.decode(new byte[] { data[0] }); month = charType.decode(new byte[] { data[1] }); year = charType.decode(new byte[] { data[2] }); } else if (StringUtils.equals(variant, HEX)) { day = charType.decode(new byte[] { data[0] }); month = charType.decode(new byte[] { data[1] }); year = charType.decode(new byte[] { data[3] }); } else if (StringUtils.equals(variant, DAYS)) { BigDecimal daysSince1900 = wordType.decode(data); calendar.set(1900, 0, 1, 0, 0); calendar.add(Calendar.DAY_OF_YEAR, daysSince1900.intValue()); } if (day != null && month != null && year != null) { if (day.intValue() < 1 || day.intValue() > 31) { throw new EBusTypeException("A valid day must be in a range between 1-31 !"); } if (month.intValue() < 1 || month.intValue() > 12) { throw new EBusTypeException("A valid day must be in a range between 1-12 !"); } } if (year != null) { if (year.intValue() < 70) { year = year.add(new BigDecimal(2000)); } else { year = year.add(new BigDecimal(1900)); } calendar.set(Calendar.YEAR, year.intValue()); } if (month != null) { calendar.set(Calendar.MONTH, month.intValue() - 1); } if (day != null && day.intValue() > 0 && day.intValue() < 32) { calendar.set(Calendar.DAY_OF_MONTH, day.intValue()); } return new EBusDateTime(calendar, false, true); }
From source file:com.redhat.rhn.frontend.action.audit.scap.XccdfSearchAction.java
private DateRangePicker setupDatePicker(DynaActionForm form, HttpServletRequest request) { Calendar today = Calendar.getInstance(); today.setTime(new Date()); Calendar yesterday = (Calendar) today.clone(); yesterday.add(Calendar.DAY_OF_YEAR, -1); return new DateRangePicker(form, request, yesterday.getTime(), today.getTime(), DatePicker.YEAR_RANGE_NEGATIVE, "scapsearch.jsp.start_date", "scapsearch.jsp.end_date"); }