List of usage examples for org.joda.time Duration getStandardSeconds
public long getStandardSeconds()
From source file:manageBeans.AddAuctionMB.java
/** * Creates an auction with a product/*from w w w . jav a2 s .c o m*/ * @param product * product to add to an auction * @return auction * the new created auction */ private Auction createAuction(Product product) { DateTime currentTime = new DateTime(); DateTime temp = new DateTime(endDate); DateTime end = new DateTime(temp.getYear(), temp.getMonthOfYear(), temp.getDayOfMonth(), endTime.getHours(), endTime.getMinutes()); // Calculate duration from start to end date Duration duration = new Duration(currentTime, end); long durationSeconds = duration.getStandardSeconds(); Auction auction = new Auction(); auction.setDuration(durationSeconds); auction.setInitPrice(price); // All auctions are published. TODO remove field from db auction.setPublished(true); Calendar calendar = Calendar.getInstance(); auction.setStartTime(calendar); auction.setProduct(product); auction.setUser(userFacade.getAuctionUser()); return auction; }
From source file:me.tongfei.progressbar.Util.java
License:Apache License
static String formatDuration(Duration d) { long s = d.getStandardSeconds(); return String.format("%d:%02d:%02d", s / 3600, (s % 3600) / 60, s % 60); }
From source file:org.apache.cloudstack.utils.process.ProcessRunner.java
License:Apache License
/** * Executes a process with provided list of commands with a given timeout that is less * than or equal to DEFAULT_MAX_TIMEOUT// w ww . j a v a 2 s .c om * @param commands list of string commands * @param timeOut timeout duration * @return returns process result */ public ProcessResult executeCommands(final List<String> commands, final Duration timeOut) { Preconditions.checkArgument(commands != null && timeOut != null && timeOut.getStandardSeconds() > 0L && (timeOut.compareTo(DEFAULT_MAX_TIMEOUT) <= 0) && executor != null); int retVal = -2; String stdOutput = null; String stdError = null; try { final Process process = new ProcessBuilder().command(commands).start(); final Future<Integer> processFuture = executor.submit(new Callable<Integer>() { @Override public Integer call() throws Exception { return process.waitFor(); } }); try { retVal = processFuture.get(timeOut.getStandardSeconds(), TimeUnit.SECONDS); } catch (ExecutionException e) { retVal = -2; stdError = e.getMessage(); if (LOG.isTraceEnabled()) { LOG.trace("Failed to complete the requested command due to execution error: " + e.getMessage()); } } catch (TimeoutException e) { retVal = -1; stdError = "Operation timed out, aborted"; if (LOG.isTraceEnabled()) { LOG.trace("Failed to complete the requested command within timeout: " + e.getMessage()); } } finally { if (Strings.isNullOrEmpty(stdError)) { stdOutput = CharStreams.toString(new InputStreamReader(process.getInputStream())); stdError = CharStreams.toString(new InputStreamReader(process.getErrorStream())); } process.destroy(); } if (LOG.isTraceEnabled()) { LOG.trace("Process standard output: " + stdOutput); LOG.trace("Process standard error output: " + stdError); } } catch (IOException | InterruptedException e) { stdError = e.getMessage(); LOG.error("Exception caught error running commands: " + e.getMessage()); } return new ProcessResult(stdOutput, stdError, retVal); }
From source file:org.atlasapi.media.entity.Broadcast.java
License:Apache License
public Broadcast(String broadcastOn, DateTime transmissionTime, Duration duration, Boolean activelyPublished) { this.broadcastOn = broadcastOn; this.transmissionTime = transmissionTime; this.transmissionEndTime = transmissionTime.plus(duration); this.broadcastDuration = (int) duration.getStandardSeconds(); this.activelyPublished = activelyPublished; }
From source file:org.atlasapi.media.entity.Version.java
License:Apache License
public void setDuration(Duration duration) { if (duration != null) { this.duration = (int) duration.getStandardSeconds(); } else {/*from www . j a v a 2 s . c om*/ this.duration = null; } }
From source file:org.atlasapi.remotesite.bbc.BbcProgrammeGraphExtractor.java
License:Apache License
public static void setDurations(Version version, IonVersion ionVersion) { if (ionVersion.getDuration() != null) { Duration duration = standardSeconds(ionVersion.getDuration()); version.setDuration(duration);//from ww w .j a va 2s . co m version.setPublishedDuration(Ints.saturatedCast(duration.getStandardSeconds())); } }
From source file:org.jadira.usertype.dateandtime.joda.columnmapper.IntegerColumnDurationMapper.java
License:Apache License
@Override public Integer toNonNullValue(Duration value) { long longValue = value.getStandardSeconds(); if (longValue < Integer.MIN_VALUE || longValue > Integer.MAX_VALUE) { throw new IllegalStateException(longValue + " cannot be cast to int without changing its value."); }// w ww .j av a 2 s . com return (int) longValue; }
From source file:org.jgrasstools.hortonmachine.modules.hydrogeomorphology.peakflow.core.discharge.QReal.java
License:Open Source License
/** * Calculate the discharge with rainfall data. *//* ww w . j a v a 2 s. co m*/ // public QReal( ParameterBox fixedParameters, double[][] iuhdata, double[][] jeffdata ) { // fixedParams = fixedParameters; // // jeff = jeffdata; // ampi = iuhdata; // // System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAA: ampilength " + ampi[ampi.length - 1][0]); // } /* * (non-Javadoc) * @see bsh.commands.h.peakflow.core.discharge.DischargeCalculator#calculateQ() */ public double[][] calculateQ() { double timestep = fixedParams.getTimestep(); double area_super = fixedParams.getArea(); double area_sub = fixedParams.getArea_sub(); double area_tot = 0f; double raintimestep = jeffC.getRain_timestep(); DateTime firstDate = jeffC.getFirstDate(); /* * The maximum rain time has no sense with the real precipitations. In this case it will use * the rain timestep for tp. */ double tcorr = ampi[ampi.length - 1][0]; tpmax = (double) raintimestep; int rainLength = jeff.size(); double[][] totalQshiftMatrix = new double[rainLength][(int) (Math.floor((tcorr + tpmax) / timestep) + 1 + rainLength * raintimestep / timestep)]; double[][] Q = new double[(int) Math.floor((tcorr + tpmax) / timestep) + 1][3]; if (area_sub != -9999.0) { area_tot = area_sub + area_super; } else { area_tot = area_super; } Set<DateTime> dates = jeff.keySet(); pm.beginTask("Calculating discharge...", dates.size()); int i = 0; for (DateTime dateTime : dates) { double J = jeff.get(dateTime); /* * calculate the discharge for t < tcorr */ int j = 0; for (int t = 1; t < tcorr; t += timestep) { j = (int) Math.floor((t) / timestep); if (t <= tpmax) { Q[j][0] = t; double widthInterpolate = ModelsEngine.width_interpolate(ampi, t, 0, 2); Q[j][1] = (double) (J * area_tot * widthInterpolate); Q[j][2] = Q[j - 1][2] + Q[j][1]; } else { Q[j][0] = t; Q[j][1] = (double) (J * area_tot * (ModelsEngine.width_interpolate(ampi, t, 0, 2) - ModelsEngine.width_interpolate(ampi, t - tpmax, 0, 2))); Q[j][2] = Q[j - 1][2] + Q[j][1]; } } /* * calculate the discharge for t > tcorr */ for (double t = tcorr; t < (tcorr + tpmax); t += timestep) { j = (int) Math.floor(((int) t) / timestep); Q[j][0] = t; Q[j][1] = (double) (J * area_tot * (ampi[ampi.length - 1][2] - ModelsEngine.width_interpolate(ampi, t - tpmax, 0, 2))); Q[j][2] = Q[j - 1][2] + Q[j][1]; } /* * calculate the volumes */ // double vol = Q[Q.length - 2][2] * timestep; // double vol2 = (double) (area_tot * J * raintimestep); /* * calculate zero padding before first value Note that jeff contains already the * progressive time of the rainfile. */ int totalshiftmatrixindex = 0; int initalshiftmatrixindex = 0; // FIXME time in ??? Duration duration = new Duration(firstDate, dateTime); long intervalSeconds = duration.getStandardSeconds(); int paddingnumber = (int) (intervalSeconds / timestep); for (int m = 0; m < paddingnumber; m++) { totalQshiftMatrix[i][m] = 0; totalshiftmatrixindex++; } initalshiftmatrixindex = totalshiftmatrixindex; for (int k = initalshiftmatrixindex; k < Q.length + initalshiftmatrixindex; k++) { totalQshiftMatrix[i][k] = Q[k - initalshiftmatrixindex][1]; totalshiftmatrixindex++; } for (int k = Q.length + totalshiftmatrixindex; k < totalQshiftMatrix[0].length; k++) { totalQshiftMatrix[i][k] = 0; } i++; pm.worked(1); } pm.done(); /* * sum the discharge contributes */ Qtot = new double[totalQshiftMatrix[0].length][2]; double tottime = 0f; for (int k = 0; k < Qtot.length; k++) { double sum = 0f; for (int j = 0; j < totalQshiftMatrix.length; j++) { sum = sum + totalQshiftMatrix[j][k]; } tottime = tottime + timestep; Qtot[k][1] = sum; Qtot[k][0] = tottime; } double total_vol = 0f; for (int k = 0; k < Qtot.length; k++) { total_vol = total_vol + Qtot[k][1]; } double total_rain = 0.0; for (DateTime dateTime : dates) { double J = jeff.get(dateTime); total_rain = total_rain + J; } total_rain = total_rain * area_tot * raintimestep; return Qtot; }
From source file:org.kuali.kpme.tklm.utils.TkTestUtils.java
License:Educational Community License
public static Map<DateTime, BigDecimal> getDateToHoursMap(TimeBlock timeBlock, TimeHourDetail timeHourDetail) { Map<DateTime, BigDecimal> dateToHoursMap = new HashMap<DateTime, BigDecimal>(); DateTime beginTime = timeBlock.getBeginDateTime(); DateTime endTime = timeBlock.getEndDateTime(); Days d = Days.daysBetween(beginTime, endTime); int numberOfDays = d.getDays(); if (numberOfDays < 1) { dateToHoursMap.put(timeBlock.getBeginDateTime(), timeHourDetail.getHours()); return dateToHoursMap; }/*from ww w . jav a 2 s. c om*/ DateTime currentTime = beginTime; for (int i = 0; i < numberOfDays; i++) { DateTime nextDayAtMidnight = currentTime.plusDays(1); nextDayAtMidnight = nextDayAtMidnight.hourOfDay().setCopy(12); nextDayAtMidnight = nextDayAtMidnight.minuteOfDay().setCopy(0); nextDayAtMidnight = nextDayAtMidnight.secondOfDay().setCopy(0); nextDayAtMidnight = nextDayAtMidnight.millisOfSecond().setCopy(0); Duration dur = new Duration(currentTime, nextDayAtMidnight); long duration = dur.getStandardSeconds(); BigDecimal hrs = new BigDecimal(duration / 3600, HrConstants.MATH_CONTEXT); dateToHoursMap.put(currentTime, hrs); currentTime = nextDayAtMidnight; } Duration dur = new Duration(currentTime, endTime); long duration = dur.getStandardSeconds(); BigDecimal hrs = new BigDecimal(duration / 3600, HrConstants.MATH_CONTEXT); dateToHoursMap.put(currentTime, hrs); return dateToHoursMap; }
From source file:org.numenta.nupic.encoders.DateEncoder.java
License:Open Source License
/** * Returns an {@link TDoubleList} containing the sub-field scalar value(s) for * each sub-field of the inputData. To get the associated field names for each of * the scalar values, call getScalarNames(). * * @param inputData the input value, in this case a date object * @return a list of one input double/*from ww w .j a v a 2 s. co m*/ */ public TDoubleList getScalars(DateTime inputData) { if (inputData == null) { throw new IllegalArgumentException("DateEncoder requires a valid Date object but got null"); } TDoubleList values = new TDoubleArrayList(); //Get the scalar values for each sub-field double timeOfDay = inputData.getHourOfDay() + inputData.getMinuteOfHour() / 60.0; // The day of week was 1 based, so convert to 0 based int dayOfWeek = inputData.getDayOfWeek() - 1; // + timeOfDay / 24.0 if (seasonEncoder != null) { // The day of year was 1 based, so convert to 0 based double dayOfYear = inputData.getDayOfYear() - 1; values.add(dayOfYear); } if (dayOfWeekEncoder != null) { values.add(dayOfWeek); } if (weekendEncoder != null) { //saturday, sunday or friday evening boolean isWeekend = dayOfWeek == 6 || dayOfWeek == 5 || (dayOfWeek == 4 && timeOfDay > 18); int weekend = isWeekend ? 1 : 0; values.add(weekend); } if (customDaysEncoder != null) { boolean isCustomDays = customDaysList.contains(dayOfWeek); int customDay = isCustomDays ? 1 : 0; values.add(customDay); } if (holidayEncoder != null) { // A "continuous" binary value. = 1 on the holiday itself and smooth ramp // 0->1 on the day before the holiday and 1->0 on the day after the holiday. double holidayness = 0; for (Tuple h : holidaysList) { //hdate is midnight on the holiday DateTime hdate = new DateTime(inputData.getYear(), (int) h.get(0), (int) h.get(1), 0, 0, 0); if (inputData.isAfter(hdate)) { Duration diff = new Interval(hdate, inputData).toDuration(); long days = diff.getStandardDays(); if (days == 0) { //return 1 on the holiday itself holidayness = 1; break; } else if (days == 1) { //ramp smoothly from 1 -> 0 on the next day holidayness = 1.0 - ((diff.getStandardSeconds() - 86400.0 * days) / 86400.0); break; } } else { //TODO This is not the same as when date.isAfter(hdate), why? Duration diff = new Interval(inputData, hdate).toDuration(); long days = diff.getStandardDays(); if (days == 0) { //ramp smoothly from 0 -> 1 on the previous day holidayness = 1.0 - ((diff.getStandardSeconds() - 86400.0 * days) / 86400.0); //TODO Why no break? } } } values.add(holidayness); } if (timeOfDayEncoder != null) { values.add(timeOfDay); } return values; }