List of usage examples for java.util GregorianCalendar getTime
public final Date getTime()
Date
object representing this Calendar
's time value (millisecond offset from the Epoch"). From source file:iSoron.HistoryChart.java
private void drawColumnHeader(Canvas canvas, RectF location, GregorianCalendar date) { String month = dfMonth.format(date.getTime()); String year = dfYear.format(date.getTime()); String text = null;//from www .j a va2 s. com if (!month.equals(previousMonth)) text = previousMonth = month; else if (!year.equals(previousYear)) text = previousYear = year; if (text != null) { canvas.drawText(text, location.left + headerOverflow, location.bottom - headerTextOffset, pTextHeader); headerOverflow += pTextHeader.measureText(text) + columnWidth * 0.2f; } headerOverflow = Math.max(0, headerOverflow - columnWidth); }
From source file:org.nuclos.common2.SeriesUtils.java
/** * /*w ww .j a va 2s.c om*/ * @param series * @param dateOrigin * @return the next date calculated by series from origin. * origin could be a calculated date (result >= origin) */ public static DateTime getSeriesNext(String series, DateTime dateOrigin) { if (series == null) return dateOrigin; GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(dateOrigin.getDate()); String[] split = org.apache.commons.lang.StringUtils.split(series, '|'); if (split.length > 0) { String modus = split[0]; if ("d".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); int days = Integer.parseInt(split[3]); if (days == 0) { // add one day if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } while (!isWorkingDay(calendar.get(GregorianCalendar.DAY_OF_WEEK))) { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } } else { // add one day if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } if (days > 1) { calendar.add(GregorianCalendar.DAY_OF_MONTH, days - 1); } } } else if ("w".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); int weeks = Integer.parseInt(split[3]); List<Integer> possibleWeekdays = new ArrayList<Integer>(); int firstSelectedWeekday = -1000; int lastWeekday = -1000; // use getWeekdayItems() in order to get the right start (end) of the week for (SeriesListItem sli : getWeekdayItems()) { boolean addWeekday = false; switch (sli.getId()) { case GregorianCalendar.MONDAY: if (split[4].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.TUESDAY: if (split[5].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.WEDNESDAY: if (split[6].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.THURSDAY: if (split[7].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.FRIDAY: if (split[8].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.SATURDAY: if (split[9].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.SUNDAY: if (split[10].equals("0") ? false : true) addWeekday = true; break; } if (addWeekday) { possibleWeekdays.add(sli.getId()); if (firstSelectedWeekday == -1000) firstSelectedWeekday = sli.getId(); } lastWeekday = sli.getId(); } // add one day if calculated date is before origin boolean weeksAdded = false; if (calendar.getTime().before(dateOrigin.getDate())) { if (lastWeekday == calendar.get(GregorianCalendar.DAY_OF_WEEK)) { calendar.add(GregorianCalendar.WEEK_OF_YEAR, weeks - 1); weeksAdded = true; } else { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } } while (!possibleWeekdays.contains(new Integer(calendar.get(GregorianCalendar.DAY_OF_WEEK)))) { if (!weeksAdded && lastWeekday == calendar.get(GregorianCalendar.DAY_OF_WEEK)) { calendar.add(GregorianCalendar.WEEK_OF_YEAR, weeks - 1); } calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } } else if ("m".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); if ("m1".equals(split[3])) { int day = Integer.parseInt(split[4]); int months = Integer.parseInt(split[5]); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); // add one month if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.MONTH, 1); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); } if (months > 1) { calendar.add(GregorianCalendar.MONTH, months - 1); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); } } else { int number = Integer.parseInt(split[4]); int weekday = Integer.parseInt(split[5]); int months = Integer.parseInt(split[6]); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); // add one month if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.MONTH, 1); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); } if (months > 1) { calendar.add(GregorianCalendar.MONTH, months - 1); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); } } } else if ("y".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); if ("y1".equals(split[3])) { int day = Integer.parseInt(split[4]); int month = Integer.parseInt(split[5]); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); // add one year if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.YEAR, 1); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); } } else { int number = Integer.parseInt(split[4]); int weekday = Integer.parseInt(split[5]); int month = Integer.parseInt(split[6]); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); // add one year if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.YEAR, 1); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); } } } } return new DateTime(calendar.getTimeInMillis()); }
From source file:org.apache.juddi.api.impl.UDDICustodyTransferImpl.java
public void getTransferToken(String authInfo, KeyBag keyBag, Holder<String> nodeID, Holder<XMLGregorianCalendar> expirationTime, Holder<byte[]> opaqueToken) throws DispositionReportFaultMessage { long startTime = System.currentTimeMillis(); EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try {/* w w w . jav a 2 s . co m*/ tx.begin(); UddiEntityPublisher publisher = this.getEntityPublisher(em, authInfo); new ValidateCustodyTransfer(publisher).validateGetTransferToken(em, keyBag); int transferExpirationDays = DEFAULT_TRANSFEREXPIRATION_DAYS; try { transferExpirationDays = AppConfig.getConfiguration() .getInt(Property.JUDDI_TRANSFER_EXPIRATION_DAYS); // For output nodeID.value = AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID); } catch (ConfigurationException ce) { throw new FatalErrorException(new ErrorMessage("errors.configuration.Retrieval")); } String transferKey = TRANSFER_TOKEN_PREFIX + UUID.randomUUID(); org.apache.juddi.model.TransferToken transferToken = new org.apache.juddi.model.TransferToken(); transferToken.setTransferToken(transferKey); // For output opaqueToken.value = transferKey.getBytes(); GregorianCalendar gc = new GregorianCalendar(); gc.add(GregorianCalendar.DAY_OF_MONTH, transferExpirationDays); transferToken.setExpirationDate(gc.getTime()); try { DatatypeFactory df = DatatypeFactory.newInstance(); // For output expirationTime.value = df.newXMLGregorianCalendar(gc); } catch (DatatypeConfigurationException ce) { throw new FatalErrorException(new ErrorMessage("errors.Unspecified")); } List<String> keyList = keyBag.getKey(); for (String key : keyList) { TransferTokenKey tokenKey = new TransferTokenKey(transferToken, key); transferToken.getTransferKeys().add(tokenKey); } em.persist(transferToken); tx.commit(); long procTime = System.currentTimeMillis() - startTime; serviceCounter.update(CustodyTransferQuery.GET_TRANSFERTOKEN, QueryStatus.SUCCESS, procTime); } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:com.betel.flowers.web.bean.CredencialBean.java
private String codigoFoto() { GregorianCalendar calendario = new GregorianCalendar(); SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyy"); return "BETEL-U" + RandomStringUtils.randomNumeric(4) + "-IMG-" + format.format(calendario.getTime()); }
From source file:com.datamountaineer.streamreactor.connect.json.SimpleJsonConverterTest.java
@Test public void dateToJson() throws IOException { GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.add(Calendar.DATE, 10000); java.util.Date date = calendar.getTime(); JsonNode converted = converter.fromConnectData(Date.SCHEMA, date); assertTrue(converted.isTextual());/*w w w . java2 s . c o m*/ assertEquals(SimpleJsonConverter.ISO_DATE_FORMAT.format(date), converted.textValue()); }
From source file:org.nuxeo.webengine.sites.fragments.SearchResultsFragment.java
/** * Searches a certain webPage between all the pages under a <b>WebSite</b> * that contains in title, description , main content or attached files the * given searchParam./* w w w. j a va 2 s . c o m*/ */ @Override public Model getModel() throws ModelException { SearchListModel model = new SearchListModel(); try { if (WebEngine.getActiveContext() != null) { WebContext ctx = WebEngine.getActiveContext(); CoreSession session = ctx.getCoreSession(); DocumentModel documentModel = ctx.getTargetObject().getAdapter(DocumentModel.class); String searchParam = (String) ctx.getProperty(SEARCH_PARAM); String tagDocumentId = (String) ctx.getProperty(TAG_DOCUMENT); String documentType = (String) ctx.getProperty(SEARCH_PARAM_DOC_TYPE); String dateAfter = (String) ctx.getProperty(DATE_AFTER); String dateBefore = (String) ctx.getProperty(DATE_BEFORE); TagService tagService = Framework.getService(TagService.class); // get first workspace parent DocumentModel ws = SiteUtils.getFirstWebSiteParent(session, documentModel); DocumentModelList results = new DocumentModelListImpl(new ArrayList<DocumentModel>()); if ((!StringUtils.isEmpty(searchParam) || (dateAfter != null && dateBefore != null)) && ws != null && StringUtils.isEmpty(tagDocumentId)) { results = SiteQueriesCollection.querySearchPages(session, searchParam, ws.getPathAsString(), documentType, dateAfter, dateBefore); } if (StringUtils.isEmpty(searchParam) && StringUtils.isNotEmpty(tagDocumentId)) { // TODO only search under website ws List<String> docIds = tagService.getTagDocumentIds(session, tagDocumentId, null); for (String docId : docIds) { DocumentModel doc = session.getDocument(new IdRef(docId)); DocumentModel webSite = SiteUtils.getFirstWebSiteParent(session, doc); if (ws.equals(webSite)) { results.add(session.getDocument(new IdRef(docId))); } } } for (DocumentModel document : results) { GregorianCalendar date = SiteUtils.getGregorianCalendar(document, "dc:created"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMM yyyy", WebEngine.getActiveContext().getLocale()); String created = simpleDateFormat.format(date.getTime()); date = SiteUtils.getGregorianCalendar(document, "dc:modified"); String modified = simpleDateFormat.format(date.getTime()); String author = SiteUtils.getUserDetails(SiteUtils.getString(document, "dc:creator")); String path = SiteUtils.getPagePath(ws, document); String name = SiteUtils.getString(document, "dc:title"); String description = SiteUtils.getFistNWordsFromString( SiteUtils.getString(document, "dc:description"), nrWordsFromDescription); SearchModel searchModel = new SearchModel(name, description, path, author, created, modified); model.addItem(searchModel); } } } catch (Exception e) { throw new ModelException(e); } return model; }
From source file:org.miloss.fgsms.services.rs.impl.reports.os.FreeDiskSpace.java
@Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { Connection con = Utility.getPerformanceDBConnection(); try {/*www. j a v a 2s.c om*/ PreparedStatement cmd = null; ResultSet rs = null; JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append(GetHtmlFormattedHelp() + "<br />"); data.append( "<table class=\"table table-hover\"><tr><th>URI</th><th>Average Send Rate</th><th>Average Free Disk Space (all paritions)</th><th>Average Write KB/s</th><th>Average Read KB/s</th></tr>"); TimeSeriesCollection col = new TimeSeriesCollection(); for (int i = 0; i < urls.size(); i++) { if (!isPolicyTypeOf(urls.get(i), PolicyType.MACHINE)) { continue; } //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) { continue; } String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i))); double average = 0; data.append("<tr><td>").append(url).append("</td>"); try { cmd = con.prepareStatement( "select avg(freespace) from rawdatadrives where uri=? and utcdatetime > ? and utcdatetime < ?;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); if (rs.next()) { average = rs.getDouble(1); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(average + "").append("</td>"); try { cmd = con.prepareStatement( "select avg(writekbs) from rawdatadrives where uri=? and utcdatetime > ? and utcdatetime < ?;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); average = 0; if (rs.next()) { average = rs.getDouble(1); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(average + "").append("</td>"); try { cmd = con.prepareStatement( "select avg(readkbs) from rawdatadrives where uri=? and utcdatetime > ? and utcdatetime < ?;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); average = 0; if (rs.next()) { average = rs.getDouble(1); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(average + "").append("</td></tr>"); //ok now get the raw data.... TimeSeriesContainer tsc = new TimeSeriesContainer(); try { cmd = con.prepareStatement( "select readkbs, writekbs,freespace, utcdatetime, driveidentifier from rawdatadrives where uri=? and utcdatetime > ? and utcdatetime < ?;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); while (rs.next()) { TimeSeries ts2 = tsc.Get(url + " " + rs.getString("driveidentifier"), Millisecond.class); GregorianCalendar gcal = new GregorianCalendar(); gcal.setTimeInMillis(rs.getLong(4)); Millisecond m = new Millisecond(gcal.getTime()); ts2.addOrUpdate(m, rs.getLong("freespace")); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } for (int ik = 0; ik < tsc.data.size(); ik++) { col.addSeries(tsc.data.get(ik)); } } data.append("</table>"); chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "MBytes", col, true, false, false); try { // if (set.getRowCount() != 0) { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, 400); data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); // } } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:com.datamountaineer.streamreactor.connect.json.SimpleJsonConverterTest.java
@Test public void timeToJson() throws IOException { GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.add(Calendar.MILLISECOND, 14400000); java.util.Date date = calendar.getTime(); JsonNode converted = converter.fromConnectData(Time.SCHEMA, date); assertTrue(converted.isTextual());//from w w w. j a v a 2 s . co m assertEquals(SimpleJsonConverter.TIME_FORMAT.format(date), converted.textValue()); }
From source file:edu.lternet.pasta.portal.statistics.GrowthStats.java
private String getLabel(int scale, GregorianCalendar date) { String label = null;/*w w w. j a v a2 s.c o m*/ SimpleDateFormat formatter; switch (scale) { case Calendar.HOUR: formatter = new SimpleDateFormat("kk00 yyyy-MMM-d"); label = formatter.format(date.getTime()); break; case Calendar.DAY_OF_MONTH: formatter = new SimpleDateFormat("yyyy-MMM-d"); label = formatter.format(date.getTime()); break; case Calendar.WEEK_OF_YEAR: formatter = new SimpleDateFormat("w yyyy"); label = formatter.format(date.getTime()); break; case Calendar.MONTH: formatter = new SimpleDateFormat("MMM yyyy"); label = formatter.format(date.getTime()); break; case Calendar.YEAR: formatter = new SimpleDateFormat("yyyy"); label = formatter.format(date.getTime()); break; default: label = date.getTime().toString(); } return label; }
From source file:org.squale.squaleweb.applicationlayer.action.results.ReviewAction.java
/** * //from ww w . ja v a 2 s.c o m * @param pForm le formulaire * @param pRequest la requte * @return les paramtres */ private Object[] getParams(ActionForm pForm, HttpServletRequest pRequest) { ActionErrors errors = new ActionErrors(); Object[] paramIn = null; ParamReviewForm currentForm = (ParamReviewForm) pForm; int index = 0; int nbDays = currentForm.getNbDays(); String tre = currentForm.getTre(); String ruleId = currentForm.getRuleId(); String componentId = currentForm.getComponentId(); ComponentDTO comp = new ComponentDTO(); comp.setID(Long.decode(componentId).longValue()); Date date = null; // Conversion en une date if (nbDays > 0) { GregorianCalendar gc = new GregorianCalendar(); gc.add(Calendar.DATE, -nbDays); date = gc.getTime(); } String treLabel = WebMessages.getString(pRequest, tre); if (ruleId.length() > 0) { paramIn = new Object[] { comp, tre, treLabel, date, Long.decode(ruleId) }; } else { paramIn = new Object[] { comp, tre, treLabel, date, null }; } return paramIn; }