List of usage examples for org.joda.time Duration getMillis
public long getMillis()
From source file:au.id.hazelwood.xmltvguidebuilder.postprocessor.ListingVerifier.java
License:Apache License
public void verifyListing(ChannelListings listings, DateTime from, DateTime to, DateTime subsetTo) { Duration listingDurationTotal = new Interval(from, to).toDuration(); Duration listingDurationSubset = new Interval(from, subsetTo).toDuration(); LOGGER.info(repeat("-", 100)); for (ChannelDetail channelDetail : listings.getChannels()) { Duration missingDurationTotal = Duration.ZERO; Duration missingDurationSubset = Duration.ZERO; StringBuilder allMissingIntervalDetails = new StringBuilder(); for (Interval missing : findMissingIntervals(listings, from, to, channelDetail.getId())) { missingDurationTotal = missingDurationTotal.plus(missing.toDuration()); if (missing.getStart().isBefore(subsetTo)) { if (missing.getEnd().isBefore(subsetTo)) { missingDurationSubset = missingDurationSubset.plus(missing.toDuration()); } else { missingDurationSubset = missingDurationSubset .plus(new Duration(missing.getStart(), subsetTo)); }/*from w ww. j av a2 s . c o m*/ } allMissingIntervalDetails.append(allMissingIntervalDetails.length() == 0 ? "missing " : ", "); allMissingIntervalDetails.append( format("{0}-{1}", toISODateTime(missing.getStart()), toISODateTime(missing.getEnd()))); } Duration availableDurationTotal = listingDurationTotal.minus(missingDurationTotal); Duration availableDurationSubset = listingDurationSubset.minus(missingDurationSubset); Integer availablePercentageTotal = getPercentage(availableDurationTotal, listingDurationTotal); Integer availablePercentageSubset = getPercentage(availableDurationSubset, listingDurationSubset); LOGGER.info("{} {} [{}|{}] {}", rightPad(channelDetail.getId() + " - " + channelDetail.getName(), 42), formatDurationDHM(availableDurationTotal.getMillis()), leftPad(availablePercentageSubset + "%", 4), leftPad(availablePercentageTotal + "%", 4), allMissingIntervalDetails.toString()); } LOGGER.info(repeat("-", 100)); }
From source file:au.id.hazelwood.xmltvguidebuilder.postprocessor.ListingVerifier.java
License:Apache License
private int getPercentage(Duration available, Duration total) { return round(available.getMillis() * 100F / total.getMillis()); }
From source file:azkaban.app.Scheduler.java
License:Apache License
private ScheduledFuture<?> schedule(final ScheduledJob schedJob, boolean saveResults) { // fail fast if there is a problem with this job _jobManager.validateJob(schedJob.getId()); Duration wait = new Duration(new DateTime(), schedJob.getScheduledExecution()); if (wait.getMillis() < -1000) { logger.warn("Job " + schedJob.getId() + " is scheduled for " + DateTimeFormat.shortDateTime().print(schedJob.getScheduledExecution()) + " which is " + (PeriodFormat.getDefault().print(wait.toPeriod())) + " in the past, adjusting scheduled date to now."); wait = new Duration(0); }//from w w w .ja va2 s.c om // mark the job as scheduled _scheduled.put(schedJob.getId(), schedJob); if (saveResults) { try { saveSchedule(); } catch (IOException e) { throw new RuntimeException("Error saving schedule after scheduling job " + schedJob.getId()); } } ScheduledRunnable runnable = new ScheduledRunnable(schedJob); schedJob.setScheduledRunnable(runnable); return _executor.schedule(runnable, wait.getMillis(), TimeUnit.MILLISECONDS); }
From source file:br.com.anteros.persistence.metadata.converter.converters.JodaDurationConverter.java
License:Apache License
public Long convertToDatabaseColumn(Duration duration) { return duration.getMillis(); }
From source file:ch.eitchnet.android.util.JodaHelper.java
License:Open Source License
public static String toHourMinute(Duration duration) { PeriodFormatterBuilder builder = new PeriodFormatterBuilder(); builder.printZeroAlways();//w w w.j ava2 s . c o m if (duration.isShorterThan(Duration.ZERO)) builder.appendLiteral("-"); builder.minimumPrintedDigits(2).appendHours().appendLiteral(":").minimumPrintedDigits(2).appendMinutes(); return builder.toFormatter().print(new Period(Math.abs(duration.getMillis()))); }
From source file:ch.oakmountain.tpa.solver.PeriodicalTimeFrame.java
License:Apache License
public static String formatDuration(Duration d) { if (d == null) { return ""; }/* w w w .j a va2 s . c om*/ long millis = d.getMillis(); return String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis), TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))); //return "" + String.format("%02d", t.getHourOfDay()) + ":" + String.format("%02d", t.getMinuteOfHour()) + ":" + String.format("%02d", t.getSecondOfMinute()); }
From source file:ch.oakmountain.tpa.solver.SolutionCandidate.java
License:Apache License
/** * Returns the duration in milliseconds from the start of the first of the first slot to the end of the last slot. * * @return//from w ww .j a v a2 s .c o m */ public long getDuration() { Duration duration = getEndTime().distanceAfter(getStartTime()); if (duration.getMillis() < 0) { throw new IllegalStateException("Request " + getTrainPathApplication().getName() + ": duration must not be negative for path " + describeFullPath()); } return duration.getMillis(); }
From source file:ch.oakmountain.tpa.solver.TrainPathAllocationProblemModel.java
License:Apache License
protected long getDuration(TrainPathSlot slot) { Duration duration = slot.getEndTime().distanceAfter(slot.getStartTime()); return duration.getMillis(); }
From source file:ch.oakmountain.tpa.solver.TrainPathAllocationProblemPruningParameters.java
License:Apache License
public void setMAXIMUM_ADDITIONAL_DWELL_TIME(Duration MAXIMUM_ADDITIONAL_DWELL_TIME) { if (MAXIMUM_ADDITIONAL_DWELL_TIME.getMillis() < 0) { throw new IllegalArgumentException("Duration must not be < 0"); }/*from w ww. j a va2 s . c o m*/ this.MAXIMUM_ADDITIONAL_DWELL_TIME = MAXIMUM_ADDITIONAL_DWELL_TIME; }
From source file:ch.oakmountain.tpa.solver.TrainPathAllocationProblemPruningParameters.java
License:Apache License
public void setMAXIMUM_ADDITIONAL_DWELL_TIME(SystemNode node, Duration MAXIMUM_ADDITIONAL_DWELL_TIME) { if (MAXIMUM_ADDITIONAL_DWELL_TIME.getMillis() < 0) { throw new IllegalArgumentException("Duration must not be < 0"); }//from w ww. j a v a 2s. c o m nonDefaultAddiontalDwellTimesMap.put(node, MAXIMUM_ADDITIONAL_DWELL_TIME); }