Example usage for org.joda.time Minutes Minutes

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

Introduction

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

Prototype

private Minutes(int minutes) 

Source Link

Document

Creates a new instance representing a number of minutes.

Usage

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

License:Apache License

private ReadablePeriod parseDuration(String duration) {
    int hour = Integer.parseInt(duration.split(":")[0]);
    int min = Integer.parseInt(duration.split(":")[1]);
    return Minutes.minutes(min + hour * 60).toPeriod();
}

From source file:ch.eitchnet.android.mabea.MabeaParsing.java

License:Open Source License

public static Duration parseBalance(String value) throws MabeaParsingException {
    try {/*from   ww  w  .  j  av a  2  s . c o  m*/

        int posColon = value.indexOf(':');
        int posSpace = value.indexOf(' ');

        int hours = Integer.parseInt(value.substring(0, posColon));
        int minutes = Integer.parseInt(value.substring(posColon + 1, posSpace));
        if (hours < 0)
            minutes = -minutes;

        Duration duration = Hours.hours(hours).toStandardDuration();
        duration = duration.plus(Minutes.minutes((int) minutes).toStandardDuration());
        return duration;

    } catch (Exception e) {
        throw new MabeaParsingException("Balance can not be parsed from value " + value, e);
    }
}

From source file:ch.eitchnet.android.mabea.model.Setting.java

License:Open Source License

/**
 * Default constructor
 */
public Setting() {
    requiredWorkPerDay = Hours.EIGHT.toStandardDuration().plus(Minutes.minutes(30).toStandardDuration());
}

From source file:ch.oakmountain.tpa.solver.TrainPathAllocationProblemPruningParameters.java

License:Apache License

public TrainPathAllocationProblemPruningParameters(SimpleTrainPathApplication application) {
    this.simpleTrainPathApplication = application;
    HARD_MAXIMUM_EARLIER_DEPARTURE = Minutes.minutes(0).toStandardDuration();
    HARD_MINIMUM_DWELL_TIME = Minutes.minutes(0).toStandardDuration();
    HARD_MAXIMUM_LATER_ARRIVAL = Minutes.minutes(0).toStandardDuration();
}

From source file:ch.oakmountain.tpa.solver.TrainPathAllocationProblemPruningParameters.java

License:Apache License

public TrainPathAllocationProblemPruningParameters(SimpleTrainPathApplication application,
        int hardMaximumEarlierDeparture, int hardMinimumDwellTime, int hardMaximumLaterArrival) {
    this.simpleTrainPathApplication = application;
    HARD_MAXIMUM_EARLIER_DEPARTURE = Minutes.minutes(hardMaximumEarlierDeparture).toStandardDuration();
    HARD_MINIMUM_DWELL_TIME = Minutes.minutes(hardMinimumDwellTime).toStandardDuration();
    HARD_MAXIMUM_LATER_ARRIVAL = Minutes.minutes(hardMaximumLaterArrival).toStandardDuration();
    setMINIMUM_DWELL_TIME(Minutes.minutes(hardMinimumDwellTime).toStandardDuration());
}

From source file:ch.oakmountain.tpa.solver.TrainPathAllocationProblemPruningParameters.java

License:Apache License

public void relax(SimpleTrainPathApplication simpleTrainPathApplication, MacroscopicTopology topology) {
    // TODO not implemented yet
    List<List<SystemNode>> routes = topology.getRoutes(simpleTrainPathApplication.getFrom(),
            simpleTrainPathApplication.getTo());
    Set<SystemNode> nodes = new HashSet<>();
    for (List<SystemNode> route : routes) {
        for (SystemNode systemNode : route) {
            nodes.add(systemNode);/*ww  w  .ja v  a 2 s .c  o m*/
        }
    }
    for (SystemNode node : nodes) {
        setMAXIMUM_ADDITIONAL_DWELL_TIME(
                getMAXIMUM_ADDITIONAL_DWELL_TIME(node).plus(Minutes.minutes(10).toStandardDuration()));
    }

}

From source file:ch.oakmountain.tpa.solver.TrainPathAllocationProblemPruningParameters.java

License:Apache License

public void setDefaultPruning() {
    // set to applications hard bounds
    setMINIMUM_DWELL_TIME(getHARD_MINIMUM_DWELL_TIME());
    setMAXIMUM_EARLIER_DEPARTURE(getHARD_MAXIMUM_EARLIER_DEPARTURE());
    setMAXIMUM_LATER_ARRIVAL(getHARD_MAXIMUM_LATER_ARRIVAL());

    // set to arbitrary initial values
    // TODO command-line options for default pruning?
    setMAXIMUM_ADDITIONAL_DWELL_TIME(Minutes.minutes(15).toStandardDuration());
    Duration maxDuration = getApplicationHardMaxDuration();
    Duration anHour = Minutes.minutes(60).toStandardDuration();
    if (maxDuration.isShorterThan(anHour)) {
        setMAXIMUM_LATER_DEPARTURE(maxDuration);
        setMAXIMUM_EARLIER_ARRIVAL(maxDuration);
    } else {//from w w w  .  ja  va 2 s  . c o m
        setMAXIMUM_LATER_DEPARTURE(Minutes.minutes(60).toStandardDuration());
        setMAXIMUM_EARLIER_ARRIVAL(Minutes.minutes(60).toStandardDuration());
    }

    nonDefaultAddiontalDwellTimesMap.clear();
}

From source file:ch.oakmountain.tpa.solver.TrainPathSlotCatalogue.java

License:Apache License

public PeriodicalTrainPathSlot add(String trainPathSectionName, String name, LocalTime startTime,
        LocalTime endTime, SystemNode from, SystemNode to, Periodicity periodicity) {
    if (periodicalSlotMap.containsKey(name)) {
        throw new IllegalArgumentException("There is already a periodical train path slot of name " + name
                + " in this train path catalogue; found for " + trainPathSectionName);
    }//from  w ww.j a  v  a  2 s.c om
    PeriodicalTrainPathSlot slot = new PeriodicalTrainPathSlot(trainPathSectionName, name, startTime, endTime,
            from, to, periodicity);
    Pair<SystemNode, SystemNode> link = new Pair(from, to);
    if (!linkMap.containsKey(link)) {
        linkMap.put(link, new LinkedList<PeriodicalTrainPathSlot>());
    }
    if (linkMap.get(link).size() > 0) {
        //PeriodicalTrainPathSlot ps =
        for (PeriodicalTrainPathSlot ps : linkMap.get(link)) {
            if (ps.getPeriodicity().getWeekDays().size() > 0
                    && slot.getPeriodicity().getWeekDays().size() > 0) {
                TrainPathSlot referenceSlot = ps.getSlotOn(ps.getPeriodicity().getWeekDays().get(0));
                TrainPathSlot thisSlot = slot.getSlotOn(slot.getPeriodicity().getWeekDays().get(0));
                Duration referenceLb = referenceSlot.getDuration()
                        .minus(Minutes.minutes(10).toStandardDuration());
                Duration referenceUb = referenceSlot.getDuration()
                        .plus(Minutes.minutes(10).toStandardDuration());
                if (thisSlot.getDuration().isShorterThan(referenceLb)
                        || thisSlot.getDuration().isLongerThan(referenceUb)) {
                    throw new IllegalArgumentException("Slot " + thisSlot.getName() + " ("
                            + PeriodicalTimeFrame.formatDuration(thisSlot.getDuration())
                            + ") is more than 10 minutes shorter/longer than reference slot "
                            + referenceSlot.getName() + " ("
                            + PeriodicalTimeFrame.formatDuration(referenceSlot.getDuration()) + ").");
                }
            }
        }
    }
    linkMap.get(link).add(slot);
    periodicalSlotMap.put(name, slot);
    for (TrainPathSlot trainPathSlot : slot.getSlots()) {
        if (slotMap.containsKey(trainPathSlot.getName())) {
            throw new IllegalArgumentException("There is alreaday a train path slot of this name "
                    + trainPathSlot.getName() + " in this train path catalogue");
        }
        slotMap.put(trainPathSlot.getName(), trainPathSlot);
    }
    trainPathSlots.add(slot);
    if (!fromMap.containsKey(from)) {
        fromMap.put(from, new LinkedList<PeriodicalTrainPathSlot>());
    }
    fromMap.get(from).add(slot);
    if (!toMap.containsKey(to)) {
        toMap.put(to, new LinkedList<PeriodicalTrainPathSlot>());
    }
    toMap.get(to).add(slot);

    trainPathSectionNameMap.put(slot, trainPathSectionName);
    return slot;
}

From source file:com.cenrise.test.azkaban.Utils.java

License:Apache License

public static ReadablePeriod parsePeriodString(final String periodStr) {
    final ReadablePeriod period;
    final char periodUnit = periodStr.charAt(periodStr.length() - 1);
    if (periodStr.equals("null") || periodUnit == 'n') {
        return null;
    }/*  www .  j  a  va2s . c om*/

    final int periodInt = Integer.parseInt(periodStr.substring(0, periodStr.length() - 1));
    switch (periodUnit) {
    case 'y':
        period = Years.years(periodInt);
        break;
    case 'M':
        period = Months.months(periodInt);
        break;
    case 'w':
        period = Weeks.weeks(periodInt);
        break;
    case 'd':
        period = Days.days(periodInt);
        break;
    case 'h':
        period = Hours.hours(periodInt);
        break;
    case 'm':
        period = Minutes.minutes(periodInt);
        break;
    case 's':
        period = Seconds.seconds(periodInt);
        break;
    default:
        throw new IllegalArgumentException("Invalid schedule period unit '" + periodUnit);
    }

    return period;
}

From source file:com.effektif.workflow.api.model.AfterRelativeTime.java

License:Apache License

public LocalDateTime resolve(LocalDateTime base) {
    if (this.duration == null || this.durationUnit == null) {
        return null;
    }/*from w ww .j a  v  a 2 s  . c om*/

    ReadablePeriod period = null;
    if (DAYS.equals(durationUnit)) {
        period = Days.days(getDurationAsInt());
    } else if (WEEKS.equals(durationUnit)) {
        period = Weeks.weeks(getDurationAsInt());
    } else if (HOURS.equals(durationUnit)) {
        period = Hours.hours(getDurationAsInt());
    } else if (MONTHS.equals(durationUnit)) {
        period = Months.months(getDurationAsInt());
    } else if (YEARS.equals(durationUnit)) {
        period = Years.years(getDurationAsInt());
    } else if (MINUTES.equals(durationUnit)) {
        period = Minutes.minutes(getDurationAsInt());
    } else {
        return null;
    }

    LocalDateTime time = base.plus(period);

    if (atHour != null) {
        LocalDateTime atTime = time.withTime(atHour, atMinute != null ? atMinute : 0, 0, 0);
        if (atTime.isBefore(time)) {
            time = atTime.plusDays(1);
        } else {
            time = atTime;
        }
    } else if (isDayResolutionOrBigger()) {
        time = time.withTime(23, 59, 59, 999);
    }

    return time;
}