List of usage examples for java.util Calendar HOUR
int HOUR
To view the source code for java.util Calendar HOUR.
Click Source Link
get
and set
indicating the hour of the morning or afternoon. From source file:com.silverpeas.mailinglist.service.model.dao.TestMessageDao.java
@Test public void testListActivities() { MessageDao messageDao = getMessageDAO(); Calendar sentDate = Calendar.getInstance(); sentDate.set(Calendar.MILLISECOND, 0); sentDate.set(Calendar.SECOND, 10); sentDate.set(Calendar.MINUTE, 3); sentDate.set(Calendar.HOUR, 10); sentDate.set(Calendar.DAY_OF_MONTH, 22); sentDate.set(Calendar.MONTH, Calendar.FEBRUARY); sentDate.set(Calendar.YEAR, 2008); Message message = new Message(); message.setBody(textEmailContent);//w w w .j a v a 2s. c o m message.setComponentId("componentId"); message.setModerated(true); message.setSummary(textEmailContent.substring(0, 200)); message.setSender("bart.simpson@ilverpeas.com"); message.setMessageId("0000001747b40c22"); Date message1SentDate = sentDate.getTime(); message.setSentDate(message1SentDate); message.setTitle("Simple text message"); Attachment attachment = new Attachment(); attachment.setPath(attachmentPath + "lemonde.html"); attachment.setFileName("lemonde.html"); attachment.setSize(10000); message.getAttachments().add(attachment); attachment = new Attachment(); attachment.setPath(attachmentPath + "lemonde2.html"); attachment.setFileName("lemonde2.html"); attachment.setSize(20000); message.getAttachments().add(attachment); messageDao.saveMessage(message); message = new Message(); message.setBody(textEmailContent); message.setComponentId("componentId"); message.setModerated(true); message.setSummary(textEmailContent.substring(0, 200)); message.setSender("bart.simpson@ilverpeas.com"); message.setMessageId("0000001747b40c23"); sentDate.add(Calendar.MONTH, -1); Date message2SentDate = sentDate.getTime(); message.setSentDate(message2SentDate); message.setTitle("Simple text message 2"); messageDao.saveMessage(message); message = new Message(); message.setBody(textEmailContent); message.setComponentId("componentId"); message.setModerated(true); message.setSummary(textEmailContent.substring(0, 200)); message.setSender("bart.simpson@ilverpeas.com"); message.setMessageId("0000001747b40c24"); sentDate.add(Calendar.DAY_OF_MONTH, -1); Date message3SentDate = sentDate.getTime(); message.setSentDate(message3SentDate); message.setTitle("Simple text message 3"); messageDao.saveMessage(message); message = new Message(); message.setBody(textEmailContent); message.setComponentId("componentId"); message.setModerated(false); message.setSummary(textEmailContent.substring(0, 200)); message.setSender("bart.simpson@ilverpeas.com"); message.setMessageId("0000001747b40c25"); sentDate.add(Calendar.DAY_OF_MONTH, -1); message.setSentDate(message3SentDate); message.setTitle("Simple text message 4"); messageDao.saveMessage(message); List activities = messageDao.listActivity("componentId"); assertNotNull(activities); assertEquals(2, activities.size()); Iterator iter = activities.iterator(); while (iter.hasNext()) { Activity activity = (Activity) iter.next(); assertEquals(activity.getYear(), 2008); if (activity.getMonth() == Calendar.FEBRUARY) { assertEquals(1, activity.getNbMessages()); } else { assertEquals(Calendar.JANUARY, activity.getMonth()); assertEquals(2, activity.getNbMessages()); } } }
From source file:cx.fbn.nevernote.sql.REnSearch.java
private GregorianCalendar stringToGregorianCalendar(String date) { String datePart = date;//from www. j a v a2 s.co m GregorianCalendar calendar = new GregorianCalendar(); boolean GMT = false; String timePart = ""; if (date.contains("T")) { datePart = date.substring(0, date.indexOf("T")); timePart = date.substring(date.indexOf("T") + 1); } else { timePart = "000001"; } if (datePart.length() != 8) return null; calendar.set(Calendar.YEAR, new Integer(datePart.substring(0, 4))); calendar.set(Calendar.MONTH, new Integer(datePart.substring(4, 6)) - 1); calendar.set(Calendar.DAY_OF_MONTH, new Integer(datePart.substring(6))); if (timePart.endsWith("Z")) { GMT = true; timePart = timePart.substring(0, timePart.length() - 1); } timePart = timePart.concat("000000"); timePart = timePart.substring(0, 6); calendar.set(Calendar.HOUR, new Integer(timePart.substring(0, 2))); calendar.set(Calendar.MINUTE, new Integer(timePart.substring(2, 4))); calendar.set(Calendar.SECOND, new Integer(timePart.substring(4))); if (GMT) calendar.set(Calendar.ZONE_OFFSET, -1 * (calendar.get(Calendar.ZONE_OFFSET) / (1000 * 60 * 60))); return calendar; }
From source file:com.flexive.tests.embedded.SearchEngineTest.java
/** * Tests date and datetime queries with functions, e.g. YEAR(dateprop)=2008 * * @throws FxApplicationException on errors */// w ww .j a v a2s.c o m @Test public void dateConditionFunctionsTest() throws FxApplicationException { for (String name : new String[] { "date", "datetime" }) { testDateFunctionLT(name, 2020, DateFunction.YEAR, Calendar.YEAR); testDateFunctionLT(name, 8, DateFunction.MONTH, Calendar.MONTH); testDateFunctionLT(name, 20, DateFunction.DAY, Calendar.DAY_OF_MONTH); } testDateFunctionLT("datetime", 12, DateFunction.HOUR, Calendar.HOUR); testDateFunctionLT("datetime", 30, DateFunction.MINUTE, Calendar.MINUTE); testDateFunctionLT("datetime", 30, DateFunction.SECOND, Calendar.SECOND); }
From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java
/** * @param cal/*from w ww. ja va 2 s . co m*/ * @return */ private boolean checkHourList(GregorianCalendar cal) { if (mByHourList.size() > 0) { for (Integer cur : mByHourList) { int curHour = cal.get(Calendar.HOUR_OF_DAY); if (curHour == cur.intValue()) return true; // since the month list is in order, if we hit a HIGHER month, // then we know out current month isn't in the list, and therefore // we should go to this next one if (cur > curHour) { cal.set(Calendar.HOUR_OF_DAY, cur); return false; // must re-start checks } } // we've not found a match AND we've not found a // higher value in our list -- so wrap cal.set(Calendar.HOUR, mByHourList.get(0)); cal.add(Calendar.DAY_OF_YEAR, 1); return false; // must re-start checks } return true; }
From source file:com.mb.framework.util.DateTimeUtil.java
/** * /*from ww w . j av a2 s . c o m*/ * This method is used for getting the date/time of next 24 hrs . * * @param date * @return */ public static Date getNextDayTime(long date) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(date); ; c.add(Calendar.HOUR, 24); return c.getTime(); }
From source file:org.kuali.kfs.module.purap.document.service.impl.PaymentRequestServiceImpl.java
/** * @see org.kuali.kfs.module.purap.document.service.PaymentRequestService#isInvoiceDateAfterToday(java.sql.Date) *///from w w w . jav a2 s .c o m @Override @NonTransactional public boolean isInvoiceDateAfterToday(Date invoiceDate) { // Check invoice date to make sure it is today or before Calendar now = Calendar.getInstance(); now.set(Calendar.HOUR, 11); now.set(Calendar.MINUTE, 59); now.set(Calendar.SECOND, 59); now.set(Calendar.MILLISECOND, 59); Timestamp nowTime = new Timestamp(now.getTimeInMillis()); Calendar invoiceDateC = Calendar.getInstance(); invoiceDateC.setTime(invoiceDate); // set time to midnight invoiceDateC.set(Calendar.HOUR, 0); invoiceDateC.set(Calendar.MINUTE, 0); invoiceDateC.set(Calendar.SECOND, 0); invoiceDateC.set(Calendar.MILLISECOND, 0); Timestamp invoiceDateTime = new Timestamp(invoiceDateC.getTimeInMillis()); return ((invoiceDateTime.compareTo(nowTime)) > 0); }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getListMemberships(Session s, int groupId, UserModel currentUser) { final int NUM_MONTHS = 6; Logger log = Logger.getLogger(this.getClass()); JFreeChart chart;// ww w.j a v a 2s . co m Date startDate; TreeMap<Day, Integer> memberChange = new TreeMap<Day, Integer>(); GroupModel g = (GroupModel) s.get(GroupModel.class, groupId); if (g == null) { log.warn("Someone requested chapter stats with a bad group id"); } else if (!Permissions.canAdministerGroupMembership(currentUser, g)) { log.warn(currentUser.getUsername() + "tried to access list memberships graph!"); } Calendar cal = GregorianCalendar.getInstance(); Date now = cal.getTime(); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 1); cal.add(Calendar.MONTH, -NUM_MONTHS); startDate = cal.getTime(); //Set Initial Number of Members int initMembers = g.getNumMembers() + g.getNumRecipients(); //Pull a list of all of the membership start dates List starts = s.createQuery("SELECT rm.start, count(*) " + "FROM RoleModel as rm " + "WHERE rm.group = :group " + "AND (rm.level = 'r' OR rm.level = 'm') " + "AND rm.start > :startDate " + "GROUP BY rm.start ").setEntity("group", g) .setDate("startDate", startDate).list(); for (Object o : starts) { Day date = new Day((Date) (((Object[]) o)[0])); int change = ((Long) (((Object[]) o)[1])).intValue(); memberChange.put(date, change); initMembers -= change; } //Pull a list of all of the membership end dates List ends = s.createQuery("SELECT rm.end, count(*) " + "FROM RoleModel as rm " + "WHERE rm.group = :group " + "AND (rm.level = 'r' OR rm.level = 'm') " + "AND rm.end > :startDate " + "GROUP BY rm.end ") .setEntity("group", g).setDate("startDate", startDate).list(); for (Object o : ends) { Day date = new Day((Date) (((Object[]) o)[0])); int change = ((Long) (((Object[]) o)[1])).intValue(); if (memberChange.containsKey(date)) { memberChange.put(date, memberChange.get(date) - change); } else { memberChange.put(date, -change); } initMembers += change; } TimeSeriesCollection theData = new TimeSeriesCollection(); TimeSeries signups = new TimeSeries("List Membership", Day.class); theData.addSeries(signups); while (startDate.before(now)) { Day d = new Day(startDate); if (memberChange.containsKey(d)) { initMembers += memberChange.get(d); } signups.add(d, initMembers); cal.add(Calendar.DATE, 1); startDate = cal.getTime(); } chart = ChartFactory.createTimeSeriesChart("List Members", "Day", "Number of Members", theData, true, true, true); XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); return chart; }
From source file:com.mb.framework.util.DateTimeUtil.java
public static boolean isPriority(String dt) throws ParseException { boolean isDue = false; long dtMillis = Long.valueOf(dt); Calendar dueDt = Calendar.getInstance(); dueDt.add(Calendar.DATE, 2);/* w w w. j a v a 2 s . c o m*/ dueDt.set(Calendar.HOUR, 0); dueDt.set(Calendar.MINUTE, 0); dueDt.set(Calendar.SECOND, 0); long dueDtMillis = dueDt.getTimeInMillis(); if (dueDtMillis - dtMillis > 0) { isDue = true; } return isDue; }
From source file:com.ecofactor.qa.automation.api.ReportsAPITest.java
/** * Gets the month params./* w ww. jav a 2 s. c o m*/ * @param month the month * @return the month params */ private HashMap<String, String> getMonthParams(int month) { HashMap<String, String> params = new HashMap<String, String>(); Calendar start = DateUtil.getUTCCalendar(); start.set(Calendar.MONTH, month - 1); start.set(Calendar.DATE, 1); start.set(Calendar.HOUR, 12); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); start.set(Calendar.AM_PM, 0); Calendar end = DateUtil.getUTCCalendar(); end.set(Calendar.MONTH, month - 1); end.set(Calendar.DATE, end.getMaximum(Calendar.DATE)); end.set(Calendar.HOUR, 12); end.set(Calendar.MINUTE, 0); end.set(Calendar.SECOND, 0); start.set(Calendar.AM_PM, 0); params.put(ReportsAPIConfig.START_DATE, DateUtil.format(start, DateUtil.DATE_FMT)); params.put(ReportsAPIConfig.END_DATE, DateUtil.format(end, DateUtil.DATE_FMT)); params.put(ReportsAPIConfig.INTERVAL, "MONTHS"); return params; }
From source file:ch.algotrader.service.PortfolioServiceImpl.java
/** * {@inheritDoc}/*from w ww . j a va 2 s . c o m*/ */ @Override @Transactional(propagation = Propagation.REQUIRED) public void savePortfolioValues() { for (Strategy strategy : this.strategyDao.findAutoActivateStrategies()) { PortfolioValue portfolioValue = getPortfolioValue(strategy.getName()); // truncate Date to hour portfolioValue.setDateTime(DateUtils.truncate(portfolioValue.getDateTime(), Calendar.HOUR)); this.portfolioValueDao.save(portfolioValue); } }