document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.io.Serializable;
  2. import java.util.Date;
  3. import javax.faces.bean.ManagedBean;
  4. import javax.faces.bean.ViewScoped;
  5. import javax.faces.event.AjaxBehaviorEvent;
  6.  
  7. @ManagedBean(name = "horasController")
  8. @ViewScoped
  9. public class HorasController implements Serializable {
  10.  
  11.     private Date horainicial;
  12.     private Date horafinal;
  13.     private Double tiempotranscurrido;
  14.  
  15.     public HorasController() {
  16.     }
  17.  
  18.     public Date getHorainicial() {
  19.         return horainicial;
  20.     }
  21.  
  22.     public void setHorainicial(Date horainicial) {
  23.         this.horainicial = horainicial;
  24.     }
  25.  
  26.     public Date getHorafinal() {
  27.         return horafinal;
  28.     }
  29.  
  30.     public void setHorafinal(Date horafinal) {
  31.         this.horafinal = horafinal;
  32.     }
  33.  
  34.     public Double getTiempotranscurrido() {
  35.         return tiempotranscurrido;
  36.     }
  37.  
  38.     public void setTiempotranscurrido(Double tiempotranscurrido) {
  39.         this.tiempotranscurrido = tiempotranscurrido;
  40.     }
  41.    
  42.     /**
  43.      * Método para setear el valor del número de horas escogidos en un rango.
  44.      *
  45.      * @param event
  46.      */
  47.     public void seleccionHoras(AjaxBehaviorEvent event) {
  48.         if (getHorainicial() != null && getHorafinal() != null) {
  49.             if (getHorainicial().getTime() < getHorafinal().getTime()) {
  50.                 //3600000  es el valor en milisegundos de una hora..
  51.                 int tempresta = (int) (getHorafinal().getTime() - getHorainicial().getTime());
  52.                 tiempotranscurrido = Math.rint(((double) tempresta / 3600000) * 100) / 100;
  53.             } else if (getHorainicial().getTime() == getHorafinal().getTime()) {
  54.                 tiempotranscurrido = 0.0;
  55.             } else {
  56.                 setHorafinal(null);
  57.                 tiempotranscurrido = 0.0;
  58.             }
  59.         } else {
  60.             tiempotranscurrido = 0.0;
  61.         }
  62.     }
  63. }
');