Example usage for org.joda.time DateTime plus

List of usage examples for org.joda.time DateTime plus

Introduction

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

Prototype

public DateTime plus(ReadablePeriod period) 

Source Link

Document

Returns a copy of this datetime with the specified period added.

Usage

From source file:aDeleteME.DeleteME.java

public static void main(String[] args) {
    Random random = new Random();

    DateTime startTime = new DateTime(random.nextLong()).withMillisOfSecond(0);

    Minutes minimumPeriod = Minutes.TWO;
    int minimumPeriodInSeconds = minimumPeriod.toStandardSeconds().getSeconds();
    int maximumPeriodInSeconds = Hours.ONE.toStandardSeconds().getSeconds();

    Seconds randomPeriod = Seconds.seconds(random.nextInt(maximumPeriodInSeconds - minimumPeriodInSeconds));
    DateTime endTime = startTime.plus(minimumPeriod).plus(randomPeriod);

    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");

    System.out.println(dateTimeFormatter.print(startTime));
    System.out.println(dateTimeFormatter.print(endTime));
}

From source file:aplicacion.control.util.Fechas.java

public static String differenceBetweenHours(Time time1, Time time2) {
    DateTime dateTime1 = new DateTime(time1.getTime());
    dateTime1 = dateTime1.plus(1);
    DateTime dateTime2 = new DateTime(time2.getTime());
    dateTime2 = dateTime2.plus(1);/*from  www.  ja  v a2s .  c  o m*/
    long c = dateTime2.getMillis() - dateTime1.getMillis();
    DateTime dateTime = new DateTime(c);
    dateTime = dateTime.plusHours(4);
    Time diff = new Time(dateTime.getMillis());
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
    return formatter.format(getLocalFromTime(diff));
}

From source file:au.id.hazelwood.xmltvguidebuilder.model.ProgrammeDetail.java

License:Apache License

public ProgrammeDetail(DateTime startDate, Minutes duration, String title, EpisodeDetail episodeDetail,
        List<String> categories, String rating) {
    Assert.notNull(startDate, "StartDate is required");
    Assert.notNull(duration, "Duration is required");
    this.startDate = startDate;
    this.duration = duration;
    this.endDate = startDate.plus(duration);
    this.title = title;
    this.episodeDetail = episodeDetail;
    this.categories = Collections.unmodifiableList(categories);
    this.rating = rating;
}

From source file:azkaban.app.Scheduler.java

License:Apache License

private DateTime updatedTime(DateTime scheduledDate, ReadablePeriod period) {
    DateTime now = new DateTime();
    DateTime date = new DateTime(scheduledDate);
    int count = 0;
    while (now.isAfter(date)) {
        if (count > 100000) {
            throw new IllegalStateException("100000 increments of period did not get to present time.");
        }/*from   w ww .j  a v a 2s  .c  om*/

        if (period == null) {
            break;
        } else {
            date = date.plus(period);
        }

        count += 1;
    }

    return date;
}

From source file:azkaban.migration.scheduler.Schedule.java

License:Apache License

private DateTime getNextRuntime(long scheduleTime, DateTimeZone timezone, ReadablePeriod period) {
    DateTime now = new DateTime();
    DateTime date = new DateTime(scheduleTime).withZone(timezone);
    int count = 0;
    while (!now.isBefore(date)) {
        if (count > 100000) {
            throw new IllegalStateException("100000 increments of period did not get to present time.");
        }//from  w ww  .  ja  va  2  s . c om

        if (period == null) {
            break;
        } else {
            date = date.plus(period);
        }

        count += 1;
    }

    return date;
}

From source file:azkaban.scheduler.ScheduledJob.java

License:Apache License

/**
 * Calculates the next runtime by adding the period.
 * // ww  w .  ja  va 2  s  .  co m
 * @param scheduledDate
 * @param period
 * @return
 */
private DateTime getNextRuntime(DateTime scheduledDate, ReadablePeriod period) {
    DateTime now = new DateTime();
    DateTime date = new DateTime(scheduledDate);
    int count = 0;
    while (!now.isBefore(date)) {
        if (count > 100000) {
            throw new IllegalStateException("100000 increments of period did not get to present time.");
        }

        if (period == null) {
            break;
        } else {
            date = date.plus(period);
        }

        count += 1;
    }

    return date;
}

From source file:azkaban.trigger.builtin.BasicTimeChecker.java

License:Apache License

private long calculateNextCheckTime() {
    DateTime date = new DateTime(nextCheckTime).withZone(timezone);
    int count = 0;
    while (!date.isAfterNow()) {
        if (count > 100000) {
            throw new IllegalStateException("100000 increments of period did not get to present time.");
        }/*from   w  ww  . j  a va  2 s .  com*/
        if (period == null) {
            break;
        } else {
            date = date.plus(period);
        }
        count += 1;
        if (!skipPastChecks) {
            continue;
        }
    }
    return date.getMillis();
}

From source file:azkaban.trigger.builtin.SlaChecker.java

License:Apache License

private Boolean isSlaMissed(ExecutableFlow flow) {
    String type = slaOption.getType();
    logger.info("flow is " + flow.getStatus());
    if (flow.getStartTime() < 0) {
        return Boolean.FALSE;
    }//from   www. j  a  v  a  2  s.c o  m
    Status status;
    if (type.equals(SlaOption.TYPE_FLOW_FINISH)) {
        if (checkTime < flow.getStartTime()) {
            ReadablePeriod duration = Utils
                    .parsePeriodString((String) slaOption.getInfo().get(SlaOption.INFO_DURATION));
            DateTime startTime = new DateTime(flow.getStartTime());
            DateTime nextCheckTime = startTime.plus(duration);
            this.checkTime = nextCheckTime.getMillis();
        }
        status = flow.getStatus();
        if (checkTime < DateTime.now().getMillis()) {
            return !isFlowFinished(status);
        }
    } else if (type.equals(SlaOption.TYPE_FLOW_SUCCEED)) {
        if (checkTime < flow.getStartTime()) {
            ReadablePeriod duration = Utils
                    .parsePeriodString((String) slaOption.getInfo().get(SlaOption.INFO_DURATION));
            DateTime startTime = new DateTime(flow.getStartTime());
            DateTime nextCheckTime = startTime.plus(duration);
            this.checkTime = nextCheckTime.getMillis();
        }
        status = flow.getStatus();
        if (checkTime < DateTime.now().getMillis()) {
            return !isFlowSucceeded(status);
        } else {
            return status.equals(Status.FAILED) || status.equals(Status.KILLED);
        }
    } else if (type.equals(SlaOption.TYPE_JOB_FINISH)) {
        String jobName = (String) slaOption.getInfo().get(SlaOption.INFO_JOB_NAME);
        ExecutableNode node = flow.getExecutableNode(jobName);
        if (node.getStartTime() < 0) {
            return Boolean.FALSE;
        }
        if (checkTime < node.getStartTime()) {
            ReadablePeriod duration = Utils
                    .parsePeriodString((String) slaOption.getInfo().get(SlaOption.INFO_DURATION));
            DateTime startTime = new DateTime(node.getStartTime());
            DateTime nextCheckTime = startTime.plus(duration);
            this.checkTime = nextCheckTime.getMillis();
        }
        status = node.getStatus();
        if (checkTime < DateTime.now().getMillis()) {
            return !isJobFinished(status);
        }
    } else if (type.equals(SlaOption.TYPE_JOB_SUCCEED)) {
        String jobName = (String) slaOption.getInfo().get(SlaOption.INFO_JOB_NAME);
        ExecutableNode node = flow.getExecutableNode(jobName);
        if (node.getStartTime() < 0) {
            return Boolean.FALSE;
        }
        if (checkTime < node.getStartTime()) {
            ReadablePeriod duration = Utils
                    .parsePeriodString((String) slaOption.getInfo().get(SlaOption.INFO_DURATION));
            DateTime startTime = new DateTime(node.getStartTime());
            DateTime nextCheckTime = startTime.plus(duration);
            this.checkTime = nextCheckTime.getMillis();
        }
        status = node.getStatus();
        if (checkTime < DateTime.now().getMillis()) {
            return !isJobFinished(status);
        } else {
            return status.equals(Status.FAILED) || status.equals(Status.KILLED);
        }
    }
    return Boolean.FALSE;
}

From source file:azkaban.trigger.builtin.SlaChecker.java

License:Apache License

private Boolean isSlaGood(ExecutableFlow flow) {
    String type = slaOption.getType();
    logger.info("flow is " + flow.getStatus());
    if (flow.getStartTime() < 0) {
        return Boolean.FALSE;
    }//ww w .  j a  v a 2  s .c  o  m
    Status status;
    if (type.equals(SlaOption.TYPE_FLOW_FINISH)) {
        if (checkTime < flow.getStartTime()) {
            ReadablePeriod duration = Utils
                    .parsePeriodString((String) slaOption.getInfo().get(SlaOption.INFO_DURATION));
            DateTime startTime = new DateTime(flow.getStartTime());
            DateTime nextCheckTime = startTime.plus(duration);
            this.checkTime = nextCheckTime.getMillis();
        }
        status = flow.getStatus();
        return isFlowFinished(status);
    } else if (type.equals(SlaOption.TYPE_FLOW_SUCCEED)) {
        if (checkTime < flow.getStartTime()) {
            ReadablePeriod duration = Utils
                    .parsePeriodString((String) slaOption.getInfo().get(SlaOption.INFO_DURATION));
            DateTime startTime = new DateTime(flow.getStartTime());
            DateTime nextCheckTime = startTime.plus(duration);
            this.checkTime = nextCheckTime.getMillis();
        }
        status = flow.getStatus();
        return isFlowSucceeded(status);
    } else if (type.equals(SlaOption.TYPE_JOB_FINISH)) {
        String jobName = (String) slaOption.getInfo().get(SlaOption.INFO_JOB_NAME);
        ExecutableNode node = flow.getExecutableNode(jobName);
        if (node.getStartTime() < 0) {
            return Boolean.FALSE;
        }
        if (checkTime < node.getStartTime()) {
            ReadablePeriod duration = Utils
                    .parsePeriodString((String) slaOption.getInfo().get(SlaOption.INFO_DURATION));
            DateTime startTime = new DateTime(node.getStartTime());
            DateTime nextCheckTime = startTime.plus(duration);
            this.checkTime = nextCheckTime.getMillis();
        }
        status = node.getStatus();
        return isJobFinished(status);
    } else if (type.equals(SlaOption.TYPE_JOB_SUCCEED)) {
        String jobName = (String) slaOption.getInfo().get(SlaOption.INFO_JOB_NAME);
        ExecutableNode node = flow.getExecutableNode(jobName);
        if (node.getStartTime() < 0) {
            return Boolean.FALSE;
        }
        if (checkTime < node.getStartTime()) {
            ReadablePeriod duration = Utils
                    .parsePeriodString((String) slaOption.getInfo().get(SlaOption.INFO_DURATION));
            DateTime startTime = new DateTime(node.getStartTime());
            DateTime nextCheckTime = startTime.plus(duration);
            this.checkTime = nextCheckTime.getMillis();
        }
        status = node.getStatus();
        return isJobSucceeded(status);
    }
    return Boolean.FALSE;
}

From source file:azkaban.webapp.servlet.ScheduleServlet.java

License:Apache License

private void writeScheduleData(List<HashMap<String, Object>> output, Schedule schedule)
        throws ScheduleManagerException {
    Map<String, Object> stats = SchedulerStatistics.getStatistics(schedule.getScheduleId(),
            (AzkabanWebServer) getApplication());
    HashMap<String, Object> data = new HashMap<String, Object>();
    data.put("scheduleid", schedule.getScheduleId());
    data.put("flowname", schedule.getFlowName());
    data.put("projectname", schedule.getProjectName());
    data.put("time", schedule.getFirstSchedTime());

    DateTime time = DateTime.now();
    long period = 0;
    if (schedule.getPeriod() != null) {
        period = time.plus(schedule.getPeriod()).getMillis() - time.getMillis();
    }//from w w  w  .j a  va2s  .c o m
    data.put("period", period);
    int length = 3600 * 1000;
    if (stats.get("average") != null && stats.get("average") instanceof Integer) {
        length = (int) (Integer) stats.get("average");
        if (length == 0) {
            length = 3600 * 1000;
        }
    }
    data.put("length", length);
    data.put("history", false);
    data.put("stats", stats);
    output.add(data);
}