Change timestamp to be DateTime object not integers in Mastodon Timeline API

This commit is contained in:
Hank Grabowski 2023-02-28 08:20:08 -05:00
parent 6ffd3a3f8c
commit 1adb23d8fd
2 changed files with 13 additions and 15 deletions

View file

@ -112,7 +112,7 @@ class BaseApi extends BaseModule
* @return array paging data condition parameters data
* @throws \Exception
*/
public function addPagingConditions(array $request, array $condition): array
protected function addPagingConditions(array $request, array $condition): array
{
$requested_order = $request['friendica_order'];
if ($requested_order == TimelineOrderByTypes::ID) {
@ -159,7 +159,7 @@ class BaseApi extends BaseModule
* @return array ordering data added to the params blocks that was passed in
* @throws \Exception
*/
public function buildOrderAndLimitParams(array $request, array $params = []): array
protected function buildOrderAndLimitParams(array $request, array $params = []): array
{
$requested_order = $request['friendica_order'];
switch ($requested_order) {
@ -171,7 +171,7 @@ class BaseApi extends BaseModule
$order_field = 'uri-id';
}
if(!empty($request['min_id'])) {
if (!empty($request['min_id'])) {
$params['order'] = [$order_field];
} else {
$params['order'] = [$order_field => true];
@ -204,9 +204,9 @@ class BaseApi extends BaseModule
/**
* Set boundaries for the "link" header
* @param array $boundaries
* @param int $id
* @param int|\DateTime $id
*/
protected static function setBoundaries(int $id)
protected static function setBoundaries($id)
{
if (!isset(self::$boundaries['min'])) {
self::$boundaries['min'] = $id;
@ -239,10 +239,8 @@ class BaseApi extends BaseModule
$prev_request = $next_request = $request;
if ($asDate) {
$max_date = new DateTime();
$max_date->setTimestamp(self::$boundaries['max']);
$min_date = new DateTime();
$min_date->setTimestamp(self::$boundaries['min']);
$max_date = self::$boundaries['max'];
$min_date = self::$boundaries['min'];
$prev_request['min_id'] = $max_date->format(DateTimeFormat::JSON);
$next_request['max_id'] = $min_date->format(DateTimeFormat::JSON);
} else {

View file

@ -156,12 +156,12 @@ class Status extends BaseDataTransferObject
/**
* Returns the current created_at DateTime as an integer timestamp
* @return int
* @return \DateTime
* @throws \Exception
*/
public function createdAtTimestamp(): int
public function createdAtTimestamp(): \DateTime
{
$result = strtotime($this->created_at);
$result = new \DateTime($this->created_at);
if (!$result) {
throw new \Exception('Unknown date-time format');
}