List of usage examples for java.util GregorianCalendar get
public int get(int field)
From source file:org.matsim.counts.algorithms.graphs.helper.OutputDelegate.java
private void writeHtml(final CountsGraph cg, final String iter_path, boolean indexFile) { /* we want landscape, thus exchange width / height */ int width = 800; int height = 600; JFreeChart chart = null;//from w ww . j av a2 s .c o m String fileName = ""; File file2; if (!indexFile) { chart = cg.getChart(); fileName = cg.getFilename(); file2 = new File(iter_path + "/" + fileName + ".html"); } else { file2 = new File(iter_path + "/start.html"); } PrintWriter writer = null; try { ChartRenderingInfo info = null; File file1; if (!indexFile) { info = new ChartRenderingInfo(new StandardEntityCollection()); file1 = new File(iter_path + "/png/" + fileName + ".png"); ChartUtilities.saveChartAsPNG(file1, chart, width, height, info); } writer = new PrintWriter(new BufferedOutputStream(new FileOutputStream(file2))); writer.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); //writer.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">"); writer.println( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); writer.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">"); writer.println("<head>"); //writer.println("<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=UTF-8\" />"); writer.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"); writer.println("<meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\"/>"); writer.println("<meta http-equiv=\"Content-Style-Type\" content=\"text/css\"/>"); writer.println("<title> MATSim validation </title>"); writer.println("<script type=\"text/javascript\" src=\"div/overlib.js\"></script>"); writer.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"div/style1.css\"/>"); writer.println("</head>"); writer.println("<body>"); writer.println("<div id=\"overDiv\" style=\"Z-INDEX: 1; POSITION: absolute\"></div>"); writer.println("<div id=\"header\">"); writer.println("<div id=\"logo\">"); writer.println( "<img src=\"div/logo.png\" width=\"224\" height=\"52\" style=\"border:none;\" alt=\"logo\"/><br>Multi-Agent Transport Simulation Toolkit"); writer.println("</div>"); writer.println("<h3>Counting Volumes</h3>"); writer.println("</div>"); writer.println("<div id=\"footer\">"); GregorianCalendar cal = new GregorianCalendar(); writer.println(cal.get(Calendar.DATE) + "."); writer.println(cal.get(Calendar.MONTH) + 1 + "."); writer.println(cal.get(Calendar.YEAR) + "\t "); writer.println(System.getProperty("user.name")); writer.println("</div>"); writer.println("<div id=\"links\">"); for (Section sec : this.sections_) { writer.print("<h3>"); writer.print(sec.getTitle() + ":<br />"); writer.print("</h3>"); Iterator<MyURL> url_it = sec.getURLs().iterator(); while (url_it.hasNext()) { MyURL url = url_it.next(); writer.println("<a href=\"" + url.address + "\">" + url.displayText + "</a><br />"); } } writer.println("</div>"); writer.println("<div id=\"contents\">"); writer.println("<p>"); if (!indexFile) { ChartUtilities.writeImageMap(writer, "chart", info, true); /* chart=cg.getChart(); CategoryPlot plot=chart.getCategoryPlot(); Renderer renderer=(BarRenderer) plot.getRenderer(); renderer.getSeriesToolTipGenerator(0); */ /* how to get tooltips in there, without using xxxToolTipTagFragmentGenerator? Wait for next version of jFreeChart? Meanwhile doing slight changes to the libarary String imagemap=ChartUtilities.getImageMap("chart", info); System.out.println(imagemap); */ // reference '#chart' not working without '#' writer.println("<img src=\"png/" + fileName + ".png\" " + "width=\"" + width + "\" height=\"" + height + "\" style=\"border:none;\" alt=\"graph\" usemap=\"#chart\"/>"); } else { writer.println("<img src=\"div/title.png\" " + "width=\"972\" height=\"602\" style=\"border:none;\" alt=\"title\"/>"); } writer.println("</p>"); writer.println("</div>"); writer.println("</body>"); writer.println("</html>"); } catch (IOException e) { System.out.println(e.toString()); } finally { if (writer != null) { writer.close(); } } }
From source file:edu.harvard.i2b2.query.data.QueryConceptTreePanelData.java
public ConstrainByDate writeTimeConstraint() { ConstrainByDate timeConstrain = new ConstrainByDate(); DTOFactory dtoFactory = new DTOFactory(); TimeZone tz = Calendar.getInstance().getTimeZone(); GregorianCalendar cal = new GregorianCalendar(tz); //cal.get(Calendar.ZONE_OFFSET); int zt_offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000; log.info("Timezone: " + tz.getID() + " : " + zt_offset); if (startTime() != -1) { ConstrainDateType constraindateType = new ConstrainDateType(); XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(startYear(), startMonth() + 1, startDay());/*from ww w.ja v a2 s. c o m*/ xmlC.setTimezone(zt_offset);//0);//-5*60); xmlC.setHour(0); xmlC.setMinute(0); xmlC.setSecond(0); constraindateType.setValue(xmlC); timeConstrain.setDateFrom(constraindateType); } if (endTime() != -1) { ConstrainDateType constraindateType = new ConstrainDateType(); XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(endYear(), endMonth() + 1, endDay()); xmlC.setTimezone(zt_offset);//0);//-5*60); xmlC.setHour(0); xmlC.setMinute(0); xmlC.setSecond(0); constraindateType.setValue(xmlC); timeConstrain.setDateTo(constraindateType); } return timeConstrain; }
From source file:com.projity.options.CalendarOption.java
public long makeValidEnd(long end, boolean force) { end = DateTime.minuteFloor(end);// w w w.j a v a 2 s . c o m GregorianCalendar cal = DateTime.calendarInstance(); cal.setTimeInMillis(end); if (force || cal.get(GregorianCalendar.HOUR_OF_DAY) == 0 && cal.get(GregorianCalendar.MINUTE) == 0) { cal.set(GregorianCalendar.HOUR_OF_DAY, getDefaultEndTime().get(GregorianCalendar.HOUR_OF_DAY)); cal.set(GregorianCalendar.MINUTE, getDefaultEndTime().get(GregorianCalendar.MINUTE)); } return cal.getTimeInMillis(); }
From source file:com.projity.options.CalendarOption.java
public long makeValidStart(long start, boolean force) { start = DateTime.minuteFloor(start); GregorianCalendar cal = DateTime.calendarInstance(); cal.setTimeInMillis(start);//from ww w . j ava 2 s.c o m int year = cal.get(GregorianCalendar.YEAR); int dayOfYear = cal.get(GregorianCalendar.DAY_OF_YEAR); if (force || cal.get(GregorianCalendar.HOUR_OF_DAY) == 0 && cal.get(GregorianCalendar.MINUTE) == 0) { cal.set(GregorianCalendar.HOUR_OF_DAY, getDefaultStartTime().get(GregorianCalendar.HOUR_OF_DAY)); cal.set(GregorianCalendar.MINUTE, getDefaultStartTime().get(GregorianCalendar.MINUTE)); cal.set(GregorianCalendar.YEAR, year); cal.set(GregorianCalendar.DAY_OF_YEAR, dayOfYear); } return cal.getTimeInMillis(); }
From source file:org.apache.eagle.jpm.mr.history.MRHistoryJobDailyReporter.java
@Override protected void runOneIteration() throws Exception { GregorianCalendar calendar = new GregorianCalendar(timeZone); int currentHour = calendar.get(Calendar.HOUR_OF_DAY); long currentTimestamp = calendar.getTimeInMillis(); if (!isSentHour(currentHour)) { isDailySent = false;//from www . j a v a2s. c om } else if (!isDailySent) { isDailySent = true; LOG.info("last job report time is {} %s", DateTimeUtil.millisecondsToHumanDateWithSeconds(lastSentTime), timeZone.getID()); try { Collection<String> sites = loadSites(APP_TYPE); if (sites == null || sites.isEmpty()) { LOG.warn("application MR_HISTORY_JOB_APP does not run on any sites!"); return; } for (String site : sites) { int reportHour = currentHour / dailySentPeriod * dailySentPeriod; calendar.set(Calendar.HOUR_OF_DAY, reportHour); long endTime = calendar.getTimeInMillis() / DateTimeUtil.ONEHOUR * DateTimeUtil.ONEHOUR; long startTime = endTime - DateTimeUtil.ONEHOUR * dailySentPeriod; String subject = buildAlertSubject(site, startTime, endTime); Map<String, Object> alertData = buildAlertData(site, startTime, endTime); sendByEmailWithSubject(alertData, subject); } } catch (Exception ex) { LOG.error("Fail to get job summery info due to {}", ex.getMessage(), ex); } lastSentTime = currentTimestamp; } }
From source file:com.mothsoft.alexis.engine.numeric.TopicActivityDataSetImporter.java
@Override public void importData() { if (this.transactionTemplate == null) { this.transactionTemplate = new TransactionTemplate(this.transactionManager); }/* www. java 2 s . c om*/ final List<Long> userIds = listUserIds(); final GregorianCalendar calendar = new GregorianCalendar(); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); int minute = calendar.get(Calendar.MINUTE); if (minute >= 45) { calendar.set(Calendar.MINUTE, 30); } else if (minute >= 30) { calendar.set(Calendar.MINUTE, 15); } else if (minute >= 15) { calendar.set(Calendar.MINUTE, 0); } else if (minute >= 0) { calendar.set(Calendar.MINUTE, 45); calendar.add(Calendar.HOUR_OF_DAY, -1); } final Date startDate = calendar.getTime(); calendar.add(Calendar.MINUTE, 15); calendar.add(Calendar.MILLISECOND, -1); final Date endDate = calendar.getTime(); for (final Long userId : userIds) { importTopicDataForUser(userId, startDate, endDate); } }
From source file:com.artur.softwareproject.RecordService.java
private String now() { GregorianCalendar now = new GregorianCalendar(); String ret;//from w ww. j a va 2 s . co m String m = "" + (now.get(GregorianCalendar.MONTH) + 1); //months start at 0 String d = "" + now.get(GregorianCalendar.DAY_OF_MONTH); String h = "" + (now.get(GregorianCalendar.HOUR) + 12 * now.get(GregorianCalendar.AM_PM)); String min = "" + now.get(GregorianCalendar.MINUTE); String s = "" + now.get(GregorianCalendar.SECOND); if (m.length() == 1) { m = "0" + m; } if (d.length() == 1) { d = "0" + d; } if (h.length() == 1) { h = "0" + h; } if (min.length() == 1) { min = "0" + min; } if (s.length() == 1) { s = "0" + s; } ret = "" + now.get(GregorianCalendar.YEAR) + "-" + m + "-" + d + "-" + h + "-" + min + "-" + s; return ret; }
From source file:ejava.projects.edmv.bl.DataGen.java
protected Person createXMLPerson(DMVPerson person) { Person xmlPerson = new Person(); PersonNameType name = new PersonNameType(); name.setPersonGivenName(new PersonNameTextType()); name.setPersonMiddleName(new PersonNameTextType()); name.setPersonSurName(new PersonNameTextType()); name.setPersonSuffixName(new TextType()); xmlPerson.setPersonName(name);// ww w . j a v a 2s . c o m xmlPerson.setPersonBirthDate(new Date()); xmlPerson.setSourceIDText("" + person.getId()); xmlPerson.setId("p" + ++id); name.getPersonGivenName().setValue(person.getGivenName()); name.getPersonMiddleName().setValue(person.getMiddleName()); name.getPersonSurName().setValue(person.getSurName()); name.getPersonSuffixName().setValue(person.getSuffixName()); java.util.Date dob = person.getPhysicalDetails().getDob(); if (dob != null) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(dob); XMLGregorianCalendar xDate = dtf.newXMLGregorianCalendar(); xDate.setYear(cal.get(GregorianCalendar.YEAR)); xDate.setMonth(cal.get(GregorianCalendar.MONTH) + 1); xDate.setDay(cal.get(GregorianCalendar.DAY_OF_MONTH)); xmlPerson.getPersonBirthDate().setValue(xDate); } xmlPerson.setPersonPhysicalDetails(createXMLPhysicalDetails(person.getPhysicalDetails())); for (DMVResidence residence : person.getResidences()) { ResidenceType xmlResidence = createXMLResidence(residence); xmlPerson.getResidence().add(xmlResidence); } return xmlPerson; }
From source file:gov.nih.nci.cabig.caaers.domain.DateTimeValue.java
/** * Instantiates a new date value./*w w w . j a v a2 s .com*/ * * @param date the date */ public DateTimeValue(Date date) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(date); this.day = gc.get(Calendar.DAY_OF_MONTH); this.month = gc.get(Calendar.MONTH) + 1; this.year = gc.get(Calendar.YEAR); }
From source file:voldemort.scheduled.DataCleanupJobTest.java
public void testCleanupStartTime() { // Make sure the default is always the next day. GregorianCalendar cal = new GregorianCalendar(); assertEquals("Default is not tomorrow", Utils.getDayOfTheWeekFromNow(1), (cal.get(Calendar.DAY_OF_WEEK) + 1) % 7); // When starting the server any day in the week from SUN to FRI and // targeting a saturday, should always start on the next saturday GregorianCalendar expectedStart = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 29, 0, 0, 0); Random rand = new Random(); for (int day = Calendar.SUNDAY; day <= Calendar.FRIDAY; day++) { GregorianCalendar serverStartTime = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 22 + day, rand.nextInt(24), rand.nextInt(60), rand.nextInt(60)); GregorianCalendar computedStart = Utils.getCalendarForNextRun(serverStartTime, Calendar.SATURDAY, 0); assertEquals(/*from w w w . j a v a2 s. co m*/ "Expected :" + expectedStart.getTimeInMillis() + " Computed: " + computedStart.getTimeInMillis(), expectedStart.getTimeInMillis(), computedStart.getTimeInMillis()); } // Targeting saturday, 00:00 and starting on a friday 23:59:59 should // start the next saturday GregorianCalendar serverStartTime = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 28, 23, 59, 59); GregorianCalendar computedStart = Utils.getCalendarForNextRun(serverStartTime, Calendar.SATURDAY, 0); assertEquals( "Expected :" + expectedStart.getTimeInMillis() + " Computed: " + computedStart.getTimeInMillis(), expectedStart.getTimeInMillis(), computedStart.getTimeInMillis()); // If we start past the start hour on the target day, it should start // the next week serverStartTime = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 29, 1, 0, 1); computedStart = Utils.getCalendarForNextRun(serverStartTime, Calendar.SATURDAY, 0); assertEquals(Calendar.SATURDAY, computedStart.get(Calendar.DAY_OF_WEEK)); assertEquals(serverStartTime.get(Calendar.DAY_OF_YEAR) + 7, computedStart.get(Calendar.DAY_OF_YEAR)); }