Skip to content

Commit

Permalink
fixed DT-Object corresponding to wrong timezone #1388
Browse files Browse the repository at this point in the history
  • Loading branch information
hansmorb committed Oct 24, 2023
1 parent a43aed3 commit ab358a0
Showing 1 changed file with 4 additions and 3 deletions.
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

0 comments on commit ab358a0

Please sign in to comment.