door: fix data extraction

This commit is contained in:
2026-01-13 08:34:59 +09:00
parent 16c9b610ce
commit 044444eaa8
2 changed files with 7 additions and 3 deletions

View File

@@ -39,7 +39,7 @@ class Door {
$query
= 'SELECT time, open FROM door WHERE time > :startTime ORDER BY time DESC';
$statement = $this->pdo->prepare($query);
$statement->bindParam(':startTime', $startTime, \PDO::PARAM_STR);
$statement->bindParam(':startTime', $startTime->getTimestamp(), \PDO::PARAM_INT);
$statement->execute();
$doorEvents = [];

View File

@@ -31,9 +31,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$period = (string) htmlspecialchars($_GET['period']);
if ($period == 'day') {
$startTime = time() - (60 * 60 * 24);
$startTime = (new \DateTimeImmutable())
->setTimestamp(time())
->sub(new \DateInterval('P1D'));
} elseif ($period == 'week') {
$startTime = time() - (60 * 60 * 24 * 7);
$startTime = (new \DateTimeImmutable())
->setTimestamp(time())
->sub(new \DateInterval('P1W'));
} else {
echo '{"status": "error", "message": "Invalid period"}';
exit;