Ejemplo n.º 1
0
 /**
  * Support method for testDates()
  *
  * @return void
  */
 protected function runTests()
 {
     // Build an object to test with (using empty configuration to ensure default
     // settings):
     $date = new Converter(new Config([]));
     // Try some conversions:
     $this->assertEquals('11-29-1973', $date->convertToDisplayDate('U', 123456879));
     $this->assertEquals('11-29-1973', $date->convertToDisplayDate('U', 123456879.1234));
     $this->assertEquals('11-29-1973--16:34', $date->convertToDisplayDateAndTime('U', 123456879, '--'));
     $this->assertEquals('16:34 11-29-1973', $date->convertToDisplayTimeAndDate('U', 123456879));
     $this->assertEquals('11-29-1973', $date->convertToDisplayDate('m-d-y', '11-29-73'));
     $this->assertEquals('11-29-1973', $date->convertToDisplayDate('m-d-y', '11-29-1973'));
     $this->assertEquals('11-29-1973', $date->convertToDisplayDate('m-d-y H:i', '11-29-73 23:01'));
     $this->assertEquals('23:01', $date->convertToDisplayTime('m-d-y H:i', '11-29-73 23:01'));
     $this->assertEquals('01-02-2001', $date->convertToDisplayDate('m-d-y', '01-02-01'));
     $this->assertEquals('01-02-2001', $date->convertToDisplayDate('m-d-y', '01-02-2001'));
     $this->assertEquals('01-02-2001', $date->convertToDisplayDate('m-d-y H:i', '01-02-01 05:11'));
     $this->assertEquals('05:11', $date->convertToDisplayTime('m-d-y H:i', '01-02-01 05:11'));
     $this->assertEquals('01-02-2001', $date->convertToDisplayDate('Y-m-d', '2001-01-02'));
     $this->assertEquals('01-02-2001', $date->convertToDisplayDate('Y-m-d H:i', '2001-01-02 05:11'));
     $this->assertEquals('05:11', $date->convertToDisplayTime('Y-m-d H:i', '2001-01-02 05:11'));
     $this->assertEquals('01-2001', $date->convertFromDisplayDate('m-Y', '01-02-2001'));
     // Check for proper handling of known problems:
     try {
         $bad = $date->convertToDisplayDate('U', 'invalid');
         $this->fail('Expected exception did not occur');
     } catch (DateException $e) {
         $this->assertTrue((bool) stristr($e->getMessage(), 'failed to parse time string'));
     }
     try {
         $bad = $date->convertToDisplayDate('d-m-Y', '31-02-2001');
         $this->fail('Expected exception did not occur');
     } catch (DateException $e) {
         $this->assertTrue((bool) stristr($e->getMessage(), 'parsed date was invalid'));
     }
 }