Example usage for org.joda.time Period Period

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

Introduction

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

Prototype

private Period(int[] values, PeriodType type) 

Source Link

Document

Constructor used when we trust ourselves.

Usage

From source file:net.longfalcon.view.DateView.java

License:Open Source License

public String timeAgo(Date date) {
    if (date != null) {
        Date now = new Date();
        Period period = new Period(date.getTime(), now.getTime());
        period = roundPeriod(period);/*from   w w w  .j a v a 2  s  .  c om*/

        return _periodFormatter.print(period);
    } else {
        return "never";
    }
}

From source file:net.mobid.codetraq.persistence.ServerRevision.java

License:Open Source License

/**
 * Calculates and returns the number of minutes since last monitor.
 * @return number of minutes elapsed since last monitor
 *//*from  w w w .  j  a  va 2 s .co  m*/
public int getMinutesSinceLastCheck() {
    if (getLastCheckedTimestamp() > 0) {
        Period p = new Period(getLastCheckedTimestamp(), System.currentTimeMillis());
        return p.getMinutes();
    }
    return Integer.MAX_VALUE;
}

From source file:net.sourceforge.fenixedu.domain.accounting.installments.InstallmentForFirstTimeStudents.java

License:Open Source License

private int getNumberOfMonthsToChargePenalty(final Event event, final DateTime when) {
    final int numberOfMonths = (new Period(getWhenStartToApplyPenalty(event, when), when.toDateMidnight())
            .getMonths() + 1);// w  ww .  j  a  v a2s. co  m
    return numberOfMonths < getMaxMonthsToApplyPenalty() ? numberOfMonths : getMaxMonthsToApplyPenalty();
}

From source file:net.sourceforge.fenixedu.domain.accounting.installments.InstallmentWithMonthlyPenalty.java

License:Open Source License

protected int getNumberOfMonthsToChargePenalty(DateTime when) {
    final int numberOfMonths = (new Period(getWhenStartToApplyPenalty().withDayOfMonth(1).toDateMidnight(),
            when.toDateMidnight()).getMonths() + 1);
    return numberOfMonths < getMaxMonthsToApplyPenalty() ? numberOfMonths : getMaxMonthsToApplyPenalty();
}

From source file:net.sourceforge.fenixedu.domain.candidacy.workflow.PrintUnder23TransportsDeclarationOperation.java

License:Open Source License

private boolean hasLessOr23Years(final Person person) {
    return new Period(person.getDateOfBirthYearMonthDay(), new LocalDate()).getYears() <= 23;
}

From source file:net.sourceforge.fenixedu.domain.GratuitySituation.java

License:Open Source License

private int calculateMonthsToChargePenalty(final YearMonthDay when) {

    final YearMonthDay endPaymentDate = getEndPaymentDate();
    final YearMonthDay endOfMonth = endPaymentDate.plusMonths(1).withDayOfMonth(1).minusDays(1);
    final int numberOfDaysLeftInMonth = new Period(endPaymentDate, endOfMonth).getDays();
    int monthsToChargePenalty = 0;

    if (numberOfDaysLeftInMonth > 0) {
        monthsToChargePenalty += 1;//from   w w w  . j a  v  a 2 s.c o m
    }

    final Period period = new Period(endPaymentDate.plusMonths(1).withDayOfMonth(1), when);
    monthsToChargePenalty += period.getMonths() + 1;

    return monthsToChargePenalty;
}

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());

                }//w ww.  j ava 2 s.  c  om
            }
        }
    }

    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:net.sourceforge.fenixedu.domain.serviceRequests.Under23TransportsDeclarationRequest.java

License:Open Source License

private void checkPersonAge(final Person person) {
    if (new Period(person.getDateOfBirthYearMonthDay(), new LocalDate()).getYears() > 23) {
        throw new DomainException("error.Under23TransportsDeclarationRequest.invalid.person.age");
    }/*w ww.  ja v a  2 s . c o m*/
}

From source file:nl.tricode.magnolia.events.field.DurationColumnFormatter.java

License:Open Source License

@Override
public Object generateCell(Table source, Object itemId, Object columnId) {
    final Item jcrItem = getJcrItem(source, itemId);
    if (jcrItem != null && jcrItem.isNode()) {
        final Node node = (Node) jcrItem;

        try {/*from   w  w w .  j ava2 s . co m*/
            if (NodeUtil.isNodeType(node, "mgnl:eventCalendarItem")) {
                final DateTime startDate = new DateTime(PropertyUtil.getDate(node, "startDate"));
                final DateTime endDate = new DateTime(PropertyUtil.getDate(node, "endDate"));

                if (startDate != null && endDate != null) {
                    PeriodFormatter formatter = new PeriodFormatterBuilder().appendMonths()
                            .appendSuffix(" month", " months").appendWeeks().appendSuffix(" week", " weeks")
                            .appendDays().appendSuffix(" day", " days").appendHours()
                            .appendSuffix(" hour", " hours").appendMinutes().appendSuffix(" minute", " minutes")
                            .appendSeconds().appendSuffix(" second", " seconds").toFormatter();
                    Period period = new Period(startDate, endDate);

                    String formatted = formatter.print(period);
                    return formatted;
                }
            }
        } catch (RepositoryException e) {
            log.warn("Unable to get duration based on startDate and endDate properties", e);
        }
    }
    return "N/A";
}

From source file:Objects.Game.java

public int getTimeSpent() {
    Period timeElapsed = new Period(this.startTime, new DateTime());
    return timeElapsed.getSeconds();
}