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:vitkin.sfdc.mojo.wsdl.WsdlDownloadlMojo.java
/** * Tell if a session is older than an hour. * * @param client HTTP client for which to attempt deducing if the session has * expired./*from ww w . j a v a 2 s. co m*/ * * @return String The resource server for the session if the session hasn't * expired. Null otherwise. */ private String getResourceServer(InnerHttpClient client) { Log logger = getLog(); // Cookie 'oid' expiry date is supposed to be in 2 years in the future from // the date of creation of the cookie. final Calendar cal = GregorianCalendar.getInstance(); cal.add(Calendar.YEAR, 2); cal.add(Calendar.HOUR, -1); final Date futureDate = cal.getTime(); if (logger.isDebugEnabled()) { logger.debug("Future date: " + futureDate); } String resourceServer = null; for (Cookie cookie : client.getCookieStore().getCookies()) { final String name = cookie.getName(); if ("oid".equals(name)) { final Date expiryDate = cookie.getExpiryDate(); if (logger.isDebugEnabled()) { logger.debug("Expiry date: " + expiryDate); } if (futureDate.before(expiryDate)) { resourceServer = "https://" + cookie.getDomain(); } break; } } return resourceServer; }
From source file:com.marklogic.client.functionaltest.TestJacksonDateTimeFormat.java
public void validateSpArtifactDateTimeObjMapper(SpArtifactDateTimeObjMapper artifact, String artifactName, long longId, Calendar datetime) { System.out.println("Argumnt : " + datetime.toString()); System.out.println("Jackson POJO : " + artifact.getExpiryDate().toString()); assertNotNull("Artifact object should never be Null", artifact); assertNotNull("Id should never be Null", artifact.id); assertEquals("Id of the object is ", longId, artifact.getId()); assertEquals("Name of the object is ", artifactName, artifact.getName()); assertEquals("Inventory of the object is ", 1000, artifact.getInventory()); assertEquals("Company name of the object is ", artifactName, artifact.getManufacturer().getName()); assertEquals("Web site of the object is ", "http://www.acme.com", artifact.getManufacturer().getWebsite()); //Validate the calendar object's field, instead of object or string comparisions. assertEquals("Expiry date: MONTH ", datetime.get(Calendar.MONTH), artifact.getExpiryDate().get(Calendar.MONTH)); assertEquals("Expiry date: DAY_OF_MONTH ", datetime.get(Calendar.DAY_OF_MONTH), artifact.getExpiryDate().get(Calendar.DAY_OF_MONTH)); assertEquals("Expiry date: YEAR ", datetime.get(Calendar.YEAR), artifact.getExpiryDate().get(Calendar.YEAR)); assertEquals("Expiry date: HOUR ", datetime.get(Calendar.HOUR), artifact.getExpiryDate().get(Calendar.HOUR)); assertEquals("Expiry date: MINUTE ", datetime.get(Calendar.MINUTE), artifact.getExpiryDate().get(Calendar.MINUTE)); assertEquals("Expiry date: SECOND ", datetime.get(Calendar.SECOND), artifact.getExpiryDate().get(Calendar.SECOND)); assertEquals(-87.966, artifact.getManufacturer().getLongitude(), 0.00); assertEquals(41.998, artifact.getManufacturer().getLatitude(), 0.00); }
From source file:com.cloudera.sqoop.manager.OracleManagerTest.java
/** * Compare two lines. Normalize the dates we receive based on the expected * time zone.// ww w. ja v a 2s.com * @param expectedLine expected line * @param receivedLine received line * @throws IOException exception during lines comparison */ private void compareRecords(String expectedLine, String receivedLine) throws IOException { // handle null case if (expectedLine == null || receivedLine == null) { return; } // check if lines are equal if (expectedLine.equals(receivedLine)) { return; } // check if size is the same String[] expectedValues = expectedLine.split(","); String[] receivedValues = receivedLine.split(","); if (expectedValues.length != 7 || receivedValues.length != 7) { LOG.error("Number of expected fields did not match " + "number of received fields"); throw new IOException("Number of expected fields did not match " + "number of received fields"); } // check first 5 values boolean mismatch = false; for (int i = 0; !mismatch && i < 5; i++) { mismatch = !expectedValues[i].equals(receivedValues[i]); } if (mismatch) { throw new IOException("Expected:<" + expectedLine + "> but was:<" + receivedLine + ">"); } Date expectedDate = null; Date receivedDate = null; DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); int offset = TimeZone.getDefault().getOffset(System.currentTimeMillis()) / 3600000; for (int i = 5; i < 7; i++) { // parse expected timestamp. try { expectedDate = df.parse(expectedValues[i]); } catch (ParseException ex) { LOG.error("Could not parse expected timestamp: " + expectedValues[i]); throw new IOException("Could not parse expected timestamp: " + expectedValues[i]); } // parse received timestamp try { receivedDate = df.parse(receivedValues[i]); } catch (ParseException ex) { LOG.error("Could not parse received timestamp: " + receivedValues[i]); throw new IOException("Could not parse received timestamp: " + receivedValues[i]); } // compare two timestamps considering timezone offset Calendar expectedCal = Calendar.getInstance(); expectedCal.setTime(expectedDate); expectedCal.add(Calendar.HOUR, offset); Calendar receivedCal = Calendar.getInstance(); receivedCal.setTime(receivedDate); if (!expectedCal.equals(receivedCal)) { throw new IOException("Expected:<" + expectedLine + "> but was:<" + receivedLine + ">, while timezone offset is: " + offset); } } }
From source file:TimeSpan.java
/** * Returns {@code true} if the end date occurs after the start date during * the period of time represented by this time span. * /* ww w.j a v a 2 s .c o m*/ * @param mutableStartDate a <i>mutable<i> {@code Calendar} object that will * be changed to the ending time of this time range as a side effect * of this method */ private boolean isInRange(Calendar mutableStartDate, Calendar endDate) { // ensure that the ending date does not occur before the time span would // have started if (endDate.before(mutableStartDate)) return false; // update the start date to be the date at the end of the time span Calendar tsEnd = mutableStartDate; tsEnd.add(Calendar.YEAR, years); tsEnd.add(Calendar.MONTH, months); tsEnd.add(Calendar.WEEK_OF_YEAR, weeks); tsEnd.add(Calendar.DAY_OF_YEAR, days); tsEnd.add(Calendar.HOUR, hours); return endDate.before(tsEnd); }
From source file:edu.hawaii.soest.kilonalu.utilities.FileSource.java
/** * A method that executes the reading of data from the data file to the RBNB * server after all configuration of settings, connections to hosts, and * thread initiatizing occurs. This method contains the detailed code for * reading the data and interpreting the data files. *//* ww w . j a v a2s .c o m*/ protected boolean execute() { logger.debug("FileSource.execute() called."); boolean failed = true; // indicates overall success of execute() // do not execute the stream if there is no connection if (!isConnected()) return false; try { // open the data file for monitoring FileReader reader = new FileReader(new File(getFileName())); this.fileReader = new BufferedReader(reader); // add channels of data that will be pushed to the server. // Each sample will be sent to the Data Turbine as an rbnb frame. int channelIndex = 0; ChannelMap rbnbChannelMap = new ChannelMap(); // used to insert channel data ChannelMap registerChannelMap = new ChannelMap(); // used to register channels // add the DecimalASCIISampleData channel to the channelMap channelIndex = registerChannelMap.Add(getRBNBChannelName()); registerChannelMap.PutUserInfo(channelIndex, "units=none"); // and register the RBNB channels getSource().Register(registerChannelMap); registerChannelMap.Clear(); // on execute(), query the DT to find the timestamp of the last sample inserted // and be sure the following inserts are after that date ChannelMap requestMap = new ChannelMap(); int entryIndex = requestMap.Add(getRBNBClientName() + "/" + getRBNBChannelName()); logger.debug("Request Map: " + requestMap.toString()); Sink sink = new Sink(); sink.OpenRBNBConnection(getServer(), "lastEntrySink"); sink.Request(requestMap, 0., 1., "newest"); ChannelMap responseMap = sink.Fetch(5000); // get data within 5 seconds // initialize the last sample date Date initialDate = new Date(); long lastSampleTimeAsSecondsSinceEpoch = initialDate.getTime() / 1000L; logger.debug("Initialized the last sample date to: " + initialDate.toString()); logger.debug("The last sample date as a long is: " + lastSampleTimeAsSecondsSinceEpoch); if (responseMap.NumberOfChannels() == 0) { // set the last sample time to 0 since there are no channels yet lastSampleTimeAsSecondsSinceEpoch = 0L; logger.debug("Resetting the last sample date to the epoch: " + (new Date(lastSampleTimeAsSecondsSinceEpoch * 1000L)).toString()); } else if (responseMap.NumberOfChannels() > 0) { lastSampleTimeAsSecondsSinceEpoch = new Double(responseMap.GetTimeStart(entryIndex)).longValue(); logger.debug("There are existing channels. Last sample time: " + (new Date(lastSampleTimeAsSecondsSinceEpoch * 1000L)).toString()); } sink.CloseRBNBConnection(); // poll the data file for new lines of data and insert them into the RBNB while (true) { String line = fileReader.readLine(); if (line == null) { this.streamingThread.sleep(POLL_INTERVAL); } else { // test the line for the expected data pattern Matcher matcher = this.dataPattern.matcher(line); // if the line matches the data pattern, insert it into the DataTurbine if (matcher.matches()) { logger.debug("This line matches the data line pattern: " + line); Date sampleDate = getSampleDate(line); if (this.dateFormats == null || this.dateFields == null) { logger.warn("Using the default datetime format and field for sample data. " + "Use the -f and -d options to explicitly set date time fields."); } logger.debug("Sample date is: " + sampleDate.toString()); // convert the sample date to seconds since the epoch long sampleTimeAsSecondsSinceEpoch = (sampleDate.getTime() / 1000L); // only insert samples newer than the last sample seen at startup // and that are not in the future (> 1 hour since the CTD clock // may have drifted) Calendar currentCal = Calendar.getInstance(); this.tz = TimeZone.getTimeZone(this.timezone); currentCal.setTimeZone(this.tz); currentCal.add(Calendar.HOUR, 1); Date currentDate = currentCal.getTime(); if (lastSampleTimeAsSecondsSinceEpoch < sampleTimeAsSecondsSinceEpoch && sampleTimeAsSecondsSinceEpoch < currentDate.getTime() / 1000L) { // add the sample timestamp to the rbnb channel map //registerChannelMap.PutTime(sampleTimeAsSecondsSinceEpoch, 0d); rbnbChannelMap.PutTime((double) sampleTimeAsSecondsSinceEpoch, 0d); // then add the data line to the channel map channelIndex = rbnbChannelMap.Add(getRBNBChannelName()); rbnbChannelMap.PutMime(channelIndex, "text/plain"); rbnbChannelMap.PutDataAsString(channelIndex, line + "\r\n"); // be sure we are connected int numberOfChannelsFlushed = 0; try { //insert into the DataTurbine numberOfChannelsFlushed = getSource().Flush(rbnbChannelMap, true); // in the event we just lost the network, sleep, try again while (numberOfChannelsFlushed < 1) { logger.debug("No channels flushed, trying again in 10 seconds."); Thread.sleep(10000L); numberOfChannelsFlushed = getSource().Flush(rbnbChannelMap, true); } } catch (SAPIException sapie) { // reconnect if an exception is thrown on Flush() logger.debug("Error while flushing the source: " + sapie.getMessage()); logger.debug("Disconnecting from the DataTurbine."); disconnect(); logger.debug("Connecting to the DataTurbine."); connect(); getSource().Flush(rbnbChannelMap); // in the event we just lost the network, sleep, try again while (numberOfChannelsFlushed < 1) { logger.debug("No channels flushed, trying again in 10 seconds."); Thread.sleep(10000L); numberOfChannelsFlushed = getSource().Flush(rbnbChannelMap, true); } } // reset the last sample time to the sample just inserted lastSampleTimeAsSecondsSinceEpoch = sampleTimeAsSecondsSinceEpoch; logger.debug("Last sample time is now: " + (new Date(lastSampleTimeAsSecondsSinceEpoch * 1000L).toString())); logger.info(getRBNBClientName() + " Sample sent to the DataTurbine: " + line.trim()); rbnbChannelMap.Clear(); } else { logger.info("The current line is earlier than the last entry " + "in the Data Turbine or is a date in the future. " + "Skipping it. The line was: " + line); } } else { logger.info("The current line doesn't match an expected " + "data line pattern. Skipping it. The line was: " + line); } } // end if() } // end while } catch (ParseException pe) { logger.info( "There was a problem parsing the sample date string. " + "The message was: " + pe.getMessage()); try { this.fileReader.close(); } catch (IOException ioe2) { logger.info( "There was a problem closing the data file. The " + "message was: " + ioe2.getMessage()); } failed = true; return !failed; } catch (SAPIException sapie) { logger.info("There was a problem communicating with the DataTurbine. " + "The message was: " + sapie.getMessage()); try { this.fileReader.close(); } catch (IOException ioe2) { logger.info( "There was a problem closing the data file. The " + "message was: " + ioe2.getMessage()); } failed = true; return !failed; } catch (InterruptedException ie) { logger.info( "There was a problem while polling the data file. The " + "message was: " + ie.getMessage()); try { this.fileReader.close(); } catch (IOException ioe2) { logger.info( "There was a problem closing the data file. The " + "message was: " + ioe2.getMessage()); } failed = true; return !failed; } catch (IOException ioe) { logger.info("There was a problem opening the data file. " + "The message was: " + ioe.getMessage()); failed = true; return !failed; } }
From source file:com.swiftcorp.portal.common.util.CalendarUtils.java
public static Calendar getDayInitialCalendar(Calendar cal) { // get the time Date date = cal.getTime();/*from www .j a v a2 s. c o m*/ Calendar initialCal = Calendar.getInstance(); initialCal.setTime(date); // set the hour min sec initialCal.set(Calendar.HOUR, 0); initialCal.set(Calendar.HOUR_OF_DAY, 0); initialCal.set(Calendar.MINUTE, 0); initialCal.set(Calendar.SECOND, 0); // return cal return initialCal; }
From source file:com.panet.imeta.job.entries.special.JobEntrySpecial.java
private long getNextMonthlyExecutionTime() { Calendar calendar = Calendar.getInstance(); long nowMillis = calendar.getTimeInMillis(); int amHour = hour; if (amHour > 12) { amHour = amHour - 12;// www.jav a2s. c om calendar.set(Calendar.AM_PM, Calendar.PM); } else { calendar.set(Calendar.AM_PM, Calendar.AM); } calendar.set(Calendar.HOUR, amHour); calendar.set(Calendar.MINUTE, minutes); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); if (calendar.getTimeInMillis() <= nowMillis) { calendar.add(Calendar.MONTH, 1); } return calendar.getTimeInMillis() - nowMillis; }
From source file:strat.mining.multipool.stats.service.impl.DonationServiceImpl.java
/** * Return the date object that represent the first day of month * /*w w w . ja v a2 s . co m*/ * @return */ private Date getFirstDayOfMonthDate() { Calendar calendar = new GregorianCalendar(); calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.DAY_OF_MONTH, 1); return calendar.getTime(); }
From source file:de.dal33t.powerfolder.ui.information.stats.StatsInformationCard.java
private void redrawUsedBandwidthStats() { Cursor c = CursorUtils.setWaitCursor(uiComponent); try {/*from www. j a v a 2s.c o m*/ int usedGraphType = usedGraphTypeComboBox.getSelectedIndex(); int usedDataType = usedDataTypeComboBox.getSelectedIndex(); availableBandwidthSeries.clear(); usedBandwidthSeries.clear(); averageBandwidthSeries.clear(); Set<CoalescedBandwidthStat> stats = getController().getTransferManager().getBandwidthStats(); Calendar cal = Calendar.getInstance(); boolean first = true; Date last = null; for (CoalescedBandwidthStat stat : stats) { Hour hour = new Hour(stat.getDate()); if (first) { first = false; cal.setTime(stat.getDate()); } if (stat.getInfo() == BandwidthLimiterInfo.WAN_INPUT && usedDataType == 0 || stat.getInfo() == BandwidthLimiterInfo.WAN_OUTPUT && usedDataType == 1 || stat.getInfo() == BandwidthLimiterInfo.LAN_INPUT && usedDataType == 2 || stat.getInfo() == BandwidthLimiterInfo.LAN_OUTPUT && usedDataType == 3) { if (usedGraphType == 0 || usedGraphType == 1) { usedBandwidthSeries.add(hour, stat.getUsedBandwidth() / 1000.0); } if (usedGraphType == 0 || usedGraphType == 2) { availableBandwidthSeries.add(hour, stat.getInitialBandwidth() / 1000.0); } if (usedGraphType == 3) { averageBandwidthSeries.add(hour, stat.getAverageUsedBandwidth() / 1000.0); } } last = stat.getDate(); } if (last != null) { while (cal.getTime().before(last)) { Hour hour = new Hour(cal.getTime()); if (availableBandwidthSeries.getDataItem(hour) == null) { availableBandwidthSeries.add(hour, 0.0); } if (usedBandwidthSeries.getDataItem(hour) == null) { usedBandwidthSeries.add(hour, 0.0); } if (averageBandwidthSeries.getDataItem(hour) == null) { averageBandwidthSeries.add(hour, 0.0); } cal.add(Calendar.HOUR, 1); } } } finally { CursorUtils.returnToOriginal(uiComponent, c); } }
From source file:es.tid.fiware.rss.dao.impl.DbeTransactionDaoImpl.java
@Override public List<DbeTransaction> getTransactionBySvcPrdtUserDate(final Long nuServiceId, final Long nuProductId, final String enduserid, final Date rqDate) { DbeTransactionDaoImpl.LOGGER.debug("Entering getTransactionBySvcPrdtUserDate..."); Criteria criteria = this.getSession().createCriteria(DbeTransaction.class); criteria.add(Restrictions.eq("bmService.nuServiceId", nuServiceId)); if (nuProductId != null) { DbeTransactionDaoImpl.LOGGER.debug("product is NOT NULL"); criteria.add(Restrictions.eq("bmProduct.nuProductId", nuProductId)); }/*from ww w .ja v a2s . c o m*/ criteria.add(Restrictions.eq("txEndUserId", enduserid)); DbeTransactionDaoImpl.LOGGER.debug("date of request:" + rqDate.toString()); Calendar calendar = Calendar.getInstance(); calendar.setTime(rqDate); int monthreq = calendar.get(Calendar.MONTH); DbeTransactionDaoImpl.LOGGER.debug("MONTH ini:" + monthreq); int yearreq = calendar.get(Calendar.YEAR); DbeTransactionDaoImpl.LOGGER.debug("YEAR ini:" + yearreq); int dayreq = calendar.get(Calendar.DATE); DbeTransactionDaoImpl.LOGGER.debug("DAY ini:" + dayreq); Calendar calini = Calendar.getInstance(); calini.set(Calendar.YEAR, yearreq); calini.set(Calendar.MONTH, monthreq); calini.set(Calendar.DAY_OF_MONTH, dayreq); calini.set(Calendar.HOUR_OF_DAY, 0); calini.set(Calendar.MINUTE, 0); calini.set(Calendar.SECOND, 0); calini.set(Calendar.MILLISECOND, 0); Date dateini = calini.getTime(); DbeTransactionDaoImpl.LOGGER.debug("string date ini:" + dateini.toString()); DbeTransactionDaoImpl.LOGGER.debug("date ini:" + calini.get(Calendar.YEAR) + "-" + calini.get(Calendar.MONTH) + "-" + calini.get(Calendar.DATE) + "-" + calini.get(Calendar.HOUR) + "-" + calini.get(Calendar.MINUTE)); Calendar calfin = Calendar.getInstance(); calfin.set(Calendar.YEAR, yearreq); calfin.set(Calendar.MONTH, monthreq); calfin.set(Calendar.DAY_OF_MONTH, dayreq); calfin.set(Calendar.HOUR_OF_DAY, 23); calfin.set(Calendar.MINUTE, 59); calfin.set(Calendar.SECOND, 59); calfin.set(Calendar.MILLISECOND, 999); Date datefin = calfin.getTime(); DbeTransactionDaoImpl.LOGGER.debug("string date fin:" + datefin.toString()); DbeTransactionDaoImpl.LOGGER.debug("date fin:" + calfin.get(Calendar.YEAR) + "-" + calfin.get(Calendar.MONTH) + "-" + calfin.get(Calendar.DATE) + "-" + calfin.get(Calendar.HOUR) + "-" + calfin.get(Calendar.MINUTE)); criteria.add(Restrictions.between("tsRequest", dateini, datefin)); List<DbeTransaction> result = criteria.list(); return result; }