Example usage for org.joda.time Years yearsBetween

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

Introduction

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

Prototype

public static Years yearsBetween(ReadablePartial start, ReadablePartial end) 

Source Link

Document

Creates a Years representing the number of whole years between the two specified partial datetimes.

Usage

From source file:com.ligadata.kamanja.copd.COPDRiskAssessment.java

License:Apache License

private Boolean age40OrOlder() {
    org.joda.time.LocalDate birthdate = new org.joda.time.LocalDate(msg.bene_birth_dt() / 10000,
            (msg.bene_birth_dt() % 1000) / 100, msg.bene_birth_dt() % 100);
    Integer age = Years.yearsBetween(birthdate, new LocalDate()).getYears();
    if (age > 40) {
        return true;
    }/*from  w  ww. j a  va2 s .c  om*/
    return false;
}

From source file:com.netsteadfast.greenstep.bsc.action.KpiPeriodTrendsQueryAction.java

License:Apache License

private void checkDateRange(String p) throws ControllerException, Exception {
    String frequency = this.getFields().get("frequency" + p);
    String startDate = this.defaultString(this.getFields().get("startDate" + p)).replaceAll("/", "-");
    String endDate = this.defaultString(this.getFields().get("endDate" + p)).replaceAll("/", "-");
    String startYearDate = this.defaultString(this.getFields().get("startYearDate" + p)).replaceAll("/", "-");
    String endYearDate = this.defaultString(this.getFields().get("endYearDate" + p)).replaceAll("/", "-");
    if (BscMeasureDataFrequency.FREQUENCY_DAY.equals(frequency)
            || BscMeasureDataFrequency.FREQUENCY_WEEK.equals(frequency)
            || BscMeasureDataFrequency.FREQUENCY_MONTH.equals(frequency)) {
        DateTime dt1 = new DateTime(startDate);
        DateTime dt2 = new DateTime(endDate);
        int betweenMonths = Months.monthsBetween(dt1, dt2).getMonths();
        if (betweenMonths >= 12) {
            super.throwMessage("startDate" + p + "|" + "endDate" + p,
                    this.getText("MESSAGE.BSC_PROG003D0007Q_contentQuery_msg11"));
        }/*from  ww  w .  ja va  2 s. co  m*/
        return;
    }
    DateTime dt1 = new DateTime(startYearDate + "-01-01");
    DateTime dt2 = new DateTime(endYearDate + "-01-01");
    int betweenYears = Years.yearsBetween(dt1, dt2).getYears();
    if (BscMeasureDataFrequency.FREQUENCY_QUARTER.equals(frequency)) {
        if (betweenYears >= 3) {
            super.throwMessage("startYearDate" + p + "|" + "endYearDate" + p,
                    this.getText("MESSAGE.BSC_PROG003D0007Q_contentQuery_msg12"));
        }
    }
    if (BscMeasureDataFrequency.FREQUENCY_HALF_OF_YEAR.equals(frequency)) {
        if (betweenYears >= 4) {
            super.throwMessage("startYearDate" + p + "|" + "endYearDate" + p,
                    this.getText("MESSAGE.BSC_PROG003D0007Q_contentQuery_msg13"));
        }
    }
    if (BscMeasureDataFrequency.FREQUENCY_YEAR.equals(frequency)) {
        if (betweenYears >= 6) {
            super.throwMessage("startYearDate" + p + "|" + "endYearDate" + p,
                    this.getText("MESSAGE.BSC_PROG003D0007Q_contentQuery_msg14"));
        }
    }
}

From source file:com.netsteadfast.greenstep.bsc.action.KpiReportContentQueryAction.java

License:Apache License

private void checkDateRange() throws ControllerException, Exception {
    String frequency = this.getFields().get("frequency");
    String startDate = this.defaultString(this.getFields().get("startDate")).replaceAll("/", "-");
    String endDate = this.defaultString(this.getFields().get("endDate")).replaceAll("/", "-");
    String startYearDate = this.defaultString(this.getFields().get("startYearDate")).replaceAll("/", "-");
    String endYearDate = this.defaultString(this.getFields().get("endYearDate")).replaceAll("/", "-");
    if (BscMeasureDataFrequency.FREQUENCY_DAY.equals(frequency)
            || BscMeasureDataFrequency.FREQUENCY_WEEK.equals(frequency)
            || BscMeasureDataFrequency.FREQUENCY_MONTH.equals(frequency)) {
        DateTime dt1 = new DateTime(startDate);
        DateTime dt2 = new DateTime(endDate);
        int betweenMonths = Months.monthsBetween(dt1, dt2).getMonths();
        if (betweenMonths >= 12) {
            super.throwMessage("startDate|endDate",
                    this.getText("MESSAGE.BSC_PROG003D0001Q_contentQuery_msg11"));
        }//from www.  j  a  v a  2 s  .c om
        return;
    }
    DateTime dt1 = new DateTime(startYearDate + "-01-01");
    DateTime dt2 = new DateTime(endYearDate + "-01-01");
    int betweenYears = Years.yearsBetween(dt1, dt2).getYears();
    if (BscMeasureDataFrequency.FREQUENCY_QUARTER.equals(frequency)) {
        if (betweenYears >= 3) {
            super.throwMessage("startYearDate|endYearDate",
                    this.getText("MESSAGE.BSC_PROG003D0001Q_contentQuery_msg12"));
        }
    }
    if (BscMeasureDataFrequency.FREQUENCY_HALF_OF_YEAR.equals(frequency)) {
        if (betweenYears >= 4) {
            super.throwMessage("startYearDate|endYearDate",
                    this.getText("MESSAGE.BSC_PROG003D0001Q_contentQuery_msg13"));
        }
    }
    if (BscMeasureDataFrequency.FREQUENCY_YEAR.equals(frequency)) {
        if (betweenYears >= 6) {
            super.throwMessage("startYearDate|endYearDate",
                    this.getText("MESSAGE.BSC_PROG003D0001Q_contentQuery_msg14"));
        }
    }
}

From source file:com.netsteadfast.greenstep.bsc.action.TsaQueryForecastAction.java

License:Apache License

private void checkDateRange() throws ControllerException, Exception {
    String frequency = this.getFields().get("frequency");
    String startDate = this.defaultString(this.getFields().get("startDate")).replaceAll("/", "-");
    String endDate = this.defaultString(this.getFields().get("endDate")).replaceAll("/", "-");
    String startYearDate = this.defaultString(this.getFields().get("startYearDate")).replaceAll("/", "-");
    String endYearDate = this.defaultString(this.getFields().get("endYearDate")).replaceAll("/", "-");
    if (BscMeasureDataFrequency.FREQUENCY_DAY.equals(frequency)
            || BscMeasureDataFrequency.FREQUENCY_WEEK.equals(frequency)
            || BscMeasureDataFrequency.FREQUENCY_MONTH.equals(frequency)) {
        DateTime dt1 = new DateTime(startDate);
        DateTime dt2 = new DateTime(endDate);
        int betweenMonths = Months.monthsBetween(dt1, dt2).getMonths();
        if (betweenMonths >= 12) {
            super.throwMessage("startDate|endDate", "Date range can not be more than 12 months!");
        }/* w  w  w.  j ava 2 s.c  o m*/
        return;
    }
    DateTime dt1 = new DateTime(startYearDate + "-01-01");
    DateTime dt2 = new DateTime(endYearDate + "-01-01");
    int betweenYears = Years.yearsBetween(dt1, dt2).getYears();
    if (BscMeasureDataFrequency.FREQUENCY_QUARTER.equals(frequency)) {
        if (betweenYears >= 3) {
            super.throwMessage("startYearDate|endYearDate", "Date range can not be more than 3 years!");
        }
    }
    if (BscMeasureDataFrequency.FREQUENCY_HALF_OF_YEAR.equals(frequency)) {
        if (betweenYears >= 4) {
            super.throwMessage("startYearDate|endYearDate", "Date range can not be more than 4 years!");
        }
    }
    if (BscMeasureDataFrequency.FREQUENCY_YEAR.equals(frequency)) {
        if (betweenYears >= 6) {
            super.throwMessage("startYearDate|endYearDate", "Date range can not be more than 6 years!");
        }
    }
}

From source file:com.netsteadfast.greenstep.bsc.mobile.action.ScorecardQueryContentAction.java

License:Apache License

private void checkDateRange() throws ControllerException, Exception {
    String date1 = "";
    String date2 = "";
    String ver = super.defaultString(this.getFields().get("ver"));
    if (!"newVer".equals(ver)) {
        // mm/dd/yyyy to yyyy/mm/dd
        String date1Tmp[] = super.defaultString(this.getFields().get("date1")).split("/");
        String date2Tmp[] = super.defaultString(this.getFields().get("date2")).split("/");
        if (date1Tmp == null || date1Tmp.length != 3 || date2Tmp == null || date2Tmp.length != 3) {
            throw new ControllerException(this.getText("MESSAGE.ScorecardQueryContentAction_01"));
        }/*from ww  w  .ja  va  2s.  c  o m*/
        date1 = date1Tmp[2] + "/" + date1Tmp[0] + "/" + date1Tmp[1];
        date2 = date2Tmp[2] + "/" + date2Tmp[0] + "/" + date2Tmp[1];
        if (!SimpleUtils.isDate(date1) || !SimpleUtils.isDate(date2)) {
            throw new ControllerException(this.getText("MESSAGE.ScorecardQueryContentAction_01"));
        }
    } else {
        // NEW version page ? , yyyy/MM/dd
        date1 = StringUtils.defaultString(this.getFields().get("date1")).replaceAll("-", "/");
        date2 = StringUtils.defaultString(this.getFields().get("date2")).replaceAll("-", "/");
        if (!SimpleUtils.isDate(date1) || !SimpleUtils.isDate(date2)) {
            throw new ControllerException(this.getText("MESSAGE.ScorecardQueryContentAction_01"));
        }
        if (Integer.parseInt(date1.replaceAll("-", "").replaceAll("/", "")) > Integer
                .parseInt(date2.replaceAll("-", "").replaceAll("/", ""))) {
            throw new ControllerException("Date range: " + date1 + " to " + date2 + " error!");
        }
    }

    this.getFields().put("startDate", date1);
    this.getFields().put("endDate", date2);

    // copy from KpiReportContentQueryAction.java
    String frequency = this.getFields().get("frequency");
    String startDate = this.defaultString(this.getFields().get("startDate")).replaceAll("/", "-");
    String endDate = this.defaultString(this.getFields().get("endDate")).replaceAll("/", "-");
    if (BscMeasureDataFrequency.FREQUENCY_DAY.equals(frequency)
            || BscMeasureDataFrequency.FREQUENCY_WEEK.equals(frequency)
            || BscMeasureDataFrequency.FREQUENCY_MONTH.equals(frequency)) {
        DateTime dt1 = new DateTime(startDate);
        DateTime dt2 = new DateTime(endDate);
        int betweenMonths = Months.monthsBetween(dt1, dt2).getMonths();
        if (betweenMonths >= 12) {
            throw new ControllerException(this.getText("MESSAGE.ScorecardQueryContentAction_02"));
        }
        return;
    }
    DateTime dt1 = new DateTime(startDate.substring(0, 4) + "-01-01");
    DateTime dt2 = new DateTime(endDate.substring(0, 4) + "-01-01");
    int betweenYears = Years.yearsBetween(dt1, dt2).getYears();
    if (BscMeasureDataFrequency.FREQUENCY_QUARTER.equals(frequency)) {
        if (betweenYears >= 3) {
            throw new ControllerException(this.getText("MESSAGE.ScorecardQueryContentAction_03"));
        }
    }
    if (BscMeasureDataFrequency.FREQUENCY_HALF_OF_YEAR.equals(frequency)) {
        if (betweenYears >= 4) {
            throw new ControllerException(this.getText("MESSAGE.ScorecardQueryContentAction_04"));
        }
    }
    if (BscMeasureDataFrequency.FREQUENCY_YEAR.equals(frequency)) {
        if (betweenYears >= 6) {
            throw new ControllerException(this.getText("MESSAGE.ScorecardQueryContentAction_05"));
        }
    }
}

From source file:com.netsteadfast.greenstep.bsc.support.ScoreCalculationCallable.java

License:Apache License

private List<String> getDateRange(String frequency, String date1, String date2) throws Exception {
    List<String> dateRange = new LinkedList<String>();
    if (BscMeasureDataFrequency.FREQUENCY_DAY.equals(frequency)
            || BscMeasureDataFrequency.FREQUENCY_WEEK.equals(frequency)
            || BscMeasureDataFrequency.FREQUENCY_MONTH.equals(frequency)) {
        DateTime dt1 = new DateTime(date1.replaceAll("/", "-").substring(0, date1.length() - 2) + "01");
        DateTime dt2 = new DateTime(date2.replaceAll("/", "-").substring(0, date2.length() - 2) + "01");
        int betweenMonths = Months.monthsBetween(dt1, dt2).getMonths();
        Date nowDate = dt1.toDate();
        for (int i = 0; i <= betweenMonths; i++) {
            dateRange.add(SimpleUtils.getStrYMD(nowDate, "/").substring(0, 7));
            nowDate = DateUtils.addMonths(nowDate, 1);
        }/*  w w w  .  j  a v  a2s  .c  o  m*/
        return dateRange;
    }
    if (BscMeasureDataFrequency.FREQUENCY_QUARTER.equals(frequency)) {
        DateTime dt1 = new DateTime(date1 + "-01-01");
        DateTime dt2 = new DateTime(date2 + "-01-01");
        int betweenYears = Years.yearsBetween(dt1, dt2).getYears();
        Date nowDate = dt1.toDate();
        for (int i = 0; i <= betweenYears; i++) {
            String yyyy = SimpleUtils.getStrYMD(nowDate, "/").substring(0, 4);
            dateRange.add(yyyy + "/" + AggregationMethod.QUARTER_1);
            dateRange.add(yyyy + "/" + AggregationMethod.QUARTER_2);
            dateRange.add(yyyy + "/" + AggregationMethod.QUARTER_3);
            dateRange.add(yyyy + "/" + AggregationMethod.QUARTER_4);
            nowDate = DateUtils.addYears(nowDate, 1);
        }
        return dateRange;
    }
    if (BscMeasureDataFrequency.FREQUENCY_HALF_OF_YEAR.equals(frequency)) {
        DateTime dt1 = new DateTime(date1 + "-01-01");
        DateTime dt2 = new DateTime(date2 + "-01-01");
        int betweenYears = Years.yearsBetween(dt1, dt2).getYears();
        Date nowDate = dt1.toDate();
        for (int i = 0; i <= betweenYears; i++) {
            String yyyy = SimpleUtils.getStrYMD(nowDate, "/").substring(0, 4);
            dateRange.add(yyyy + "/" + AggregationMethod.HALF_YEAR_FIRST);
            dateRange.add(yyyy + "/" + AggregationMethod.HALF_YEAR_LAST);
            nowDate = DateUtils.addYears(nowDate, 1);
        }
        return dateRange;
    }
    int begYear = Integer.parseInt(date1.substring(0, 4));
    int endYear = Integer.parseInt(date2.substring(0, 4));
    for (int i = begYear; i <= endYear; i++) {
        dateRange.add(String.valueOf(i));
    }
    return dateRange;
}

From source file:com.netsteadfast.greenstep.util.SimpleUtils.java

License:Apache License

public static int getYearsBetween(String startDate, String endDate) {
    DateTime s = new DateTime(
            startDate.length() == 4 ? startDate + "-01-01" : getStrYMD(startDate.replaceAll("/", "-"), "-"));
    DateTime e = new DateTime(
            endDate.length() == 4 ? endDate + "-01-01" : getStrYMD(endDate.replaceAll("/", "-"), "-"));
    return Years.yearsBetween(s, e).getYears();
}

From source file:com.pfm.utils.recuringPayments.RecuringPaymentsOverviewManager.java

public static Integer getPeriodsInInterval(Integer recuringType, Date startDate, Date endDate) {
    Integer periods = 0;//from   w w  w . j  av  a 2s . c o m
    DateTime start = new DateTime(startDate);
    DateTime end = new DateTime(endDate);
    if (Objects.equals(recuringType, RecurringTypes.Daily.getValue())) {
        periods = Days.daysBetween(start, end).getDays();
    }

    if (Objects.equals(recuringType, RecurringTypes.Weekly.getValue())) {
        periods = Weeks.weeksBetween(start, end).getWeeks();
    }

    if (Objects.equals(recuringType, RecurringTypes.Monthly.getValue())) {
        periods = Months.monthsBetween(start, end).getMonths();
    }

    if (Objects.equals(recuringType, RecurringTypes.Yearly.getValue())) {
        periods = Years.yearsBetween(start, end).getYears();
    }

    return periods;
}

From source file:com.qnoid.java.tRm1.dont.Person.java

License:Creative Commons License

public Person(byte[] name, Calendar dob) throws UnsupportedEncodingException {
    this.name = new String(name, "UTF-8");
    this.age = Years.yearsBetween(new DateTime(Calendar.getInstance()), new DateTime(dob)).getYears();
}

From source file:com.qnoid.java.tRm1.Persons.java

License:Creative Commons License

public static Person valueOf(byte[] itsName, Calendar dob) throws UnsupportedEncodingException {
    String name = new String(itsName, "UTF-8");
    int age = Years.yearsBetween(new DateTime(Calendar.getInstance()), new DateTime(dob)).getYears();

    return new Person(name, age);
}