Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GBFS API: fixed wrong timezone used #1389

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/API/GBFS/StationStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace CommonsBooking\API\GBFS;


use CommonsBooking\Helper\Wordpress;
use CommonsBooking\Model\Calendar;
use CommonsBooking\Model\Day;
use CommonsBooking\Model\Location;
Expand Down Expand Up @@ -58,7 +59,7 @@ public function prepare_item_for_response( $item, $request ): stdClass {
*/
private function getItemCountAtLocation($locationId){
$items = Item::getByLocation($locationId,true);
$nowDT = new \DateTime();
$nowDT = Wordpress::getUTCDateTime('now');
$availableCounter = 0;
foreach ($items as $item){
//we have to make our calendar span at least one day, otherwise we get no results
Expand All @@ -72,8 +73,8 @@ private function getItemCountAtLocation($locationId){
//we have to iterate over multiple slots because the calendar will give us more than we asked for
foreach ($availabilitySlots as $availabilitySlot){
//match our exact current time to the slot
$startDT = new \DateTime($availabilitySlot->start);
$endDT = new \DateTime($availabilitySlot->end);
$startDT = Wordpress::getUTCDateTime( $availabilitySlot->start );
$endDT = Wordpress::getUTCDateTime( $availabilitySlot->end );
if ($nowDT >= $startDT && $nowDT <= $endDT){
$availableCounter++;
//break out of the loop, we only need one match of availability per item
Expand Down