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

public Period(Object period, PeriodType type, Chronology chrono) 

Source Link

Document

Creates a period by converting or copying from another object.

Usage

From source file:au.org.theark.study.service.StudyServiceImpl.java

License:Open Source License

private String calculatePedigreeAge(Date birthDate, Date selectDate) {
    String age = null;/*from   w  ww . j a  v a  2 s.  co  m*/
    LocalDate oldDate = null;
    LocalDate newDate = null;

    oldDate = new LocalDate(birthDate);

    if (selectDate != null) {
        newDate = new LocalDate(selectDate);
    } else {
        newDate = new LocalDate();
    }

    Period period = new Period(oldDate, newDate, PeriodType.yearMonthDay());
    int years = period.getYears();
    age = "" + (years < 1 ? "&lt;1" : years);

    return age;
}

From source file:br.edu.utfpr.cm.JGitMinerWeb.services.matrix.AgeRepositoryServices.java

@Override
public void run() {
    System.out.println(params);//from  w  w w  .j a  va 2s  .c om
    if (getRepositorys().get(0) == null) {
        throw new IllegalArgumentException("Parmetro Repository no pode ser nulo.");
    }

    String jpql = "SELECT r " + "FROM " + "EntityRepository r " + "WHERE " + "r = :repo";
    String[] bdParams = new String[] { "repo" };

    Object[] bdObjects = new Object[] { getRepositorys().get(0) };

    List<EntityRepository> repository = dao.selectWithParams(jpql, bdParams, bdObjects);

    System.out.println(repository.size());
    System.out.println(repository);
    EntityMatrix matrix = new EntityMatrix();
    for (EntityRepository r : repository) {
        DateTime dateRepository = new DateTime(r.getCreatedAt());
        Period period = new Period(dateRepository, new DateTime(), PeriodType.months().withDaysRemoved());
        matrix.getNodes().add(new EntityMatrixNode(period.getMonths()));
    }
    matricesToSave.add(matrix);
}

From source file:br.edu.utfpr.cm.JGitMinerWeb.services.matrix.FiltersServices.java

private int findAgeRepository(EntityRepository repository) {
    DateTime dateRepository = new DateTime(repository.getCreatedAt());
    Period period = new Period(dateRepository, new DateTime(), PeriodType.months().withDaysRemoved());
    return period.getMonths();
}

From source file:ca.phon.session.impl.ParticipantImpl.java

License:Open Source License

@Override
public Period getAge(DateTime fromDate) {
    // return forced age
    if (age != null || fromDate == null) {
        return age;
    } else {//  www. j a v  a  2s.  co  m
        final DateTime start = getBirthDate();
        final DateTime end = fromDate;

        final Period period = new Period(start, end, PeriodType.yearMonthDay());
        return period;
    }
}

From source file:co.edu.uelbosque.sistemas.swiii.c3.historiaclinica.entities.Medico.java

private void setNacimiento(Calendar nacimiento) {
    Calendar ahora = Calendar.getInstance();
    long hoy = ahora.getTimeInMillis();
    long dias = hoy - nacimiento.getTimeInMillis();
    Duration d = new Duration(dias);
    this.dias = (int) d.getStandardDays();
    Period period = new Period(nacimiento.getTimeInMillis(), hoy, PeriodType.months());
    this.meses = period.getMonths();
    this.nacimiento = nacimiento;
}

From source file:com.atlassian.theplugin.jira.model.ActiveJiraIssueBean.java

License:Apache License

public long recalculateTimeSpent() {
    DateTime now = new DateTime();
    if (!paused) {
        Period nextPeriod = new Period(lastStartTime, now, PeriodType.seconds());
        secondsSpent = secondsSpent + nextPeriod.getSeconds();
    }// ww  w .  j a  v a2 s . c o m
    lastStartTime = now;
    return secondsSpent;
}

From source file:com.c2a.vie.managedbeans.deces.ContratgroupeManagedBean.java

public int ageassure() {
    Calendar calendar = new GregorianCalendar();
    LocalDate aujourdui = new LocalDate();
    calendar.setTime(selectassurepret.getDatnaisassure());
    int annee = calendar.get(Calendar.YEAR);
    int mois = calendar.get(Calendar.MONTH);
    int jours = calendar.get(Calendar.DAY_OF_MONTH);
    LocalDate naissance = new LocalDate(annee, mois, jours);
    Period p = new Period(naissance, aujourdui, PeriodType.yearMonthDay());
    return p.getYears();
}

From source file:com.c2a.vie.managedbeans.deces.ContratgroupeManagedBean.java

public int ageassureren() {
    Calendar calendar = new GregorianCalendar();
    LocalDate aujourdui = new LocalDate();
    calendar.setTime(selectrnouvelmentcontrat.getCodassure().getDatnaisassure());
    int annee = calendar.get(Calendar.YEAR);
    int mois = calendar.get(Calendar.MONTH);
    int jours = calendar.get(Calendar.DAY_OF_MONTH);
    LocalDate naissance = new LocalDate(annee, mois, jours);
    Period p = new Period(naissance, aujourdui, PeriodType.yearMonthDay());
    return p.getYears();
}

From source file:com.facebook.util.TimeIntervalType.java

License:Apache License

/**
 * Gets the start instant given the event instant, interval length 
 * and the time zone for this interval type.
 * /*from w w w  .ja  v a  2s  . co m*/
 * @param instant the event time instant.
 * @param length the interval length
 * 
 * @return the start instant of the interval of given length that contains 
 * the supplied time instant in the supplied time zone 
 */
public DateTime getTimeIntervalStart(DateTime instant, long length) {
    validateValue(instant.getZone(), length);
    // Get the time in the specified timezone
    DateTime periodStart = instant;
    // Clear all the fields for this intervalType and its subtypes
    TimeIntervalType timeIntervalType = this;
    while (timeIntervalType != null) {
        periodStart = timeIntervalType.clearField(periodStart);
        timeIntervalType = timeIntervalType.subType;
    }
    // figure out the which time interval does the instant lie in
    Period period = new Period(periodStart, instant, periodType);
    DurationField durationField = fieldType.getField(instant.getChronology()).getDurationField();
    int diff = period.get(durationField.getType());
    long startDelta = (diff / length) * length;
    return periodStart.withFieldAdded(durationField.getType(), FieldUtils.safeToInt(startDelta));
}

From source file:com.google.livingstories.server.util.TimeUtil.java

License:Apache License

/**
 * Return a String representation of the time that has passed from the given time to
 * right now.//from   w w w.  j a  v a2s . c o  m
 * This method returns an approximate user-friendly duration. Eg. If 2 months, 12 days and 4 hours
 * have passed, the method will return "2 months ago".
 * TODO: the results of this method need to be internationalized
 */
public static String getElapsedTimeString(Date updateCreationTime) {
    Period period = new Period(updateCreationTime.getTime(), new Date().getTime(),
            PeriodType.yearMonthDayTime());

    int years = period.getYears();
    int months = period.getMonths();
    int days = period.getDays();
    int hours = period.getHours();
    int minutes = period.getMinutes();
    int seconds = period.getSeconds();

    String timeLabel = "";

    if (years > 0) {
        timeLabel = years == 1 ? " year " : " years ";
        return "" + years + timeLabel + "ago";
    } else if (months > 0) {
        timeLabel = months == 1 ? " month " : " months ";
        return "" + months + timeLabel + "ago";
    } else if (days > 0) {
        timeLabel = days == 1 ? " day " : " days ";
        return "" + days + timeLabel + "ago";
    } else if (hours > 0) {
        timeLabel = hours == 1 ? " hour " : " hours ";
        return "" + hours + timeLabel + "ago";
    } else if (minutes > 0) {
        timeLabel = minutes == 1 ? " minute " : " minutes ";
        return "" + minutes + timeLabel + "ago";
    } else if (seconds > 0) {
        timeLabel = seconds == 1 ? " second " : " seconds ";
        return "" + seconds + timeLabel + "ago";
    } else {
        return "1 second ago";
    }
}