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:org.cyrusbuilt.guncabinet.dao.events.TableUpdateFinishedEventArgs.java

License:Open Source License

/**
 * Initializes a new instance of the {@link org.cyrusbuilt.guncabinet.dao.events.TableUpdateFinishedEventArgs}
 * class with the start time, the table that was updated, and the ID of the
 * record that was the subject of the update.
 * @param start The time the table update started.
 * @param table The table that was updated.
 * @param recordId The ID of the record that was inserted, updated, or deleted.
 *//* ww w.  j a  v a  2 s . c o  m*/
public TableUpdateFinishedEventArgs(DateTime start, Tables table, Integer recordId) {
    super();
    this._elapsed = new Period(start, DateTime.now());
    this._table = table;
    this._recordId = recordId;
}

From source file:org.dmb.trueprice.utils.internal.ServletUtils.java

/**
 * Renvoie la priode de temps ecoule depuis <param>fromDate</param>
 * en un String formatte en FR//from w  w  w  . j  a  va2  s. c  o m
 * @param fromDate
 * @return la priode de temps ecoule formattee en FR
 */
public static String getFormattedTimeElapsed(String fromDate) {
    /* Rcupration de la date courante */
    DateTime dtCourante = new DateTime();
    /* Rcupration de la date prsente dans le cookie */
    DateTimeFormatter formatter = DateTimeFormat.forPattern(FORMAT_DATE);
    DateTime dtDerniereConnexion = formatter.parseDateTime(fromDate);
    /* Calcul de la dure de l'intervalle */
    Period periode = new Period(dtDerniereConnexion, dtCourante);
    /* Formatage de la dure de l'intervalle */
    PeriodFormatter periodFormatter = new PeriodFormatterBuilder().appendYears().appendSuffix(" an ", " ans ")
            .appendMonths().appendSuffix(" mois ").appendDays().appendSuffix(" jour ", " jours ").appendHours()
            .appendSuffix(" heure ", " heures ").appendMinutes().appendSuffix(" minute ", "minutes ")
            .appendSeparator(" et ").appendSeconds().appendSuffix(" seconde ", " secondes ").toFormatter();

    String intervalleConnexions = periodFormatter.print(periode);

    return intervalleConnexions;
}

From source file:org.drftpd.commands.tvmaze.TvMazeUtils.java

License:Open Source License

private static String calculateAge(DateTime epDate) {

    Period period;/*from  w  ww.j  a v  a  2 s .  c  o  m*/
    if (epDate.isBefore(new DateTime())) {
        period = new Period(epDate, new DateTime());
    } else {
        period = new Period(new DateTime(), epDate);
    }

    PeriodFormatter formatter = new PeriodFormatterBuilder().appendYears().appendSuffix("y").appendMonths()
            .appendSuffix("m").appendWeeks().appendSuffix("w").appendDays().appendSuffix("d ").appendHours()
            .appendSuffix("h").appendMinutes().appendSuffix("m").printZeroNever().toFormatter();

    return formatter.print(period);
}

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.  ja  va2 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";
}

From source file:org.estatio.api.Api.java

License:Apache License

@ActionSemantics(Of.IDEMPOTENT)
public void putBreakOption(@Named("leaseReference") final String leaseReference,
        @Named("breakType") final String breakTypeStr,
        @Named("breakExcerciseType") final String breakExcerciseTypeStr,
        @Named("breakDate") final LocalDate breakDate,
        @Named("notificationDate") final LocalDate notificationDate,
        @Named("notificationPeriod") @Optional String notificationPeriodStr,
        @Named("description") @Optional final String description) {
    final Lease lease = fetchLease(leaseReference);
    final BreakType breakType = BreakType.valueOf(breakTypeStr);
    final BreakExerciseType breakExerciseType = BreakExerciseType.valueOf(breakExcerciseTypeStr);
    if (notificationDate != null) {
        final Period period = new Period(notificationDate, breakDate);
        notificationPeriodStr = JodaPeriodUtils.asSimpleString(period);
    }/* w  w  w . j  a  v  a 2  s .c om*/
    wrapperFactory.wrap(breakOptions.newBreakOption(lease, breakDate, notificationPeriodStr, breakType,
            breakExerciseType, description));

}

From source file:org.estatio.dom.lease.Lease.java

License:Apache License

@org.apache.isis.applib.annotation.Property(editing = Editing.DISABLED, optionality = Optionality.OPTIONAL)
public String getTenancyDuration() {
    LocalDateInterval ldi;/*from  www  . j a  v a 2  s . co m*/
    if (getTenancyStartDate() != null && getTenancyEndDate() != null) {
        ldi = getEffectiveInterval();
    } else if (getTenancyStartDate() == null && getTenancyEndDate() != null && getStartDate() != null) {
        ldi = new LocalDateInterval(getStartDate(), getTenancyEndDate());
    } else if (getTenancyStartDate() != null && getTenancyEndDate() == null && getEndDate() != null) {
        ldi = new LocalDateInterval(getTenancyStartDate(), getEndDate());
    } else {
        return null;
    }

    if (ldi.isValid()) {
        return JodaPeriodUtils.asSimpleString(new Period(ldi.asInterval(), PeriodType.yearMonthDay()));
    }

    return null;
}

From source file:org.estatio.dom.lease.Leases.java

License:Apache License

@Action(semantics = SemanticsOf.IDEMPOTENT)
@MemberOrder(sequence = "4")
public String verifyLeasesUntil(final LeaseItemType leaseItemType,
        final @ParameterLayout(named = "Until date") LocalDate untilDate) {
    DateTime start = DateTime.now();// ww w.  j a v a2s . c  om
    List<Lease> leases = allLeases();
    for (Lease lease : leases) {
        for (LeaseItem leaseItem : lease.getItems()) {
            if (leaseItem.getType().equals(leaseItemType)) {
                leaseItem.verifyUntil(untilDate);
            }
        }
    }
    Period p = new Period(start, DateTime.now());
    return String.format("Verified %d leases in %s", leases.size(), JodaPeriodUtils.asString(p));
}

From source file:org.estatio.dom.lease.Leases.java

License:Apache License

@Action(semantics = SemanticsOf.IDEMPOTENT, restrictTo = RestrictTo.PROTOTYPING)
@MemberOrder(sequence = "98")
public String verifyAllLeases() {
    DateTime dt = DateTime.now();/*from  w w  w  . j av a2s  .co  m*/
    List<Lease> leases = allLeases();
    for (Lease lease : leases) {
        lease.verifyUntil(getClockService().now());
    }
    Period p = new Period(dt, DateTime.now());
    return String.format("Verified %d leases in %s", leases.size(), JodaPeriodUtils.asString(p));
}

From source file:org.estatio.dom.valuetypes.AbstractInterval.java

License:Apache License

/**
 * The duration in days// w  w w .j a v a  2 s .c  o  m
 * 
 * @return
 */
public int days() {
    if (isInfinite()) {
        return 0;
    }
    Period p = new Period(asInterval(), PeriodType.days());
    return p.getDays();
}