public function toStringOutput() { $date = new Date('2007-11-10 20:15+0100'); $this->assertEquals('2007-11-10 20:15:00+0100', $date->toString()); $this->assertEquals('2007-11-10 19:15:00+0000', $date->toString(Date::DEFAULT_FORMAT, new TimeZone(null))); }
function dateFunctionTest() { $date = new Date(); $myDate = $date->toString($this->myconn->getFormatter()->dialect->dateFormat); $syDate = $date->toString($this->syconn->getFormatter()->dialect->dateFormat); $pgDate = $date->toString($this->pgconn->getFormatter()->dialect->dateFormat); $sqDate = $date->toString($this->sqconn->getFormatter()->dialect->dateFormat); $this->assertProjection('cast(sysdate() as char)', 'convert(varchar, getdate())', 'str(getdate())', 'php(\'strval\', php(\'date\', \'Y-m-d H:i:s\', php(\'time\')))', create(new \rdbms\Criteria())->setProjection(SQLFunctions::str(SQLFunctions::getdate()))); $this->assertProjection('cast(timestampadd(month, -4, sysdate()) as char)', 'convert(varchar, dateadd(month, -4, getdate()))', 'str(dateadd(month, -4, getdate()))', 'php(\'strval\', dateadd("m", -4, php(\'date\', \'Y-m-d H:i:s\', php(\'time\'))))', create(new \rdbms\Criteria())->setProjection(SQLFunctions::str(SQLFunctions::dateadd('month', '-4', SQLFunctions::getdate())))); $this->assertProjection('timestampdiff(second, timestampadd(day, -4, sysdate()), sysdate())', 'datediff(second, dateadd(day, -4, getdate()), getdate())', 'datediff(second, dateadd(day, -4, getdate()), getdate())', 'datediff_not_implemented', create(new \rdbms\Criteria())->setProjection(SQLFunctions::datediff('second', SQLFunctions::dateadd('day', '-4', SQLFunctions::getdate()), SQLFunctions::getdate()))); $this->assertProjection('cast(extract(hour from sysdate()) as char)', 'datename(hour, getdate())', 'datename(hour, getdate())', 'php(\'strval\', php(\'idate\', "H", php(\'strtotime\', php(\'date\', \'Y-m-d H:i:s\', php(\'time\')))))', create(new \rdbms\Criteria())->setProjection(SQLFunctions::datename('hour', SQLFunctions::getdate()))); $this->assertProjection('extract(hour from \'' . $myDate . '\')', 'datepart(hour, \'' . $syDate . '\')', 'datepart(hour, \'' . $pgDate . '\')', 'php(\'idate\', "H", php(\'strtotime\', \'' . $sqDate . '\'))', create(new \rdbms\Criteria())->setProjection(SQLFunctions::datepart('hour', $date))); }
public function dateFormatCallbackWithoutTZ() { $date = new Date('2009-09-20 21:33:00'); $this->assertEquals($date->toString('Y-m-d H:i:s T'), $this->runTransformation(Node::fromObject($date, 'date')->getSource(), 'xp.date::format', ['string(/date/value)', "'Y-m-d H:i:s T'"])); }