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:net.sourceforge.eclipsetrader.opentick.HistoryFeed.java
public void requestHistoryStream(final Security security, long timeout) { Calendar from = Calendar.getInstance(); Calendar to = Calendar.getInstance(); to.set(Calendar.HOUR, 23); to.set(Calendar.MINUTE, 59);/*w w w.j a v a 2 s . c om*/ to.set(Calendar.SECOND, 59); to.set(Calendar.MILLISECOND, 0); HistoryClientAdapter adapter = new HistoryClientAdapter(security); client.addListener(adapter); String symbol = security.getHistoryFeed().getSymbol(); if (symbol == null || symbol.length() == 0) symbol = security.getCode(); String exchange = security.getHistoryFeed().getExchange(); if (exchange == null || exchange.length() == 0) exchange = "Q"; History history = security.getHistory(); if (history.size() == 0) { from = Calendar.getInstance(); from.add(Calendar.YEAR, -CorePlugin.getDefault().getPreferenceStore().getInt(CorePlugin.PREFS_HISTORICAL_PRICE_RANGE)); } else { Bar last = history.getLast(); from.setTime(last.getDate()); from.add(Calendar.DATE, 1); } from.set(Calendar.HOUR, 0); from.set(Calendar.MINUTE, 0); from.set(Calendar.SECOND, 0); from.set(Calendar.MILLISECOND, 0); try { adapter.historyStream = client.requestHistData(new OTDataEntity(exchange, symbol), (int) (from.getTimeInMillis() / 1000), (int) (to.getTimeInMillis() / 1000), OTConstants.OT_HIST_OHLC_DAILY, 1); log.debug(String.valueOf(adapter.historyStream) + " / Request History " + security + " [" + CorePlugin.getDateFormat().format(from.getTime()) + "-" + CorePlugin.getDateFormat().format(to.getTime()) + "]"); } catch (Exception e) { log.warn(e); } List splits = security.getSplits(); if (splits.size() == 0) { from = Calendar.getInstance(); from.add(Calendar.YEAR, -CorePlugin.getDefault().getPreferenceStore().getInt(CorePlugin.PREFS_HISTORICAL_PRICE_RANGE)); } else { Split last = (Split) splits.get(splits.size() - 1); from.setTime(last.getDate()); from.add(Calendar.DATE, 1); } from.set(Calendar.HOUR, 0); from.set(Calendar.MINUTE, 0); from.set(Calendar.SECOND, 0); from.set(Calendar.MILLISECOND, 0); try { adapter.splitsStream = client.requestSplits(new OTDataEntity(exchange, symbol), (int) (from.getTimeInMillis() / 1000), (int) (to.getTimeInMillis() / 1000)); log.debug(String.valueOf(adapter.splitsStream) + " / Request Splits " + security + " [" + CorePlugin.getDateFormat().format(from.getTime()) + "-" + CorePlugin.getDateFormat().format(to.getTime()) + "]"); } catch (Exception e) { log.warn(e); } List dividends = security.getDividends(); if (dividends.size() == 0) { from = Calendar.getInstance(); from.add(Calendar.YEAR, -CorePlugin.getDefault().getPreferenceStore().getInt(CorePlugin.PREFS_HISTORICAL_PRICE_RANGE)); } else { Dividend last = (Dividend) dividends.get(dividends.size() - 1); from.setTime(last.getDate()); from.add(Calendar.DATE, 1); } from.set(Calendar.HOUR, 0); from.set(Calendar.MINUTE, 0); from.set(Calendar.SECOND, 0); from.set(Calendar.MILLISECOND, 0); try { adapter.dividendsStream = client.requestDividends(new OTDataEntity(exchange, symbol), (int) (from.getTimeInMillis() / 1000), (int) (to.getTimeInMillis() / 1000)); log.debug(String.valueOf(adapter.dividendsStream) + " / Request Dividends " + security + " [" + CorePlugin.getDateFormat().format(from.getTime()) + "-" + CorePlugin.getDateFormat().format(to.getTime()) + "]"); } catch (Exception e) { log.warn(e); } adapter.started = System.currentTimeMillis(); try { while ((System.currentTimeMillis() - adapter.started) < timeout && !adapter.isCompleted()) Thread.sleep(100); } catch (Exception e) { log.warn(e); } client.removeListener(adapter); Collections.sort(security.getDividends(), new Comparator() { public int compare(Object o1, Object o2) { return ((Dividend) o1).getDate().compareTo(((Dividend) o2).getDate()); } }); Collections.sort(security.getSplits(), new Comparator() { public int compare(Object o1, Object o2) { return ((Split) o1).getDate().compareTo(((Split) o2).getDate()); } }); CorePlugin.getRepository().save(history); CorePlugin.getRepository().save(security); }
From source file:helper.lang.DateHelperTest.java
@Test public void testGetRangeDaysBeforeOneDay() { int days = 1; Calendar localtime = Calendar.getInstance(); CalendarRange range = DateHelper.getRangeFullDaysBefore(localtime, days); Calendar start = range.getStart(); Calendar end = range.getEnd(); System.out.println(DateFormatUtils.SMTP_DATETIME_FORMAT.format(start)); System.out.println(DateFormatUtils.SMTP_DATETIME_FORMAT.format(end)); // end date is midnight of date passed in assertEquals(localtime.get(Calendar.YEAR), end.get(Calendar.YEAR)); assertEquals(localtime.get(Calendar.MONTH), end.get(Calendar.MONTH)); assertEquals(localtime.get(Calendar.DATE), end.get(Calendar.DATE)); assertEquals(0, end.get(Calendar.HOUR)); assertEquals(0, end.get(Calendar.MINUTE)); assertEquals(0, end.get(Calendar.SECOND)); assertEquals(0, end.get(Calendar.MILLISECOND)); assertEquals(0, end.get(Calendar.HOUR_OF_DAY)); assertEquals(DateHelper.UTC_TIME_ZONE, end.getTimeZone()); // start date is 11:59:59 or 'days' time localtime.add(Calendar.DATE, -(days + 2)); //-1 is day before, -1 for day before day before, to include day before (> x) assertEquals(localtime.get(Calendar.YEAR), start.get(Calendar.YEAR)); assertEquals(localtime.get(Calendar.MONTH), start.get(Calendar.MONTH)); assertEquals(localtime.get(Calendar.DATE), start.get(Calendar.DATE)); assertEquals(11, start.get(Calendar.HOUR)); assertEquals(23, start.get(Calendar.HOUR_OF_DAY)); assertEquals(59, start.get(Calendar.MINUTE)); assertEquals(59, start.get(Calendar.SECOND)); assertEquals(999, start.get(Calendar.MILLISECOND)); assertEquals(DateHelper.UTC_TIME_ZONE, start.getTimeZone()); }
From source file:gobblin.source.extractor.utils.Utils.java
public static Date addHoursToDate(Date datetime, int hours) { Calendar calendar = Calendar.getInstance(); calendar.setTime(datetime);/*from w w w. j a va2 s . co m*/ calendar.add(Calendar.HOUR, hours); return calendar.getTime(); }
From source file:edu.hawaii.soest.pacioos.text.FileTextSource.java
protected boolean execute() { log.debug("FileTextSource.execute() called."); boolean failed = false; // indicates overall success of execute() // do not execute the stream if there is no connection if (!isConnected()) return false; try {//from w w w . j a v a 2s. c o m // open the data file for monitoring FileReader reader = new FileReader(new File(getDataFilePath())); 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; long lastSampleTimeAsSecondsSinceEpoch = getLastSampleTime(); // poll the data file for new lines of data and insert them into the RBNB while (true) { String line = fileReader.readLine(); if (line == null) { Thread.currentThread().sleep(this.pollInterval); } else { // test the line for the expected data pattern boolean valid = this.validateSample(line); // if the line matches the data pattern, insert it into the DataTurbine if (valid) { log.debug("This line matches the data line pattern: " + line); Date sampleDate = getSampleDate(line); if (this.dateFormats == null || this.dateFields == null) { log.warn("Using the default datetime format and field for sample data. " + "Use the -f and -d options to explicitly set date time fields."); } log.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) { int numberOfChannelsFlushed = 0; try { //insert into the DataTurbine numberOfChannelsFlushed = this.sendSample(line); } catch (SAPIException sapie) { // reconnect if an exception is thrown on Flush() log.error("Error while flushing the source: " + sapie.getMessage()); failed = true; } // reset the last sample time to the sample just inserted lastSampleTimeAsSecondsSinceEpoch = sampleTimeAsSecondsSinceEpoch; log.debug("Last sample time is now: " + (new Date(lastSampleTimeAsSecondsSinceEpoch * 1000L).toString())); log.info(getRBNBClientName() + " Sample sent to the DataTurbine: " + line.trim()); } else { log.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 { log.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) { log.info("There was a problem parsing the sample date string. The message was: " + pe.getMessage()); failed = true; return !failed; } catch (SAPIException sapie) { log.info("There was a problem communicating with the DataTurbine. The message was: " + sapie.getMessage()); failed = true; return !failed; } catch (InterruptedException ie) { log.info("There was a problem while polling the data file. The message was: " + ie.getMessage()); failed = true; return !failed; } catch (IOException ioe) { log.info("There was a problem opening the data file. The message was: " + ioe.getMessage()); failed = true; return !failed; } finally { try { this.fileReader.close(); } catch (IOException ioe2) { log.error("There was a problem closing the data file. The message was: " + ioe2.getMessage()); } } }
From source file:com.ozpathway.sw.erms.webapp.action.schedule.ScheduleBean.java
public void addSampleEntries(ActionEvent event) { if (model == null) return;// w w w . j a v a2s.c om Calendar calendar = GregorianCalendar.getInstance(); calendar.setTime(model.getSelectedDate()); calendar.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); calendar.set(Calendar.HOUR_OF_DAY, 14); DefaultScheduleEntry entry1 = new DefaultScheduleEntry(); // every entry in a schedule must have a unique id entry1.setId(RandomStringUtils.randomNumeric(32)); entry1.setStartTime(calendar.getTime()); calendar.add(Calendar.MINUTE, 45); entry1.setEndTime(calendar.getTime()); entry1.setTitle("Test MyFaces schedule component"); entry1.setSubtitle("my office"); entry1.setDescription("We need to get this thing out of the sandbox ASAP"); model.addEntry(entry1); DefaultScheduleEntry entry2 = new DefaultScheduleEntry(); entry2.setId(RandomStringUtils.randomNumeric(32)); // entry2 overlaps entry1 calendar.add(Calendar.MINUTE, -20); entry2.setStartTime(calendar.getTime()); calendar.add(Calendar.HOUR, 2); entry2.setEndTime(calendar.getTime()); entry2.setTitle("Show schedule component to boss"); entry2.setSubtitle("my office"); entry2.setDescription("Convince him to get time to thoroughly test it"); model.addEntry(entry2); DefaultScheduleEntry entry3 = new DefaultScheduleEntry(); entry3.setId(RandomStringUtils.randomNumeric(32)); calendar.add(Calendar.DATE, 1); calendar.set(Calendar.HOUR_OF_DAY, 9); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); entry3.setStartTime(calendar.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 17); entry3.setEndTime(calendar.getTime()); entry3.setTitle("Thoroughly test schedule component"); model.addEntry(entry3); DefaultScheduleEntry entry4 = new DefaultScheduleEntry(); entry4.setId(RandomStringUtils.randomNumeric(32)); calendar.add(Calendar.MONTH, -1); calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); calendar.set(Calendar.HOUR_OF_DAY, 11); entry4.setStartTime(calendar.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 14); entry4.setEndTime(calendar.getTime()); entry4.setTitle("Long lunch"); model.addEntry(entry4); DefaultScheduleEntry entry5 = new DefaultScheduleEntry(); entry5.setId(RandomStringUtils.randomNumeric(32)); calendar.add(Calendar.MONTH, 2); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, 1); entry5.setStartTime(calendar.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 5); entry5.setEndTime(calendar.getTime()); entry5.setTitle("Fishing trip"); model.addEntry(entry5); // Let's add a zero length entry... DefaultScheduleEntry entry6 = new DefaultScheduleEntry(); calendar.setTime(model.getSelectedDate()); calendar.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY); calendar.set(Calendar.HOUR_OF_DAY, 16); entry6.setId(RandomStringUtils.randomNumeric(32)); entry6.setStartTime(calendar.getTime()); entry6.setEndTime(calendar.getTime()); entry6.setTitle("Zero length entry"); entry6.setDescription("Is only rendered when the 'renderZeroLengthEntries' attribute is 'true'"); model.addEntry(entry6); // And also an allday event DefaultScheduleEntry entry7 = new DefaultScheduleEntry(); entry7.setId(RandomStringUtils.randomNumeric(32)); entry7.setTitle("All day event"); entry7.setSubtitle("This event renders as an all-day event"); entry7.setAllDay(true); model.addEntry(entry7); model.refresh(); }
From source file:e.pkg3.pkg6a.acertijo.acertijo.java
private void botonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonActionPerformed int numero_Usuario = 0; try {/*w w w. j av a 2 s . com*/ numero_Usuario = Integer.valueOf(texto.getText()); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(this, "Introduce un Numero"); e.printStackTrace(); contador++; } int resta = numero_Aleatorio - numero_Usuario; if (resta < 0) { area.setText("El numero es menor que " + numero_Usuario); } if (resta > 0) { area.setText("El numero es mayor que " + numero_Usuario); } contador++; if (resta == 0) { Calendar fin = Calendar.getInstance(); String formato = "HH:mm:ss"; long inicioMilis = (inicio.get(Calendar.HOUR) * 3600000L) + (inicio.get(Calendar.MINUTE) * 60000L) + (inicio.get(Calendar.SECOND) * 1000L); long finalMilis = (fin.get(Calendar.HOUR) * 3600000L) + (fin.get(Calendar.MINUTE) * 60000L) + (fin.get(Calendar.SECOND) * 1000L); String duracion = DurationFormatUtils.formatPeriod(inicioMilis, finalMilis, formato); area.setText("El numero es Correcto!\n"); area.append("Acertado en " + contador + " intentos\n"); area.append("Acertado en " + duracion); contador = 0; boton.setEnabled(false); texto.setEnabled(false); } }
From source file:it.govpay.web.rs.dars.statistiche.transazioni.DistribuzioneEsitiHandler.java
@Override public PaginaGrafico getGrafico(UriInfo uriInfo, BasicBD bd) throws WebApplicationException, ConsoleException { String methodName = "getGrafico " + this.titoloServizio; try {//from w w w . ja v a2 s .co m // Operazione consentita solo agli utenti che hanno almeno un ruolo consentito per la funzionalita' this.darsService.checkDirittiServizio(bd, this.funzionalita); this.log.info("Esecuzione " + methodName + " in corso..."); TransazioniBD transazioniBD = new TransazioniBD(bd); TransazioniFilter filter = transazioniBD.newFilter(); this.popolaFiltroRicerca(uriInfo, transazioniBD, filter); Calendar calendar = Calendar.getInstance(); calendar.setTime(filter.getData()); SimpleDateFormat _sdf = null; switch (filter.getTipoIntervallo()) { case MENSILE: calendar.add(Calendar.MONTH, -(filter.getLimit() - 1)); _sdf = this.sdfMese; break; case GIORNALIERO: calendar.add(Calendar.DATE, -(filter.getLimit() - 1)); _sdf = this.sdfGiorno; break; case ORARIO: calendar.add(Calendar.HOUR, -(filter.getLimit() - 1)); _sdf = this.sdf; break; } Date start = calendar.getTime(); String sottoTitolo = Utils.getInstance(this.getLanguage()).getMessageWithParamsFromResourceBundle( this.nomeServizio + ".label.sottotitolo", _sdf.format(start), _sdf.format(filter.getData())); // visualizza la ricerca solo se i risultati sono > del limit InfoForm infoRicerca = this.getInfoRicerca(uriInfo, bd); Map<String, ParamField<?>> infoGrafico = this.getInfoGrafico(uriInfo, bd); // valorizzo i valori da restitire al client infoGrafico = this.valorizzaInfoGrafico(uriInfo, bd, filter, infoGrafico); List<DistribuzioneEsiti> distribuzioneEsiti = transazioniBD.getDistribuzioneEsiti(filter); this.log.info("Esecuzione " + methodName + " completata."); PaginaGrafico paginaGrafico = new PaginaGrafico(this.titoloServizio, this.getInfoEsportazione(uriInfo, bd), infoRicerca, infoGrafico); Grafico grafico = new Grafico(TipoGrafico.bar); grafico.setLabelX(Utils.getInstance(this.getLanguage()) .getMessageFromResourceBundle(this.nomeServizio + ".xAxis.label")); grafico.setLabelY(Utils.getInstance(this.getLanguage()) .getMessageFromResourceBundle(this.nomeServizio + ".yAxis.label")); grafico.setTitolo(Utils.getInstance(this.getLanguage()) .getMessageFromResourceBundle(this.nomeServizio + ".label.titolo")); grafico.setSottotitolo(sottoTitolo); grafico.getColori().addAll(Colori.getColoriTransazioni()); grafico.getCategorie().add(Utils.getInstance(this.getLanguage()) .getMessageFromResourceBundle(this.nomeServizio + ".transazioniCompletate.label")); grafico.getCategorie().add(Utils.getInstance(this.getLanguage()) .getMessageFromResourceBundle(this.nomeServizio + ".transazioniRifiutate.label")); grafico.getCategorie().add(Utils.getInstance(this.getLanguage()) .getMessageFromResourceBundle(this.nomeServizio + ".transazioniInCorso.label")); if (distribuzioneEsiti != null && distribuzioneEsiti.size() > 0) { Serie<Long> serie1 = new Serie<Long>(); Serie<Long> serie2 = new Serie<Long>(); Serie<Long> serie3 = new Serie<Long>(); for (DistribuzioneEsiti elemento : distribuzioneEsiti) { String dataElemento = _sdf.format(elemento.getData()); long serie1Val = elemento.getEseguiti(); long serie2Val = elemento.getErrori(); long serie3Val = elemento.getIn_corso(); grafico.getValoriX().add(dataElemento); serie1.getDati().add(serie1Val); serie2.getDati().add(serie2Val); serie3.getDati().add(serie3Val); serie1.getTooltip() .add(Utils.getInstance(this.getLanguage()).getMessageWithParamsFromResourceBundle( this.nomeServizio + ".transazioniCompletate.tooltip", dataElemento, serie1Val)); serie2.getTooltip() .add(Utils.getInstance(this.getLanguage()).getMessageWithParamsFromResourceBundle( this.nomeServizio + ".transazioniRifiutate.tooltip", dataElemento, serie2Val)); serie3.getTooltip() .add(Utils.getInstance(this.getLanguage()).getMessageWithParamsFromResourceBundle( this.nomeServizio + ".transazioniInCorso.tooltip", dataElemento, serie3Val)); } grafico.getSerie().add(serie1); grafico.getSerie().add(serie2); grafico.getSerie().add(serie3); } paginaGrafico.setGrafico(grafico); DistribuzionePsp distrPsp = new DistribuzionePsp(); URI grafico2 = new URI(distrPsp.getPathServizio()); ElementoCorrelato graficoTorta = new ElementoCorrelato(Utils.getInstance(this.getLanguage()) .getMessageFromResourceBundle(distrPsp.getNomeServizio() + ".titolo"), grafico2); // elementi correlati paginaGrafico.getElementiCorrelati().add(graficoTorta); return paginaGrafico; } catch (WebApplicationException e) { throw e; } catch (Exception e) { throw new ConsoleException(e); } }
From source file:com.orange.cepheus.broker.SubscriptionsTest.java
@Test public void addSubscriptionWithZeroDurationTest() throws SubscriptionException, URISyntaxException, SubscriptionPersistenceException { SubscribeContext subscribeContext = createSubscribeContextTemperature(); subscribeContext.setDuration("PT0S"); String subscriptionId = subscriptions.addSubscription(subscribeContext); Assert.notNull(subscriptionId);//from ww w . j ava 2 s. c o m Assert.hasLength(subscriptionId); Subscription subscription = subscriptions.getSubscription(subscriptionId); Assert.notNull(subscription); Assert.notNull(subscription.getExpirationDate()); Assert.notNull(subscription.getSubscriptionId()); assertEquals(subscriptionId, subscription.getSubscriptionId()); Calendar c = (Calendar) Calendar.getInstance().clone(); c.add(Calendar.MONTH, 1); c.add(Calendar.HOUR, 24); assertFalse(subscription.getExpirationDate().isAfter(c.toInstant())); c.add(Calendar.HOUR, -48); assertFalse(subscription.getExpirationDate().isBefore(c.toInstant())); Assert.isTrue(subscriptionsRepository.getAllSubscriptions().size() == 1); }
From source file:cognitivabrasil.obaa.Technical.Duration.java
public void setDuration(String durationFormated) { if (durationFormated.matches("\\d\\d?")) { this.set(Integer.parseInt(durationFormated), Calendar.HOUR); }// w w w . j ava 2 s. co m if (durationFormated.matches("\\d\\dh")) { String h = durationFormated.substring(0, durationFormated.length() - 1); this.set(Integer.parseInt(h), Calendar.HOUR); } if (durationFormated.matches("\\d\\d?h\\d\\d?")) { String h = durationFormated.substring(0, durationFormated.indexOf('h')); String min = durationFormated.substring(durationFormated.indexOf('h') + 1); this.set(Integer.parseInt(h), Calendar.HOUR); this.set(Integer.parseInt(min), Calendar.MINUTE); } if (durationFormated.matches("\\d\\d?h\\d\\d?min")) { String h = durationFormated.substring(0, durationFormated.indexOf('h')); String min = durationFormated.substring(durationFormated.indexOf('h') + 1, durationFormated.length() - 3); this.set(Integer.parseInt(h), Calendar.HOUR); this.set(Integer.parseInt(min), Calendar.MINUTE); } if (durationFormated.matches("\\d\\d?h\\d\\d?min\\d\\d?")) { String h = durationFormated.substring(0, durationFormated.indexOf('h')); String min = durationFormated.substring(durationFormated.indexOf('h') + 1, durationFormated.indexOf('m')); String s = durationFormated.substring(durationFormated.indexOf('n') + 1); this.set(Integer.parseInt(h), Calendar.HOUR); this.set(Integer.parseInt(min), Calendar.MINUTE); this.set(Integer.parseInt(s), Calendar.SECOND); } if (durationFormated.matches("\\d\\d?h\\d\\d?min\\d\\d?s")) { String h = durationFormated.substring(0, durationFormated.indexOf('h')); String min = durationFormated.substring(durationFormated.indexOf('h') + 1, durationFormated.indexOf('m')); String s = durationFormated.substring(durationFormated.indexOf('n') + 1, durationFormated.length() - 1); this.set(Integer.parseInt(h), Calendar.HOUR); this.set(Integer.parseInt(min), Calendar.MINUTE); this.set(Integer.parseInt(s), Calendar.SECOND); } }
From source file:cn.loveapple.service.cool.service.health.impl.BasalBodyTemperatureServiceImpl.java
/** * //from w w w. ja va 2s . c om * {@inheritDoc} */ @Override public double getAverageBbtMeasureTime(String mail, int scope) { if (StringUtils.isEmpty(mail)) { throw new IllegalArgumentException("mail is empty."); } Calendar lastPoint = Calendar.getInstance(); lastPoint.set(Calendar.DATE, -1); Calendar startPoint = Calendar.getInstance(); startPoint.set(Calendar.DATE, -(scope + 1)); List<BasalBodyTemperatureModel> bbtList = findBasalBodyTemperatureByUser(mail, DateUtil.toDateString(startPoint.getTime(), DateUtil.DATE_PTTERN_YYYYMMDD), DateUtil.toDateString(lastPoint.getTime(), DateUtil.DATE_PTTERN_YYYYMMDD)); double totalTime = 0; // ? Calendar temp = Calendar.getInstance(); for (BasalBodyTemperatureModel basalBodyTemperatureModel : bbtList) { temp.setTime(basalBodyTemperatureModel.getTimeStamp()); totalTime += (temp.get(Calendar.MINUTE) / 60 + temp.get(Calendar.HOUR)); } return totalTime / bbtList.size(); }