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:de.schildbach.pte.AbstractHafasLegacyProvider.java
private long time(final LittleEndianDataInputStream is, final long baseDate, final int dayOffset) throws IOException { final int value = is.readShortReverse(); if (value == 0xffff) return 0; final int hours = value / 100; final int minutes = value % 100; if (minutes < 0 || minutes > 60) throw new IllegalStateException("minutes out of range: " + minutes); final Calendar time = new GregorianCalendar(timeZone); time.setTimeInMillis(baseDate);/*from ww w . j av a 2s . co m*/ if (time.get(Calendar.HOUR) != 0 || time.get(Calendar.MINUTE) != 0) throw new IllegalStateException("baseDate not on date boundary: " + baseDate); time.add(Calendar.DAY_OF_YEAR, dayOffset); time.set(Calendar.HOUR, hours); time.set(Calendar.MINUTE, minutes); return time.getTimeInMillis(); }
From source file:com.redhat.rhn.manager.system.SystemManager.java
private static List<DuplicateSystemGrouping> listDuplicates(User user, String query, List<String> ignored, Long inactiveHours) {/*from w w w .j ava 2s . c o m*/ Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR, (0 - inactiveHours.intValue())); SelectMode ipMode = ModeFactory.getMode("System_queries", query); Date d = new Date(cal.getTimeInMillis()); Map<String, Object> params = new HashMap<String, Object>(); params.put("uid", user.getId()); params.put("inactive_date", d); DataResult<NetworkDto> nets; if (ignored.isEmpty()) { nets = ipMode.execute(params); } else { nets = ipMode.execute(params, ignored); } List<DuplicateSystemGrouping> nodes = new ArrayList<DuplicateSystemGrouping>(); for (NetworkDto net : nets) { boolean found = false; for (DuplicateSystemGrouping node : nodes) { if (node.addIfMatch(net)) { found = true; break; } } if (!found) { nodes.add(new DuplicateSystemGrouping(net)); } } return nodes; }
From source file:davmail.exchange.ews.EwsExchangeSession.java
protected String convertTaskDateToZulu(String value) { String result = null;//from w ww .j a v a2 s. c o m if (value != null && value.length() > 0) { try { SimpleDateFormat parser; if (value.length() == 8) { parser = new SimpleDateFormat("yyyyMMdd", Locale.ENGLISH); parser.setTimeZone(GMT_TIMEZONE); } else if (value.length() == 15) { parser = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH); parser.setTimeZone(GMT_TIMEZONE); } else if (value.length() == 16) { parser = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH); parser.setTimeZone(GMT_TIMEZONE); } else { parser = ExchangeSession.getExchangeZuluDateFormat(); } Calendar calendarValue = Calendar.getInstance(GMT_TIMEZONE); calendarValue.setTime(parser.parse(value)); // zulu time: add 12 hours if (value.length() == 16) { calendarValue.add(Calendar.HOUR, 12); } calendarValue.set(Calendar.HOUR, 0); calendarValue.set(Calendar.MINUTE, 0); calendarValue.set(Calendar.SECOND, 0); result = ExchangeSession.getExchangeZuluDateFormat().format(calendarValue.getTime()); } catch (ParseException e) { LOGGER.warn("Invalid date: " + value); } } return result; }
From source file:ch.algotrader.service.LookupServiceTest.java
@Test public void testGetEasyToBorrowByDateAndBroker() { SecurityFamily family = new SecurityFamilyImpl(); family.setName("Forex1"); family.setTickSizePattern("0<0.1"); family.setCurrency(Currency.USD); Stock stock1 = new StockImpl(); stock1.setSecurityFamily(family);//from w ww . ja v a 2 s . c o m Stock stock2 = new StockImpl(); stock2.setSecurityFamily(family); EasyToBorrow easyToBorrow1 = new EasyToBorrowImpl(); Calendar cal1 = Calendar.getInstance(); cal1.set(Calendar.HOUR_OF_DAY, 0); cal1.set(Calendar.MINUTE, 0); cal1.set(Calendar.SECOND, 0); cal1.set(Calendar.MILLISECOND, 0); easyToBorrow1.setDate(cal1.getTime()); easyToBorrow1.setBroker(Broker.CNX.name()); easyToBorrow1.setStock(stock1); EasyToBorrow easyToBorrow2 = new EasyToBorrowImpl(); easyToBorrow2.setDate(cal1.getTime()); easyToBorrow2.setBroker(Broker.CNX.name()); easyToBorrow2.setStock(stock2); this.session.save(family); this.session.save(stock1); this.session.save(stock2); this.session.save(easyToBorrow1); this.session.save(easyToBorrow2); this.session.flush(); List<EasyToBorrow> easyToBorrows1 = (List<EasyToBorrow>) lookupService .getEasyToBorrowByDateAndBroker(cal1.getTime(), Broker.DC.name()); Assert.assertEquals(0, easyToBorrows1.size()); Calendar cal2 = Calendar.getInstance(); cal2.set(Calendar.HOUR, 2); List<EasyToBorrow> easyToBorrows2 = (List<EasyToBorrow>) lookupService .getEasyToBorrowByDateAndBroker(cal2.getTime(), Broker.CNX.name()); Assert.assertEquals(2, easyToBorrows2.size()); List<EasyToBorrow> easyToBorrows3 = (List<EasyToBorrow>) lookupService .getEasyToBorrowByDateAndBroker(cal1.getTime(), Broker.CNX.name()); Assert.assertEquals(2, easyToBorrows3.size()); Assert.assertSame(easyToBorrow1, easyToBorrows3.get(0)); Assert.assertEquals(Broker.CNX.name(), easyToBorrows3.get(0).getBroker()); Assert.assertSame(stock1, easyToBorrows3.get(0).getStock()); Assert.assertSame(easyToBorrow2, easyToBorrows3.get(1)); Assert.assertEquals(Broker.CNX.name(), easyToBorrows3.get(1).getBroker()); Assert.assertSame(stock2, easyToBorrows3.get(1).getStock()); }
From source file:org.kuali.kfs.module.purap.document.service.impl.PurchaseOrderServiceImpl.java
/** * Creates and returns a Calendar object of today minus three months. * * @return Calendar object of today minus three months. *//*from ww w . j a v a 2s . c o m*/ protected Calendar getTodayMinusThreeMonths() { Calendar todayMinusThreeMonths = Calendar.getInstance(); // Set to today. todayMinusThreeMonths.add(Calendar.MONTH, -3); // Back up 3 months. todayMinusThreeMonths.set(Calendar.HOUR, 12); todayMinusThreeMonths.set(Calendar.MINUTE, 0); todayMinusThreeMonths.set(Calendar.SECOND, 0); todayMinusThreeMonths.set(Calendar.MILLISECOND, 0); todayMinusThreeMonths.set(Calendar.AM_PM, Calendar.AM); return todayMinusThreeMonths; }
From source file:edu.ku.kuali.kra.award.sapintegration.SapIntegrationServiceImpl.java
/** * Takes the given Date and returns a copy of the Date which has all of the * time portions of the date (hours, minutes, seconds, etc.) set to zero. * * @param givenDate/*from ww w .j av a 2 s.c om*/ * the date to zero out * @return a copy of the given date with the temporal components zeroed out */ private java.util.Date zeroOutTime(java.util.Date givenDate) { if (givenDate != null) { Calendar calendar = Calendar.getInstance(); calendar.setTime(givenDate); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); } else { return null; } }
From source file:com.emc.atmos.api.test.AtmosApiClientTest.java
@Test public void testRetention() throws Exception { Metadata retention = new Metadata("retentionperiod", "1year", false); CreateObjectRequest request = new CreateObjectRequest().content(null).userMetadata(retention); ObjectId oid = api.createObject(request.contentType("text/plain")).getObjectId(); cleanup.add(oid);/* w w w . j a va 2s . c o m*/ Thread.sleep(2000); // make sure retention is enabled ObjectInfo info = api.getObjectInfo(oid); Assume.assumeTrue(info.getRetention().isEnabled()); Calendar newEnd = Calendar.getInstance(); newEnd.setTime(info.getRetainedUntil()); DateFormat iso8601Format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); String retentionEnd = "user.maui.retentionEnd"; newEnd.set(Calendar.HOUR, 0); newEnd.set(Calendar.MINUTE, 0); newEnd.set(Calendar.SECOND, 0); newEnd.set(Calendar.MILLISECOND, 0); newEnd.add(Calendar.DATE, -1); try { api.setUserMetadata(oid, new Metadata(retentionEnd, iso8601Format.format(newEnd.getTime()), false)); Assert.fail("should not be able to shorten retention period"); } catch (AtmosException e) { Assert.assertEquals("Wrong error code", 1002, e.getErrorCode()); } // disable retention so we can delete (won't work on compliant subtenants!) api.setUserMetadata(oid, new Metadata("user.maui.retentionEnable", "false", false)); }
From source file:davmail.exchange.dav.DavExchangeSession.java
protected String convertTaskDateToZulu(String value) { String result = null;//from w w w . ja v a 2 s. c o m if (value != null && value.length() > 0) { try { SimpleDateFormat parser; if (value.length() == 8) { parser = new SimpleDateFormat("yyyyMMdd", Locale.ENGLISH); parser.setTimeZone(GMT_TIMEZONE); } else if (value.length() == 15) { parser = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH); parser.setTimeZone(GMT_TIMEZONE); } else if (value.length() == 16) { parser = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH); parser.setTimeZone(GMT_TIMEZONE); } else { parser = ExchangeSession.getExchangeZuluDateFormat(); } Calendar calendarValue = Calendar.getInstance(GMT_TIMEZONE); calendarValue.setTime(parser.parse(value)); // zulu time: add 12 hours if (value.length() == 16) { calendarValue.add(Calendar.HOUR, 12); } calendarValue.set(Calendar.HOUR, 0); calendarValue.set(Calendar.MINUTE, 0); calendarValue.set(Calendar.SECOND, 0); result = ExchangeSession.getExchangeZuluDateFormatMillisecond().format(calendarValue.getTime()); } catch (ParseException e) { LOGGER.warn("Invalid date: " + value); } } return result; }
From source file:com.globalsight.webservices.Ambassador.java
/** * Get jobs info created after start time and in one project * // w w w. ja v a 2 s . c o m * @param accessToken * Access token * @param startTime * Start time, it can be '2d', '8h' and '2d8h' format * @parma projectId Id of project * @return String XML format string * @throws WebServiceException * * @author Vincent Yan * @since 8.2.3 */ public String getJobsByTimeRange(String accessToken, String startTime, long projectId) throws WebServiceException { StringBuilder xml = new StringBuilder(XML_HEAD); xml.append("<jobs>\r\n"); boolean canRun = true; WebServicesLog.Start activityStart = null; try { String userName = this.getUsernameFromSession(accessToken); Map<Object, Object> activityArgs = new HashMap<Object, Object>(); activityArgs.put("loggedUserName", userName); activityArgs.put("startTime", startTime); activityArgs.put("projectId", projectId); activityStart = WebServicesLog.start(Ambassador.class, "getJobsByTimeRange(p_accessToken,startTime, projectId)", activityArgs); if (StringUtil.isEmpty(accessToken) || StringUtil.isEmpty(startTime) || !validateTimeRange(startTime) || projectId < 0) { return makeErrorXml("getJobsByTimeRange", "Invaild time range parameter."); } int hours = getHours(startTime); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.HOUR, 0 - hours); User user = getUser(getUsernameFromSession(accessToken)); CompanyThreadLocal.getInstance().setValue(user.getCompanyName()); JobSearchParameters searchParameters = new JobSearchParameters(); if (projectId > 0) searchParameters.setProjectId(String.valueOf(projectId)); searchParameters.setCreationStart(calendar.getTime()); String hql = "from JobImpl j where j.createDate>='" + sdf.format(calendar.getTime()) + "'"; if (!CompanyWrapper.isSuperCompanyName(user.getCompanyName())) { long companyId = CompanyWrapper.getCompanyByName(user.getCompanyName()).getId(); hql += " and j.companyId=" + companyId; } Collection collection = HibernateUtil.search(hql); // Collection collection = // ServerProxy.getJobHandler().getJobs(searchParameters); if (collection != null && collection.size() > 0) { ArrayList<JobImpl> jobs = new ArrayList<JobImpl>(collection); Job job = null; for (JobImpl ji : jobs) { job = (Job) ji; if (job == null) continue; if (projectId > 0 && projectId != job.getProjectId()) continue; if (!isInSameCompany(user.getUserName(), String.valueOf(job.getCompanyId())) && !UserUtil.isSuperAdmin(user.getUserId()) && !UserUtil.isSuperPM(user.getUserId())) continue; xml.append(getJobInfo(job)); } } } catch (Exception e) { return makeErrorXml("getJobsByTimeRange", "Cannot get jobs correctly. " + e.getMessage()); } finally { if (activityStart != null) { activityStart.end(); } } xml.append("</jobs>\r\n"); return xml.toString(); }