Example usage for org.joda.time Interval Interval

List of usage examples for org.joda.time Interval Interval

Introduction

In this page you can find the example usage for org.joda.time Interval Interval.

Prototype

public Interval(Object interval, Chronology chronology) 

Source Link

Document

Constructs a time interval by converting or copying from another object, overriding the chronology.

Usage

From source file:com.peertopark.java.dates.Intervals.java

License:Apache License

public static Interval getInterval(long fromDate, long untilDate) {
    return new Interval(fromDate, untilDate);
}

From source file:com.pinterest.teletraan.worker.AutoPromoter.java

License:Apache License

public PromoteResult computePromoteBuildResult(EnvironBean currEnvBean, DeployBean currDeployBean, int size,
        PromoteBean promoteBean) throws Exception {

    Preconditions.checkArgument(size > 0);

    // Figure out the current deploy build publish date, we only consider build after this date
    long startTime = 0;
    if (currDeployBean != null) {
        BuildBean buildBean = buildDAO.getById(currDeployBean.getBuild_id());
        startTime = buildBean.getPublish_date();
    }/*w  ww.  j a  va  2  s . c  o m*/

    long endTime = getEndTime(promoteBean);

    if (endTime < startTime) {
        return new PromoteResult().withResultCode(PromoteResult.ResultCode.NoAvailableBuild);
    }

    //Get builds available between the deployed build and end time ordered by publish_date
    //It is either Long.MAX_VALUE (Get all builds) or the due time for scheduled deployment
    List<BuildBean> buildBeans = getBuildCandidates(currEnvBean, new Interval(startTime, endTime),
            maxCheckBuildsOrDeploys);
    if (buildBeans.size() < size) {
        return new PromoteResult().withResultCode(PromoteResult.ResultCode.NoAvailableBuild);
    }

    String schedule = promoteBean.getSchedule();
    if (!StringUtils.isEmpty(schedule)) {
        Function<BuildBean, Long> getPublishDate = b -> b.getPublish_date();
        BuildBean toPromoteBuild = getScheduledCheckResult(currEnvBean, promoteBean, buildBeans,
                getPublishDate);

        if (toPromoteBuild != null) {
            return new PromoteResult().withResultCode(PromoteResult.ResultCode.PromoteBuild)
                    .withBuild(toPromoteBuild.getBuild_id());

        } else {
            return new PromoteResult().withResultCode(PromoteResult.ResultCode.NoAvailableBuild);
        }

    } else {
        //No delay. Just promote it
        return new PromoteResult().withBuild(buildBeans.get(size - 1).getBuild_id())
                .withResultCode(PromoteResult.ResultCode.PromoteBuild);
    }

}

From source file:com.pinterest.teletraan.worker.AutoPromoter.java

License:Apache License

public PromoteResult computePromoteDeployResult(EnvironBean currEnvBean, DeployBean currDeployBean, int size,
        PromoteBean promoteBean) throws Exception {
    String precededStage = promoteBean.getPred_stage();
    // Special case when there is no preceded environment
    EnvironBean precededEnvBean = environDAO.getByStage(currEnvBean.getEnv_name(), precededStage);
    if (precededEnvBean == null) {
        LOG.warn("Pred env {}/{} does not exist, bail out!", currEnvBean.getEnv_name(), precededStage);
        return new PromoteResult().withResultCode(PromoteResult.ResultCode.NoPredEnvironment);
    }/*w w w  .j  a v a  2 s.com*/

    String predDeployId = precededEnvBean.getDeploy_id();
    if (predDeployId == null) {
        LOG.debug("Pred env {}/{} does not have deploy yet, bail out!", currEnvBean.getEnv_name(),
                precededStage);
        return new PromoteResult().withResultCode(PromoteResult.ResultCode.NoPredEnvironmentDeploy);
    }

    //Get the start time to find a deploy in preceded environment. If current deploy is promoted
    //from preceded environment, use the last promoted deploy startDate in preceded
    // environment.
    //Otherwise (current deploy is not promoted from preceded environment), use the current
    // deploy
    // startDate
    long startTime = getCurrentDeployStartDate(currDeployBean, precededEnvBean, currEnvBean);

    long endTime = getEndTime(promoteBean);
    if (endTime < startTime) {
        return new PromoteResult().withResultCode(PromoteResult.ResultCode.NoCandidateWithinDelayPeriod);
    }

    //Get all deploys in preceded environment order by start dese
    List<DeployBean> deployCandidates = getDeployCandidates(precededEnvBean.getEnv_id(),
            new Interval(startTime, endTime), maxCheckBuildsOrDeploys);

    if (deployCandidates.size() < size) {
        return new PromoteResult().withResultCode(PromoteResult.ResultCode.NoCandidateWithinDelayPeriod);
    }
    String schedule = promoteBean.getSchedule();
    if (!StringUtils.isEmpty(schedule)) {
        Function<DeployBean, Long> getSucceedDate = b -> b.getStart_date();
        DeployBean toPromoteDeploy = getScheduledCheckResult(currEnvBean, promoteBean, deployCandidates,
                getSucceedDate);

        if (toPromoteDeploy != null) {
            return new PromoteResult().withResultCode(PromoteResult.ResultCode.PromoteDeploy)
                    .withPredDeployBean(toPromoteDeploy, precededEnvBean);

        } else {
            return new PromoteResult()
                    .withResultCode(PromoteResult.ResultCode.NoRegularDeployWithinDelayPeriod);
        }

    } else {
        return new PromoteResult().withResultCode(PromoteResult.ResultCode.PromoteDeploy)
                .withPredDeployBean(deployCandidates.get(size - 1), precededEnvBean);
    }

}

From source file:com.pokescanner.objects.Pokemons.java

License:Open Source License

public MarkerOptions getMarker(Context context, int scale) {
    String uri = "p" + getNumber();
    int resourceID = context.getResources().getIdentifier(uri, "drawable", context.getPackageName());

    Interval interval;//ww w.  java 2 s.co m
    //Find our interval
    interval = new Interval(new Instant(), getDate());
    //turn our interval into MM:SS
    DateTime dt = new DateTime(interval.toDurationMillis());
    DateTimeFormatter fmt = DateTimeFormat.forPattern("mm:ss");
    String timeOut = fmt.print(dt);
    //set our location
    LatLng position = new LatLng(getLatitude(), getLongitude());

    Bitmap out = DrawableUtils.writeTextOnDrawable(resourceID, timeOut, scale, context);

    String name = getName();
    name = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();

    MarkerOptions pokeIcon = new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(out))
            .position(position).title(name).snippet(timeOut);

    return pokeIcon;
}

From source file:com.qcadoo.commons.dateTime.TimeRange.java

License:Open Source License

public Interval toInterval(final LocalDate date) {
    DateTime start = date.toDateTime(getFrom());
    DateTime end = date.toDateTime(getTo());
    if (startsDayBefore()) {
        end = end.plusDays(1);/*w  ww .  j  a  va  2  s  . c  o m*/
    }
    return new Interval(start, end);
}

From source file:com.qcadoo.mes.deviationCausesReporting.DeviationsReportCriteria.java

License:Open Source License

private static DeviationsReportCriteria fromLocalDates(final LocalDate fromDate,
        final Optional<LocalDate> maybeToDate) {
    DateTime rangeBegin = fromDate.toDateTimeAtStartOfDay();
    DateTime rangeEnd = maybeToDate.or(LocalDate.now()).plusDays(1).toDateTimeAtStartOfDay().minusMillis(1);
    Preconditions.checkArgument(rangeBegin.isBefore(rangeEnd), "Passed dates have wrong order.");
    Interval searchInterval = new Interval(rangeBegin, rangeEnd);
    return new DeviationsReportCriteria(searchInterval);
}

From source file:com.qcadoo.mes.productionPerShift.DateTimeRange.java

License:Open Source License

public DateTimeRange(final DateTime from, final DateTime to) {
    Preconditions.checkArgument(from != null, "Missing lower bound for date range.");
    Preconditions.checkArgument(to != null, "Missing upper bound for date range.");
    interval = new Interval(from, to);
}

From source file:com.qcadoo.mes.productionPerShift.DateTimeRange.java

License:Open Source License

public DateTimeRange(final Date from, final Date to) {
    Preconditions.checkArgument(from != null, "Missing lower bound for date range.");
    Preconditions.checkArgument(to != null, "Missing upper bound for date range.");
    DateTime fromDT = new DateTime(from);
    DateTime toDT = new DateTime(to);
    interval = new Interval(fromDT, toDT);
}

From source file:com.qcadoo.mes.productionPerShift.DateTimeRange.java

License:Open Source License

public DateTimeRange(final DateTime day, final TimeRange range) {
    DateTime from;// ww  w  .j a  v a 2  s .c o m
    DateTime to;
    if (range.startsDayBefore()) {
        to = range.getTo().toDateTime(day.plusDays(1));
    } else {
        to = range.getTo().toDateTime(day);
    }
    from = range.getFrom().toDateTime(day);
    interval = new Interval(from, to);
}

From source file:com.qcadoo.mes.productionPerShift.DateTimeRange.java

License:Open Source License

public DateTimeRange unionWith(DateTimeRange other) {
    Interval otherInterval = other.interval;
    DateTime start = interval.getStart().isBefore(otherInterval.getStart()) ? interval.getStart()
            : otherInterval.getStart();/*from  w w w  .j a  v a  2  s .c  o  m*/
    DateTime end = interval.getEnd().isAfter(otherInterval.getEnd()) ? interval.getEnd()
            : otherInterval.getEnd();
    Interval unionInterval = new Interval(start, end);

    return new DateTimeRange(unionInterval);
}