Skip to content

Commit c1776ff

Browse files
committed
Fix Client::getTime()
fixes #298
1 parent 382d1d4 commit c1776ff

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/Bigcommerce/Api/Client.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ public static function getCustomerLoginToken($id, $redirectUrl = '', $requestIp
474474
}
475475

476476
/**
477-
* Pings the time endpoint to test the connection to a store.
477+
* Pings the time endpoint to test the connection to the BigCommerce API.
478478
*
479479
* @return ?DateTime
480480
*/
@@ -486,7 +486,9 @@ public static function getTime()
486486
return null;
487487
}
488488

489-
return new DateTime("@{$response}");
489+
$seconds = floor($response / 1000);
490+
$microseconds = $response % 1000;
491+
return DateTime::createFromFormat('U.u', sprintf('%d.%03d', $seconds, $microseconds));
490492
}
491493

492494
/**

test/Unit/Api/ClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ public function testGetTimeReturnsTheExpectedTime()
210210
$this->connection->expects($this->once())
211211
->method('get')
212212
->with('https://api.bigcommerce.com/time', false)
213-
->will($this->returnValue($now->format('U')));
213+
->will($this->returnValue('1718283600000'));
214214

215-
$this->assertEquals($now->format('U'), Client::getTime()->format('U'));
215+
$this->assertEquals('2024-06-13 13:00:00', Client::getTime()->format('Y-m-d H:i:s'));
216216
}
217217

218218
public function testGetStoreReturnsTheResultBodyDirectly()

0 commit comments

Comments
 (0)