本文整理汇总了PHP中DateHelper::validateDate方法的典型用法代码示例。如果您正苦于以下问题:PHP DateHelper::validateDate方法的具体用法?PHP DateHelper::validateDate怎么用?PHP DateHelper::validateDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateHelper
的用法示例。
在下文中一共展示了DateHelper::validateDate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: instantiate
public function instantiate($dao)
{
// Instantiate a Slim application:
$app = new \Slim\App(['settings' => ['displayErrorDetails' => true]]);
// Routes
$app->get('/api/posts/{id}', function (ServerRequestInterface $request, ResponseInterface $response, $args) use($dao) {
$params = $request->getQueryParams();
$id = $args['id'];
$post = $dao->getPost($id);
if (!empty($post[0])) {
$postResponse = ["post" => $post[0]];
} else {
// send an empty json list {} and not []
$postResponse = ["post" => new ArrayObject()];
}
$response->getBody()->write(json_encode($postResponse, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE));
$response = $response->withHeader('Content-type', 'application/json');
return $response;
});
$app->get('/api/posts', function (ServerRequestInterface $request, ResponseInterface $response) use($dao) {
$params = $request->getQueryParams();
if (isset($params['author'])) {
$author = $params['author'];
} else {
$author = null;
}
// TODO : move in settings
$formatDate = 'Y-m-d';
// Date checking
if (isset($params['from']) || isset($params['to'])) {
if (!DateHelper::validateDate($formatDate, $params['from']) || !DateHelper::validateDate($formatDate, $params['to'])) {
throw new Exception("'from' date parameter or 'to' date parameter is not correct or missing.");
} else {
// pipe concatenation to set h-m-s at 00:00:00
$fromDate = DateTime::createFromFormat($formatDate . '|', $params['from']);
$toDate = DateTime::createFromFormat($formatDate . '|', $params['to']);
}
} else {
$fromDate = null;
$toDate = null;
}
$post = $dao->getPosts($author, $fromDate, $toDate);
$postResponse = ["posts" => $post, "count" => count($post)];
$response->getBody()->write(json_encode($postResponse, JSON_HEX_TAG | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE));
$response = $response->withHeader('Content-type', 'application/json');
return $response;
});
return $app;
}
示例2: testValidateGoodDate
public function testValidateGoodDate()
{
$format = 'Y-m-d';
$this->assertTrue(DateHelper::validateDate($format, '2016-02-28'));
}