Example usage for org.joda.time Weeks Weeks

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

Introduction

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

Prototype

private Weeks(int weeks) 

Source Link

Document

Creates a new instance representing a number of weeks.

Usage

From source file:au.edu.uq.cmm.paul.servlet.WebUIController.java

License:Open Source License

private Date determineCutoff(Model model, String olderThan, String age) {

    if (olderThan.isEmpty() && age.isEmpty()) {
        model.addAttribute("message", "Either an expiry date or an age must be supplied");
        return null;
    }/*from   w  ww  . j ava  2s  .c  o  m*/
    String[] parts = age.split("\\s", 2);
    DateTime cutoff;
    if (olderThan.isEmpty()) {
        int value;
        try {
            value = Integer.parseInt(parts[0]);
        } catch (NumberFormatException ex) {
            model.addAttribute("message", "Age quantity is not an integer");
            return null;
        }
        BaseSingleFieldPeriod p;
        switch (parts.length == 1 ? "" : parts[1]) {
        case "minute":
        case "minutes":
            p = Minutes.minutes(value);
            break;
        case "hour":
        case "hours":
            p = Hours.hours(value);
            break;
        case "day":
        case "days":
            p = Days.days(value);
            break;
        case "week":
        case "weeks":
            p = Weeks.weeks(value);
            break;
        case "month":
        case "months":
            p = Months.months(value);
            break;
        case "year":
        case "years":
            p = Years.years(value);
            break;
        default:
            model.addAttribute("message", "Unrecognized age time-unit");
            return null;
        }
        cutoff = DateTime.now().minus(p);
    } else {
        cutoff = parseTimestamp(olderThan);
        if (cutoff == null) {
            model.addAttribute("message", "Unrecognizable expiry date");
            return null;
        }
    }
    if (cutoff.isAfter(new DateTime())) {
        model.addAttribute("message", "Supplied or computed expiry date is in the future!");
        return null;
    }
    model.addAttribute("computedDate", FORMATS[0].print(cutoff));
    return cutoff.toDate();
}

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

License:Apache License

public static ReadablePeriod parsePeriodString(String periodStr) {
    ReadablePeriod period;//from ww w  .  j  a  va  2 s .c  om
    char periodUnit = periodStr.charAt(periodStr.length() - 1);
    if (periodUnit == 'n') {
        return null;
    }

    int periodInt = Integer.parseInt(periodStr.substring(0, periodStr.length() - 1));
    switch (periodUnit) {
    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:azkaban.reportal.util.Reportal.java

License:Apache License

public void updateSchedules(Reportal report, ScheduleManager scheduleManager, User user, Flow flow)
        throws ScheduleManagerException {
    // Clear previous schedules
    removeSchedules(scheduleManager);// w  ww . j  av a2  s.c om
    // Add new schedule
    if (schedule) {
        int hour = (Integer.parseInt(scheduleHour) % 12) + (scheduleAmPm.equalsIgnoreCase("pm") ? 12 : 0);
        int minute = Integer.parseInt(scheduleMinute) % 60;
        DateTimeZone timeZone = scheduleTimeZone.equalsIgnoreCase("UTC") ? DateTimeZone.UTC
                : DateTimeZone.getDefault();
        DateTime firstSchedTime = DateTimeFormat.forPattern("MM/dd/yyyy").withZone(timeZone)
                .parseDateTime(scheduleDate);
        firstSchedTime = firstSchedTime.withHourOfDay(hour).withMinuteOfHour(minute).withSecondOfMinute(0)
                .withMillisOfSecond(0);

        ReadablePeriod period = null;
        if (scheduleRepeat) {
            int intervalQuantity = Integer.parseInt(scheduleIntervalQuantity);

            if (scheduleInterval.equals("y")) {
                period = Years.years(intervalQuantity);
            } else if (scheduleInterval.equals("m")) {
                period = Months.months(intervalQuantity);
            } else if (scheduleInterval.equals("w")) {
                period = Weeks.weeks(intervalQuantity);
            } else if (scheduleInterval.equals("d")) {
                period = Days.days(intervalQuantity);
            } else if (scheduleInterval.equals("h")) {
                period = Hours.hours(intervalQuantity);
            } else if (scheduleInterval.equals("M")) {
                period = Minutes.minutes(intervalQuantity);
            }
        }

        ExecutionOptions options = new ExecutionOptions();
        options.getFlowParameters().put("reportal.execution.user", user.getUserId());
        options.getFlowParameters().put("reportal.title", report.title);
        options.getFlowParameters().put("reportal.render.results.as.html",
                report.renderResultsAsHtml ? "true" : "false");
        options.setMailCreator(ReportalMailCreator.REPORTAL_MAIL_CREATOR);

        scheduleManager.scheduleFlow(-1, project.getId(), project.getName(), flow.getId(), "ready",
                firstSchedTime.getMillis(), firstSchedTime.getZone(), period, DateTime.now().getMillis(),
                firstSchedTime.getMillis(), firstSchedTime.getMillis(), user.getUserId(), options, null);
    }
}

From source file:azkaban.utils.TimeUtils.java

License:Apache License

/**
 * Parse Period String to a ReadablePeriod Object
 *
 * @param periodStr string formatted period
 * @return ReadablePeriod Object//  w ww.j  a v  a 2  s . co m
 */
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;
    }

    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:azkaban.utils.Utils.java

License:Apache License

public static ReadablePeriod parsePeriodString(String periodStr) {
    ReadablePeriod period;//w  ww.  j a  v a  2  s . c o m
    char periodUnit = periodStr.charAt(periodStr.length() - 1);
    if (periodStr.equals("null") || periodUnit == 'n') {
        return null;
    }

    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.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;
    }//from   w ww . j  a v a 2s. c o  m

    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;
    }//  ww  w  . j  av  a2  s. com

    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;
}

From source file:com.mbc.jfin.schedule.impl.AbstractBaseScheduleGenerator.java

License:Open Source License

protected ReadablePeriod multiplyPeriod(ReadablePeriod frequency, int periodCount) throws ScheduleException {

    if (frequency instanceof Months) {
        return Months.months(frequency.getValue(0) * periodCount);
    } else if (frequency instanceof Days) {
        return Days.days(frequency.getValue(0) * periodCount);
    } else if (frequency instanceof Weeks) {
        return Weeks.weeks(frequency.getValue(0) * periodCount);
    } else if (frequency instanceof Years) {
        return Years.years(frequency.getValue(0) * periodCount);
    } else {//from  ww  w .ja v  a  2  s. c  om
        throw new ScheduleException("Unknown frequency type: " + frequency);
    }
}

From source file:com.ning.billing.util.clock.ClockMock.java

License:Apache License

public synchronized void addWeeks(final int weeks) {
    adjustTo(Weeks.weeks(weeks));
}

From source file:fi.hsl.parkandride.core.domain.prediction.AverageOfPreviousWeeksPredictor.java

License:EUPL

@Override
public List<Prediction> predict(PredictorState state, UtilizationHistory history, int maxCapacity) {
    Optional<Utilization> latest = history.getLatest();
    if (!latest.isPresent())
        return Collections.emptyList();
    DateTime now = state.latestUtilization = latest.get().timestamp;

    List<List<Prediction>> groupedByWeek = Stream.of(Weeks.weeks(1), Weeks.weeks(2), Weeks.weeks(3))
            .map(offset -> {//from  w  w w .  j  av a  2 s. co  m
                DateTime start = now.minus(offset);
                DateTime end = start.plus(PredictionRepository.PREDICTION_WINDOW);
                List<Utilization> utilizations = history.getRange(start, end);
                return utilizations.stream()
                        .map(u -> new Prediction(u.timestamp.plus(offset), u.spacesAvailable))
                        .collect(Collectors.toList());
            }).collect(Collectors.toList());

    List<List<Prediction>> groupedByTimeOfDay = ListUtil.transpose(groupedByWeek);

    return groupedByTimeOfDay.stream().map(this::reduce).collect(Collectors.toList());
}