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:au.com.scds.chats.dom.attendance.Attend.java

License:Apache License

@Action()
public Attend updateDatesAndTimes(@ParameterLayout(named = "Start Date Time") DateTime start,
        @ParameterLayout(named = "End Date Time") DateTime end) {
    if (start != null && end != null) {
        if (end.isBefore(start)) {
            container.warnUser("end date & time is earlier than start date & time");
            return this;
        }//from  www  .  j ava 2s.  co  m
        if (end.getDayOfWeek() != start.getDayOfWeek()) {
            container.warnUser("end date and start date are different days of the week");
            return this;
        }
        Period period = new Period(start.toLocalDateTime(), end.toLocalDateTime());
        Float hours = ((float) period.toStandardMinutes().getMinutes()) / 60;
        if (hours > 12.0) {
            container.warnUser("end date & time and start date & time are not in the same 12 hour period");
            return this;
        }
        setStartDateTime(start);
        setEndDateTime(end);
        setAttended(true);
    }
    return this;
}

From source file:au.com.scds.chats.dom.call.ScheduledCall.java

License:Apache License

@Property(editing = Editing.DISABLED, notPersisted = true)
@PropertyLayout(named = "Call Length in Hours", describedAs = "The interval that the participant attended the activity in hours")
@MemberOrder(sequence = "6")
@NotPersistent//from w  ww.java  2s . co m
public String getCallLength() {
    if (getStartDateTime() != null && getEndDateTime() != null) {
        Period per = new Period(getStartDateTime().toLocalDateTime(), getEndDateTime().toLocalDateTime());
        Float hours = ((float) per.toStandardMinutes().getMinutes()) / 60;
        return hoursFormat.format(hours);
    } else
        return null;
}

From source file:au.com.scds.chats.dom.general.Person.java

License:Apache License

@Programmatic()
public Integer getAge(LocalDate futureDate) {
    if (futureDate == null)
        futureDate = LocalDate.now();
    Period p = new Period(getBirthdate(), futureDate);
    return p.getYears();
}

From source file:au.com.scds.chats.dom.volunteer.VolunteeredTime.java

License:Apache License

@Action()
@MemberOrder(name = "enddatetime", sequence = "1")
public VolunteeredTime updateDatesAndTimes(@ParameterLayout(named = "Start Date Time") DateTime start,
        @ParameterLayout(named = "End Date Time") DateTime end) {
    if (start != null && end != null) {
        if (end.isBefore(start)) {
            container.warnUser("end date & time is earlier than start date & time");
            return this;
        }//from   w  w  w  .  j  av a2  s . c  o m
        if (end.getDayOfWeek() != start.getDayOfWeek()) {
            container.warnUser("end date and start date are different days of the week");
            return this;
        }
        Period period = new Period(start.toLocalDateTime(), end.toLocalDateTime());
        Float hours = ((float) period.toStandardMinutes().getMinutes()) / 60;
        if (hours > 12.0) {
            container.warnUser("end date & time and start date & time are not in the same 12 hour period");
            return this;
        }
        setStartDateTime(start);
        setEndDateTime(end);
    }
    return this;
}

From source file:au.com.scds.chats.dom.volunteer.VolunteeredTime.java

License:Apache License

@Property(editing = Editing.DISABLED, notPersisted = true)
@PropertyLayout(named = "Effort in Hours", describedAs = "The interval of volunteer effort provided in hours")
@MemberOrder(sequence = "13")
@NotPersistent/*from   w ww .  ja v a2  s.c  o m*/
public String getEffortLength() {
    if (getStartDateTime() != null && getEndDateTime() != null) {
        Period per = new Period(getStartDateTime().toLocalDateTime(), getEndDateTime().toLocalDateTime());
        Float hours = ((float) per.toStandardMinutes().getMinutes()) / 60;
        return hoursFormat.format(hours);
    } else
        return null;
}

From source file:be.kdg.repaircafemodel.dom.repairs.RepairDetails.java

/**
 * How much time is left for bidding on this repair
 *
 * @return Period. Represents time period
 *///from   w w  w  .  j  a  v a  2s  .  c  om
public Period getExpirationTime() {
    return new Period(new DateTime(), dueDate);
}

From source file:beans.utilidades.MetodosGenerales.java

public String calcularEdad(Date fechaNacimiento) {//calcular la edad a partir de la fecha de nacimiento    
    Period periodo = new Period(new DateTime(fechaNacimiento), new DateTime(new Date()));
    return String.valueOf(periodo.getYears()) + "A " + String.valueOf(periodo.getMonths()) + "M ";
}

From source file:beans.utilidades.MetodosGenerales.java

public int calcularEdadInt(Date fechaNacimiento) {//calcular la edad en aos
    Period periodo = new Period(new DateTime(fechaNacimiento), new DateTime(new Date()));
    if (periodo.getYears() == 0) {
        return 1;
    } else {// ww w.  ja  v a 2s. co m
        return periodo.getYears();
    }
}

From source file:br.com.bob.dashboard.model.Metric.java

public String getInactiveTime() {
    final DateTime old = new DateTime(date);
    final DateTime now = new DateTime();
    final Period period = new Period(old, now);

    int interval;
    if ((interval = period.getDays()) > 0)
        return getText(interval, "dia(s)");

    else if ((interval = period.getHours()) > 0)
        return getText(interval, "hora(s)");

    else if ((interval = period.getMinutes()) > 0)
        return getText(interval, "minuto(s)");
    else//from  www  .  ja  va2 s  .co  m
        return "h pouco";
}

From source file:br.com.registro.view.TelaHoras.java

private void jButtonConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConfirmarActionPerformed
    // TODO add your handling code here:

    ControleDAO dao = new ControleDAO();
    Controle control = new Controle();
    HoraUtil util = new HoraUtil();

    SimpleDateFormat data = new SimpleDateFormat("dd/MM/yyyy");
    Date date = new Date();
    String d = data.format(date);

    int indiceLinha = jTable1.getSelectedRow();

    if (jComboBoxFuncionario.getSelectedItem().equals("Selecione um funciorio")
            || jFormattedTextFieldHoraEntrada.getText().isEmpty()
            || jFormattedTextFieldHoraSaida.getText().isEmpty()
            || jFormattedTextFieldData.getText().isEmpty()) {

        JOptionPane.showMessageDialog(null, "Campos obrigatrios vazios", "Ateno",
                JOptionPane.INFORMATION_MESSAGE);

    } else if (jFormattedTextFieldData.getText().equals(d)) {

        JOptionPane.showMessageDialog(null, "Funcionrio j registrou ponto nesta data", "Ateno",
                JOptionPane.ERROR_MESSAGE);

        jButtonAdicionar.setEnabled(true);
        jButtonConfirmar.setEnabled(false);
        jButtonCancelar.setEnabled(false);
        jButtonAtualizar.setEnabled(false);
        jButtonExcluir.setEnabled(false);

        jComboBoxFuncionario.setEnabled(false);
        jFormattedTextFieldHoraEntrada.setEnabled(false);

        jFormattedTextFieldHoraSaida.setEnabled(false);
        jFormattedTextFieldHoraExtra.setEnabled(false);
        jFormattedTextFieldData.setEnabled(false);
        jTextAreaDescricao.setEnabled(false);

        jComboBoxFuncionario.setSelectedItem("Selecione um funcionrio");
        jFormattedTextFieldHoraEntrada.setText("");

        jFormattedTextFieldHoraSaida.setText("");
        jFormattedTextFieldHoraExtra.setText("");
        jFormattedTextFieldData.setText("");
        jTextAreaDescricao.setText("");

    } else {/*from w  w w. j  a v  a 2 s . co  m*/

        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");

        Date dataInicial = null;
        Date dataFinal = null;

        try {

            dataInicial = format
                    .parse(jFormattedTextFieldData.getText() + " " + jFormattedTextFieldHoraEntrada.getText());
            dataFinal = format
                    .parse(jFormattedTextFieldData.getText() + " " + jFormattedTextFieldHoraSaida.getText());

            Timestamp inicialStamp = new Timestamp(dataInicial.getTime());
            Timestamp finalStamp = new Timestamp(dataFinal.getTime());

            control.setHoraEntrada(inicialStamp);
            control.setHoraSaida(finalStamp);

            DateTime dataHoraEntrada = new DateTime(inicialStamp);
            DateTime dataHoraSaida = new DateTime(finalStamp);

            Period tempoTrabalhado = new Period(dataHoraEntrada, dataHoraSaida);

            int horaLocal = tempoTrabalhado.getMinutes() + tempoTrabalhado.getHours() * 60
                    + tempoTrabalhado.getDays() * 1440;

            int hora = horaLocal - 540;

            control.setHoraExtra(hora);

            control.setFuncionario((Funcionario) jComboBoxFuncionario.getSelectedItem());

            control.setData(jFormattedTextFieldData.getText());
            control.setStatus(util.informaAtraso(horaLocal) + "");
            control.setDescricao(jTextAreaDescricao.getText());

            if (dao.savar(control)) {

                JOptionPane.showMessageDialog(null, "Ponto registrado com sucesso", "Ateno",
                        JOptionPane.INFORMATION_MESSAGE);

                jButtonAdicionar.setEnabled(true);
                jButtonConfirmar.setEnabled(false);
                jButtonCancelar.setEnabled(false);
                jButtonAtualizar.setEnabled(false);
                jButtonExcluir.setEnabled(false);

                jComboBoxFuncionario.setEnabled(false);
                jFormattedTextFieldHoraEntrada.setEnabled(false);

                jFormattedTextFieldHoraSaida.setEnabled(false);
                jFormattedTextFieldHoraExtra.setEnabled(false);
                jFormattedTextFieldData.setEnabled(false);
                jTextAreaDescricao.setEnabled(false);

                jComboBoxFuncionario.setSelectedItem("Selecione um funcionrio");
                jFormattedTextFieldHoraEntrada.setText("");

                jFormattedTextFieldHoraSaida.setText("");
                jFormattedTextFieldHoraExtra.setText("");
                jFormattedTextFieldData.setText("");
                jTextAreaDescricao.setText("");

                //========================
                //--Tabela
                this.tabelaControle = new TableModelControle();
                this.jTable1.setModel(tabelaControle);

            } else {

                JOptionPane.showMessageDialog(null, "Erro ao cadastrar.", "Ateno",
                        JOptionPane.ERROR_MESSAGE);

                jButtonAdicionar.setEnabled(true);
                jButtonConfirmar.setEnabled(false);
                jButtonCancelar.setEnabled(false);
                jButtonAtualizar.setEnabled(false);
                jButtonExcluir.setEnabled(false);

                jComboBoxFuncionario.setEnabled(false);
                jFormattedTextFieldHoraEntrada.setEnabled(false);

                jFormattedTextFieldHoraSaida.setEnabled(false);
                jFormattedTextFieldHoraExtra.setEnabled(false);
                jFormattedTextFieldData.setEnabled(false);
                jTextAreaDescricao.setEnabled(false);

                jComboBoxFuncionario.setSelectedItem("Selecione um funcionrio");
                jFormattedTextFieldHoraEntrada.setText("");

                jFormattedTextFieldHoraSaida.setText("");
                jFormattedTextFieldHoraExtra.setText("");
                jFormattedTextFieldData.setText("");
                jTextAreaDescricao.setText("");
            }

        } catch (Exception e) {
        }
    }

}