Example #1
0
 /**
  * Tests RW_Math::moda()
  */
 public function testGet()
 {
     /**
      * SEGUNDOS
      */
     // 1 segundo
     $time = new RW_Time(1);
     $this->assertSame('01', $time->get(RW_Time::SECOND));
     $this->assertSame('1', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('00', $time->get(RW_Time::MINUTE));
     $this->assertSame('0', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('00', $time->get(RW_Time::HOUR));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     // 1 segundo
     $time = new RW_Time(1, RW_Time::SECOND);
     $this->assertSame('01', $time->get(RW_Time::SECOND));
     $this->assertSame('1', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('00', $time->get(RW_Time::MINUTE));
     $this->assertSame('0', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('00', $time->get(RW_Time::HOUR));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     // 13 segundos
     $time = new RW_Time(13);
     $this->assertSame('13', $time->get(RW_Time::SECOND));
     $this->assertSame('13', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('00', $time->get(RW_Time::MINUTE));
     $this->assertSame('0', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('00', $time->get(RW_Time::HOUR));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     // 13 segundos
     $time = new RW_Time(13, RW_Time::SECOND);
     $this->assertSame('13', $time->get(RW_Time::SECOND));
     $this->assertSame('13', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('00', $time->get(RW_Time::MINUTE));
     $this->assertSame('0', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('00', $time->get(RW_Time::HOUR));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     // 63 segundos
     $time = new RW_Time(63);
     $this->assertSame('03', $time->get(RW_Time::SECOND));
     $this->assertSame('3', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('01', $time->get(RW_Time::MINUTE));
     $this->assertSame('1', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('00', $time->get(RW_Time::HOUR));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     // 63 segundos
     $time = new RW_Time(63, RW_Time::SECOND);
     $this->assertSame('03', $time->get(RW_Time::SECOND));
     $this->assertSame('3', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('01', $time->get(RW_Time::MINUTE));
     $this->assertSame('1', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('00', $time->get(RW_Time::HOUR));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     /**
      * MINUTOS
      */
     // 1 minuto
     $time = new RW_Time(60);
     $this->assertSame('00', $time->get(RW_Time::SECOND));
     $this->assertSame('0', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('01', $time->get(RW_Time::MINUTE));
     $this->assertSame('1', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('00', $time->get(RW_Time::HOUR));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     // 1 minuto
     $time = new RW_Time(1, RW_Time::MINUTE);
     $this->assertSame('00', $time->get(RW_Time::SECOND));
     $this->assertSame('0', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('01', $time->get(RW_Time::MINUTE));
     $this->assertSame('1', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('00', $time->get(RW_Time::HOUR));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     // 13 minutos
     $time = new RW_Time(13 * 60);
     $this->assertSame('00', $time->get(RW_Time::SECOND));
     $this->assertSame('0', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('13', $time->get(RW_Time::MINUTE));
     $this->assertSame('13', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('00', $time->get(RW_Time::HOUR));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     // 13 minutos
     $time = new RW_Time(13, RW_Time::MINUTE);
     $this->assertSame('00', $time->get(RW_Time::SECOND));
     $this->assertSame('0', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('13', $time->get(RW_Time::MINUTE));
     $this->assertSame('13', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('00', $time->get(RW_Time::HOUR));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     // 13,5 minutos
     $time = new RW_Time(13 * 60 + 30);
     $this->assertSame('30', $time->get(RW_Time::SECOND));
     $this->assertSame('30', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('13', $time->get(RW_Time::MINUTE));
     $this->assertSame('13', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('00', $time->get(RW_Time::HOUR));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     // 13,5 minutos
     $time = new RW_Time(13.5, RW_Time::MINUTE);
     $this->assertSame('30', $time->get(RW_Time::SECOND));
     $this->assertSame('30', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('13', $time->get(RW_Time::MINUTE));
     $this->assertSame('13', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('00', $time->get(RW_Time::HOUR));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     // 13:30 minutos
     $time = new RW_Time('13:30', RW_Time::MINUTE . ':' . RW_Time::SECOND);
     $this->assertSame('30', $time->get(RW_Time::SECOND));
     $this->assertSame('30', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('13', $time->get(RW_Time::MINUTE));
     $this->assertSame('13', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('00', $time->get(RW_Time::HOUR));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     /**
      * HORAS
      */
     // 1 hora
     $time = new RW_Time(60 * 60);
     $this->assertSame('00', $time->get(RW_Time::SECOND));
     $this->assertSame('0', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('00', $time->get(RW_Time::MINUTE));
     $this->assertSame('0', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('01', $time->get(RW_Time::HOUR));
     $this->assertSame('1', $time->get(RW_Time::HOUR_SHORT));
     // 1 hora
     $time = new RW_Time(1, RW_Time::HOUR);
     $this->assertSame('00', $time->get(RW_Time::SECOND));
     $this->assertSame('0', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('00', $time->get(RW_Time::MINUTE));
     $this->assertSame('0', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('01', $time->get(RW_Time::HOUR));
     $this->assertSame('1', $time->get(RW_Time::HOUR_SHORT));
     // 120 horas
     $time = new RW_Time(120 * 60 * 60);
     $this->assertSame('00', $time->get(RW_Time::SECOND));
     $this->assertSame('0', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('00', $time->get(RW_Time::MINUTE));
     $this->assertSame('0', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('120', $time->get(RW_Time::HOUR));
     $this->assertSame('120', $time->get(RW_Time::HOUR_SHORT));
     // 120 horas
     $time = new RW_Time(120, RW_Time::HOUR);
     $this->assertSame('00', $time->get(RW_Time::SECOND));
     $this->assertSame('0', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('00', $time->get(RW_Time::MINUTE));
     $this->assertSame('0', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('120', $time->get(RW_Time::HOUR));
     $this->assertSame('120', $time->get(RW_Time::HOUR_SHORT));
     // 27 horas
     $time = new RW_Time(27 * 60 * 60);
     $this->assertSame('0', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('0', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('27', $time->get(RW_Time::HOUR_SHORT));
     // 27 horas
     $time = new RW_Time(27, RW_Time::HOUR);
     $this->assertSame('0', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('0', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('27', $time->get(RW_Time::HOUR_SHORT));
     // 27,5 horas
     $time = new RW_Time(27.5 * 60 * 60);
     $this->assertSame('0', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('30', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('27', $time->get(RW_Time::HOUR_SHORT));
     // 27,5 horas
     $time = new RW_Time(27.5, RW_Time::HOUR);
     $this->assertSame('0', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('30', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('27', $time->get(RW_Time::HOUR_SHORT));
     // 13:45:3
     $time = new RW_Time(13 * 60 * 60 + 45 * 60 + 3);
     $this->assertSame('3', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('45', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('13', $time->get(RW_Time::HOUR_SHORT));
     // 13:45:03 minutos
     $time = new RW_Time('13:45:3', RW_Time::HOUR . ':' . RW_Time::MINUTE . ':' . RW_Time::SECOND);
     $this->assertSame('3', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('45', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('13', $time->get(RW_Time::HOUR_SHORT));
     /**
      * FORMATOS
      */
     $time = new RW_Time('13:24', RW_Time::HOUR . ':' . RW_Time::MINUTE);
     $this->assertSame('0', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('24', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('13', $time->get(RW_Time::HOUR_SHORT));
     $time = new RW_Time('13:24');
     $this->assertSame('24', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('13', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     $time = new RW_Time('13:24:15');
     $this->assertSame('15', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('24', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('13', $time->get(RW_Time::HOUR_SHORT));
     // hora inválida
     $time = new RW_Time('13:60:00');
     $this->assertSame('0', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('0', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('14', $time->get(RW_Time::HOUR_SHORT));
     // formato teoricamnente inválido
     $time = new RW_Time('13:24', RW_Time::SECOND . ':' . RW_Time::MINUTE);
     $this->assertSame('13', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('24', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('0', $time->get(RW_Time::HOUR_SHORT));
     /**
      * Zend_Date
      */
     $time = new RW_Time(new Zend_Date('12/01/2012 13:24:45', 'dd/MM/yyyy hh:mm:ss'));
     $this->assertSame('45', $time->get(RW_Time::SECOND_SHORT));
     $this->assertSame('24', $time->get(RW_Time::MINUTE_SHORT));
     $this->assertSame('13', $time->get(RW_Time::HOUR_SHORT));
 }