Example usage for org.joda.time Period getYears

List of usage examples for org.joda.time Period getYears

Introduction

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

Prototype

public int getYears() 

Source Link

Document

Gets the years field part of the period.

Usage

From source file:net.sourceforge.fenixedu.domain.reports.TeachersListFromGiafReportFile.java

License:Open Source License

private void listTeachers(Spreadsheet spreadsheet, final ExecutionYear executionYear) throws IOException {
    generateNameAndHeaders(spreadsheet, executionYear);
    for (final Teacher teacher : getRootDomainObject().getTeachersSet()) {
        PersonProfessionalData personProfessionalData = teacher.getPerson().getPersonProfessionalData();
        if (personProfessionalData != null) {
            GiafProfessionalData giafProfessionalData = personProfessionalData.getGiafProfessionalData();
            if (personProfessionalData != null && giafProfessionalData != null) {
                PersonContractSituation personContractSituation = personProfessionalData
                        .getCurrentOrLastPersonContractSituationByCategoryType(CategoryType.TEACHER,
                                executionYear.getBeginDateYearMonthDay().toLocalDate(),
                                executionYear.getEndDateYearMonthDay().toLocalDate());
                if (personContractSituation != null) {
                    Unit unit = teacher.getLastWorkingUnit(executionYear.getBeginDateYearMonthDay(),
                            executionYear.getEndDateYearMonthDay());
                    ProfessionalCategory professionalCategory = personProfessionalData
                            .getLastProfessionalCategoryByCategoryType(CategoryType.TEACHER,
                                    executionYear.getBeginDateYearMonthDay().toLocalDate(),
                                    executionYear.getEndDateYearMonthDay().toLocalDate());

                    ProfessionalRegime professionalRegime = personProfessionalData.getLastProfessionalRegime(
                            giafProfessionalData, executionYear.getBeginDateYearMonthDay().toLocalDate(),
                            executionYear.getEndDateYearMonthDay().toLocalDate());

                    ProfessionalRelation professionalRelation = personProfessionalData
                            .getLastProfessionalRelation(giafProfessionalData,
                                    executionYear.getBeginDateYearMonthDay().toLocalDate(),
                                    executionYear.getEndDateYearMonthDay().toLocalDate());

                    Double mandatoryLessonHours = teacher
                            .getMandatoryLessonHours(getLastSemester(personContractSituation, executionYear));

                    Period yearsInHouse = new Period(giafProfessionalData.getInstitutionEntryDate(),
                            (personContractSituation.getEndDate() == null ? new LocalDate()
                                    : personContractSituation.getEndDate()));

                    writePersonInformationRow(spreadsheet, executionYear, teacher, "CONTRATADO", unit,
                            professionalCategory, professionalRegime, professionalRelation,
                            personContractSituation.getBeginDate(), personContractSituation.getEndDate(),
                            mandatoryLessonHours, yearsInHouse.getYears());

                }//from ww w .j a v a2  s  .c  o  m
            }
        }
    }

    for (ExecutionSemester executionSemester : executionYear.getExecutionPeriodsSet()) {
        for (ExternalTeacherAuthorization externalTeacherAuthorization : ExternalTeacherAuthorization
                .getExternalTeacherAuthorizationSet(executionSemester)) {
            writePersonInformationRow(spreadsheet, executionYear, externalTeacherAuthorization.getTeacher(),
                    "AUTORIZADO", externalTeacherAuthorization.getDepartment().getDepartmentUnit(),
                    externalTeacherAuthorization.getProfessionalCategory(), null, null,
                    externalTeacherAuthorization.getExecutionSemester().getBeginDateYearMonthDay()
                            .toLocalDate(),
                    externalTeacherAuthorization.getExecutionSemester().getEndDateYearMonthDay().toLocalDate(),
                    externalTeacherAuthorization.getLessonHours(), null);

        }
    }
}

From source file:nz.co.gregs.dbvolution.databases.definitions.DBDefinition.java

License:Apache License

/**
 * Creates a string representation of a DateRepeat from the Period
 *
 * @param interval the interval to be transformed into a DateRepeat.
 * @return a DateRpeat as an SQL string/* w  w  w  . j  a  v a 2s  .co m*/
 */
public String transformPeriodIntoDateRepeat(Period interval) {
    StringBuilder str = new StringBuilder();
    str.append("'").append(DateRepeatExpression.INTERVAL_PREFIX);
    str.append(interval.getYears()).append(DateRepeatExpression.YEAR_SUFFIX);
    str.append(interval.getMonths()).append(DateRepeatExpression.MONTH_SUFFIX);
    str.append(interval.getDays() + (interval.getWeeks() * 7)).append(DateRepeatExpression.DAY_SUFFIX);
    str.append(interval.getHours()).append(DateRepeatExpression.HOUR_SUFFIX);
    str.append(interval.getMinutes()).append(DateRepeatExpression.MINUTE_SUFFIX);
    str.append(interval.getSeconds()).append(DateRepeatExpression.SECOND_SUFFIX);
    str.append("'");
    return str.toString();
}

From source file:nz.co.gregs.dbvolution.internal.datatypes.DateRepeatImpl.java

License:Apache License

/**
 *
 * @param interval/*from w  w  w  .  j  a va2s  .  c  om*/
 * @return the DateRepeat equivalent of the Period value
 */
public static String getDateRepeatString(Period interval) {
    if (interval == null) {
        return null;
    }
    int years = interval.getYears();
    int months = interval.getMonths();
    int days = interval.getDays() + interval.getWeeks() * 7;
    int hours = interval.getHours();
    int minutes = interval.getMinutes();

    int millis = interval.getMillis();
    double seconds = interval.getSeconds() + (millis / 1000.0);
    String intervalString = "P" + years + "Y" + months + "M" + days + "D" + hours + "h" + minutes + "n"
            + seconds + "s";
    return intervalString;
}

From source file:org.apache.arrow.vector.util.DateUtility.java

License:Apache License

public static int monthsFromPeriod(Period period) {
    return (period.getYears() * yearsToMonths) + period.getMonths();
}

From source file:org.apache.drill.exec.vector.DateUtilities.java

License:Apache License

public static int periodToMonths(Period value) {
    return value.getYears() * yearsToMonths + value.getMonths();
}

From source file:org.apache.drill.exec.vector.DateUtilities.java

License:Apache License

public static StringBuilder intervalYearStringBuilder(Period value) {
    return intervalYearStringBuilder(value.getYears() * 12 + value.getMonths());
}

From source file:org.apache.drill.exec.vector.DateUtilities.java

License:Apache License

public static StringBuilder intervalStringBuilder(Period value) {
    return intervalStringBuilder(value.getYears() * 12 + value.getMonths(), value.getDays(),
            periodToMillis(value));/*  w  w w  .ja  va  2s  .co  m*/
}

From source file:org.apigw.authserver.svc.impl.TokenServicesImpl.java

License:Open Source License

/**
 * @param residentIdentificationNumber in format yyyyMMddnnnn- for example 199212319876
 * @param validitySeconds - for example 43200  (60 * 60 * 12) - 12 hours in the future
 * @return// w ww  . ja v  a  2s . c  o  m
 */
protected Date generateExpirationTime(String residentIdentificationNumber, long validitySeconds) {
    if (residentIdentificationNumber == null || residentIdentificationNumber.length() < 8) {
        throw new IllegalArgumentException(
                "Invalid residentIdentificationNumber " + residentIdentificationNumber);
    }
    long validityMilliseconds = validitySeconds * 1000L;
    final String birthdayString = residentIdentificationNumber.substring(0, 8);
    final DateTime birthDate = DateTime.parse(birthdayString, ISODateTimeFormat.basicDate());
    Period period = new Period(birthDate, new DateTime(), PeriodType.yearMonthDay());
    DateTime birthDatePlusLegalGuardianAgeLimit = birthDate.plusYears(legalGuardianAgeLimit);
    DateTime residentAdultDate = birthDate.plusYears(adultAge);
    DateTime expiration = new DateTime().withTimeAtStartOfDay(); //defaulting to midnight of today (token will be immediately invalid)
    if (validitySeconds > 0) {
        // Standard expiration
        final DateTime standardExpiration = new DateTime().plus(validityMilliseconds);
        if (birthDatePlusLegalGuardianAgeLimit.isAfter(now().plus(validityMilliseconds))) { // resident will hit the legal guardian age after max token validity
            expiration = standardExpiration;
        } else if (residentAdultDate.isBeforeNow()) { // resident is considered adult
            expiration = standardExpiration;
        } else if (birthDatePlusLegalGuardianAgeLimit.isAfterNow()) { //resident will hit the legal guardian age before max token validity
            expiration = birthDatePlusLegalGuardianAgeLimit;
        }
        // if we get here resident has passed legal guardian age but is not considered adult, using default
    }
    log.debug("calculated token exp time for resident who is ~ {} years, {} months and {} days old to {}",
            period.getYears(), period.getMonths(), period.getDays(), expiration);
    return expiration.toDate();
}

From source file:org.dungeon.io.SavesTableWriter.java

License:Open Source License

private static String makePeriodString(long start, long end) {
    Period period = new Period(start, end);
    TimeStringBuilder builder = new TimeStringBuilder();
    builder.set(EarthTimeUnit.YEAR, period.getYears());
    builder.set(EarthTimeUnit.MONTH, period.getMonths());
    builder.set(EarthTimeUnit.DAY, period.getDays());
    builder.set(EarthTimeUnit.HOUR, period.getHours());
    builder.set(EarthTimeUnit.MINUTE, period.getMinutes());
    builder.set(EarthTimeUnit.SECOND, period.getSeconds());
    return builder.toString(2) + " ago";
}

From source file:org.eclim.plugin.core.command.history.HistoryListCommand.java

License:Open Source License

private String delta(long time) {
    // FIXME: a formatter can probably do this.
    Period period = new Period(time, System.currentTimeMillis());
    ArrayList<String> parts = new ArrayList<String>();

    int years = period.getYears();
    if (years > 0) {
        parts.add(years + " year" + (years == 1 ? "" : "s"));
    }/*from  w  ww . j a v  a 2  s  .  c  o  m*/

    int months = period.getMonths();
    if (months > 0) {
        parts.add(months + " month" + (months == 1 ? "" : "s"));
    }

    int weeks = period.getWeeks();
    if (weeks > 0) {
        parts.add(weeks + " week" + (weeks == 1 ? "" : "s"));
    }

    int days = period.getDays();
    if (days > 0) {
        parts.add(days + " day" + (days == 1 ? "" : "s"));
    }

    int hours = period.getHours();
    if (hours > 0) {
        parts.add(hours + " hour" + (hours == 1 ? "" : "s"));
    }

    int minutes = period.getMinutes();
    if (minutes > 0) {
        parts.add(minutes + " minute" + (minutes == 1 ? "" : "s"));
    }

    int seconds = period.getSeconds();
    if (seconds > 0) {
        parts.add(seconds + " second" + (seconds == 1 ? "" : "s"));
    }

    if (parts.size() == 0) {
        int millis = period.getMillis();
        if (millis > 0) {
            parts.add(millis + " millis");
        }
    }

    return StringUtils.join(parts.toArray(), ' ') + " ago";
}