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:org.oscarehr.util.AgeCalculator.java

License:Open Source License

public static Age calculateAge(Calendar birthDate) {
    LocalDate birthdate = LocalDate.fromCalendarFields(birthDate);
    LocalDate now = new LocalDate(); //Today's date
    Period period = new Period(birthdate, now, PeriodType.yearMonthDay());

    return new Age(period.getDays(), period.getMonths(), period.getYears());
}

From source file:org.wicketstuff.calendarviews.FullWeekCalendarView.java

License:Apache License

/**
 * This implementation makes sure to include the entire data range specified by the start date
 * and end date passed in to the constructor, and any additional days before and after that are
 * needed to complete the full weeks contained in this view.
 * //from   w  ww .ja v a  2s  .c o  m
 * @return a data provider of days to be shown on the calendar
 */
protected final IDataProvider<DateMidnight> createDaysDataProvider() {
    int firstDOW = getFirstDayOfWeek();
    int lastDOW = getLastDayOfWeek();
    // TODO: is this logic right? doing this since JODA has Sunday as day 7
    int add = firstDOW > lastDOW ? -7 : 0;
    final DateTime start = new DateTime(getStartDate()).withDayOfWeek(firstDOW).plusDays(add);
    final DateTime end = new DateTime(getEndDate()).withDayOfWeek(lastDOW);
    final Period period = new Period(start, end, PeriodType.days());

    getEventProvider().initializeWithDateRange(start.toDate(), end.toDate());

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("start: " + start + "; end: " + end + "; days: " + period.getDays());
    }

    return createDaysDataProvider(start, end, period);
}

From source file:org.wicketstuff.calendarviews.logic.DateMidnightIterator.java

License:Apache License

public DateMidnightIterator(DateTime start, DateTime end) {
    this(start, end, 0, new Period(start, end, PeriodType.days()).getDays() + 1);
}

From source file:ru.anr.base.BaseParent.java

License:Apache License

/**
 * @param startDate/*ww w  .j  a v  a2s  .  c  o  m*/
 *            Start date
 * @param endDate
 *            End date
 * @param locale
 *            Locale
 * @return formatted period without seconds
 */
public static String formatPeriodWithoutSeconds(Calendar startDate, Calendar endDate, String locale) {

    Period period = new Period(startDate.getTimeInMillis(), endDate.getTimeInMillis(),
            PeriodType.standard().withSecondsRemoved().withMillisRemoved());

    String l = locale == null ? Locale.getDefault().toString() : locale;
    return PeriodFormat.wordBased(Locale.forLanguageTag(l.replaceAll("_", "-"))).print(period);
}

From source file:ventanas.parqueadero.ventas.java

private void btnPagoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPagoActionPerformed

    try {// ww  w.j a  v  a2  s  . c  o m
        int indice = dBTable1.getSelectedRow();
        Billing b = ventas.get(indice);

        Object state = controller.getEm().createNativeQuery("Select estado from factura where id=" + b.getId())
                .getSingleResult();

        if (state.toString().equals("Pagada")) {
            JOptionPane.showMessageDialog(this, "El ticket ya ha sido PAGADO.\n Actualice la tabla de datos",
                    "ERROR", JOptionPane.ERROR_MESSAGE);
            verTabla(true);
            return;
        }

        if (state.toString().equals("ANULADA")) {
            JOptionPane.showMessageDialog(this, "El ticket ha sido ANULADO.\n Actualice la tabla de datos",
                    "ERROR", JOptionPane.ERROR_MESSAGE);
            verTabla(true);
            return;
        }

        if (state.equals("CONTRATO")) {
            JOptionPane.showMessageDialog(this, "El ticket es de tipo CONTRATO.\n No se puede pagar.", "ERROR",
                    JOptionPane.ERROR_MESSAGE);
            verTabla(true);
            return;
        }

        //calcular el tiempo de pago
        Date timeStart = b.getDetailBillingList().get(0).getTimestart();
        DateTime start = new DateTime(timeStart);

        //obtener la fecha de la base de datos
        //generar la hora de la bd
        Date endJava = convertToDate_DatabaseDate();
        DateTime end = new DateTime(endJava);

        Period $period = new Period(start, end, PeriodType.yearMonthDayTime());
        int days = $period.getDays();
        int hours = $period.getHours();
        int minutes = $period.getMinutes();

        System.out.println("DIA " + $period.getDays());
        System.out.println("HORAS: " + $period.getHours());
        System.out.println("MINUTOS: " + $period.getMinutes());

        Product product = b.getDetailBillingList().get(0).getProductId();
        BigDecimal price = product.getSaleprice();
        BigDecimal quantity = BigDecimal.ZERO;
        String tiempo = days + ":" + hours + ":" + minutes;

        if (hours >= 1) {
            quantity = new BigDecimal(hours);
        }

        if (minutes > 0) {
            quantity = quantity.add(BigDecimal.ONE);
        }

        if (days >= 1) {
            int hoursPerDay = days * 24;
            quantity = quantity.add(new BigDecimal(hoursPerDay));
        }

        BigDecimal totalIva = price.multiply(quantity).multiply(product.getPercentageIva());
        BigDecimal total = product.getSaleprice().multiply(quantity).add(totalIva);
        total = total.setScale(2, RoundingMode.HALF_UP);

        CobroParkForm dialog = new CobroParkForm(new javax.swing.JFrame(), Boolean.TRUE, b, tiempo, days, hours,
                minutes, quantity, endJava, total);
        dialog.setVisible(true);
        verTabla(true);
    } catch (ParseException ex) {
        Logger.getLogger(ventas.class.getName()).log(Level.SEVERE, null, ex);
    }

}