/** * This is the constructor. * * This function extracts the date. * * @author David Pauli <*****@*****.**> * @param String $date The date to set (timestamp or strtotime allowed string). * @since 0.1.3 * @since 0.2.1 Extend constructor to use also timestamps. */ public function __construct($date) { // if parameter is no string if (InputValidator::isTimestamp($date)) { $timestamp = $date; } else { if (InputValidator::isString($date)) { // try to convert to a timestamp $timestamp = strtotime($date); } else { $this->errorSet("D-1"); Logger::error("ep6\\Date\nThe parameter date " . $date . " is no string."); return; } } if (!$timestamp) { $this->errorSet("D-2"); Logger::error("ep6\\Date\nThe parameter date " . $date . " is no valid date format."); return; } $this->timestamp = $timestamp; }
/** * @group utility */ function testIsTimestamp() { $this->assertFalse(InputValidator::isTimestamp("NoTimestamp")); $this->assertTrue(InputValidator::isTimestamp(1234567890)); }