Example usage for org.joda.time Years Years

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

Introduction

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

Prototype

private Years(int years) 

Source Link

Document

Creates a new instance representing a number of years.

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;
    }//w ww  . j  a v  a 2  s . 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.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);// ww  w.  jav a2  s . c  o m
    // 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 w w .  j  av  a  2s . 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  w w .ja v a 2  s  .  com
    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  ava2  s  .  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;
    }/*from  w w  w  .  j  a  va2 s  . c  o m*/

    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 {//www . j a va 2 s .co m
        throw new ScheduleException("Unknown frequency type: " + frequency);
    }
}

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

License:Apache License

public synchronized void addYears(final int years) {
    adjustTo(Years.years(years));
}

From source file:griffon.plugins.jodatime.editors.YearsPropertyEditor.java

License:Apache License

private Years parse(Number number) {
    return Years.years(abs(number.intValue()));
}

From source file:griffon.plugins.jodatime.JodatimeExtension.java

License:Apache License

public static Years toYears(Number number) {
    return Years.years(abs(number.intValue()));
}