Example usage for org.joda.time Period getMinutes

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

Introduction

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

Prototype

public int getMinutes() 

Source Link

Document

Gets the minutes field part of the period.

Usage

From source file:uk.ac.susx.tag.method51.core.params.codec.concrete.DurationCodec.java

License:Apache License

@Override
public Duration decodeString(String value) throws DecodeException {
    Duration result = null;//w  w w . j  ava 2 s  . c o m

    long milliseconds;

    try {
        milliseconds = Long.parseLong(value);

    } catch (NumberFormatException e) {

        try {
            if (value.length() == 0) {
                throw new IllegalArgumentException("zero length interval specification");
            }
            value = value.toUpperCase();

            if (!value.matches(".*[DWMHS].*")) {
                throw new IllegalArgumentException(
                        "no time units specified, see ISO 8601 duration specification (months / years not supported): http://en.wikipedia.org/wiki/ISO_8601#Durations");
            }

            if (!value.startsWith("P")) {
                value = "P" + value;
            }

            Matcher m = Pattern.compile("[HMS]").matcher(value);
            if (!value.contains("T") && m.find()) {
                String c = m.group(0);
                int i = value.indexOf(c);
                value = value.substring(0, i - 1) + "T" + value.substring(i - 1);
            }

            Period period = ISOPeriodFormat.standard().parsePeriod(value);
            long seconds = 0;
            seconds += period.getSeconds();
            seconds += period.getMinutes() * DateTimeConstants.SECONDS_PER_MINUTE;
            seconds += period.getHours() * DateTimeConstants.SECONDS_PER_HOUR;
            seconds += period.getDays() * DateTimeConstants.SECONDS_PER_DAY;
            seconds += period.getWeeks() * DateTimeConstants.SECONDS_PER_WEEK;

            milliseconds = seconds * 1000;

        } catch (IllegalArgumentException e1) {
            throw new DecodeException("'" + value + "' is not a number, or an ISO 8601 duration", e1);
        }
    }

    result = new Duration(milliseconds);

    return result;
}

From source file:utilities.time.DateAndTimes.java

License:Open Source License

/**
 *
 * This will calculate out and return a String the length of a period in easy to read format: Y
 *
 * @param duration//w  w w .j  av  a  2 s . c o m
 * @param yearsSeparatorFormat
 * @param monthsSeparatorFormat
 * @param weeksSeparatorFormat
 * @param daysSeparatorFormat
 * @param hoursSeparatorFormat
 * @param minutesSeparatorFormat
 * @param secondsSeparatorFormat
 * @return
 */
public static String getPeriodFormattedFromMilliseconds(long duration, String yearsSeparatorFormat,
        String monthsSeparatorFormat, String weeksSeparatorFormat, String daysSeparatorFormat,
        String hoursSeparatorFormat, String minutesSeparatorFormat, String secondsSeparatorFormat) {
    Period period = new Period(duration);
    if (period.getYears() > 0) {
        return getPeriodFormat(period, yearsSeparatorFormat, monthsSeparatorFormat, weeksSeparatorFormat,
                daysSeparatorFormat, hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat);
    } else if (period.getMonths() > 0) {
        return getPeriodFormat(period, monthsSeparatorFormat, weeksSeparatorFormat, daysSeparatorFormat,
                hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat);
    } else if (period.getWeeks() > 0) {
        return getPeriodFormat(period, weeksSeparatorFormat, daysSeparatorFormat, hoursSeparatorFormat,
                minutesSeparatorFormat, secondsSeparatorFormat);
    } else if (period.getDays() > 0) {
        return getPeriodFormat(period, daysSeparatorFormat, hoursSeparatorFormat, minutesSeparatorFormat,
                secondsSeparatorFormat);
    } else if (period.getHours() > 0) {
        return getPeriodFormat(period, hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat);
    } else if (period.getMinutes() > 0) {
        return getPeriodFormat(period, minutesSeparatorFormat, secondsSeparatorFormat);
    } else if (period.getSeconds() > 0) {
        return getPeriodFormat(period, secondsSeparatorFormat);
    } else {
        return null;
    }
}

From source file:ventanas.parqueadero.ventas.java

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

    try {/*from   w w  w .j  a  va  2s.c om*/
        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);
    }

}