/** * @covers DateTimeUtil::getDateMySql */ public function testGetDateMySql() { date_default_timezone_set("Asia/Tokyo"); $obj = new DateTimeUtil(); $val = 1448400000; $actual = $obj->getDateMySql($val); $expected = '2015-11-25 06:20:00'; $this->assertEquals($expected, $actual, __CLASS__ . "::" . __METHOD__ . ": line " . __LINE__); $date = $obj->getDateMySql(); $actual = PregUtil::checkMySQLDateFormat($date); $expected = true; $this->assertEquals($expected, $actual, __CLASS__ . "::" . __METHOD__ . ": line " . __LINE__); }
public function testCheckMySQLDateFormat() { # # OK Patterns # $str = "2015-12-03 09:05:46"; $actual = PregUtil::checkMySQLDateFormat($str); $expected = true; $this->assertEquals($expected, $actual, __CLASS__ . "::" . __METHOD__ . ": line " . __LINE__); $str = "2015-01-01 01:00:00"; $actual = PregUtil::checkMySQLDateFormat($str); $expected = true; $this->assertEquals($expected, $actual, __CLASS__ . "::" . __METHOD__ . ": line " . __LINE__); $str = "2015-12-31 23:59:59"; $actual = PregUtil::checkMySQLDateFormat($str); $expected = true; $this->assertEquals($expected, $actual, __CLASS__ . "::" . __METHOD__ . ": line " . __LINE__); # # NG Patterns # $str = "3015-12-31 23:59:59"; $actual = PregUtil::checkMySQLDateFormat($str); $expected = false; $this->assertEquals($expected, $actual, __CLASS__ . "::" . __METHOD__ . ": line " . __LINE__); $str = "2015-22-31 23:59:59"; $actual = PregUtil::checkMySQLDateFormat($str); $expected = false; $this->assertEquals($expected, $actual, __CLASS__ . "::" . __METHOD__ . ": line " . __LINE__); $str = "2015-12-41 23:59:59"; $actual = PregUtil::checkMySQLDateFormat($str); $expected = false; $this->assertEquals($expected, $actual, __CLASS__ . "::" . __METHOD__ . ": line " . __LINE__); $str = "2015-12-31 23:69:59"; $actual = PregUtil::checkMySQLDateFormat($str); $expected = false; $this->assertEquals($expected, $actual, __CLASS__ . "::" . __METHOD__ . ": line " . __LINE__); $str = "2015-12-31 23:59:69"; $actual = PregUtil::checkMySQLDateFormat($str); $expected = false; $this->assertEquals($expected, $actual, __CLASS__ . "::" . __METHOD__ . ": line " . __LINE__); }