Replaced "api_date"

This commit is contained in:
Michael 2021-11-18 21:43:13 +00:00
parent 2d5989a6bd
commit 1f79d25ffc
5 changed files with 9 additions and 20 deletions

View file

@ -103,19 +103,6 @@ function api_source()
return "api"; return "api";
} }
/**
* Format date for API
*
* @param string $str Source date, as UTC
* @return string Date in UTC formatted as "D M d H:i:s +0000 Y"
* @throws Exception
*/
function api_date($str)
{
// Wed May 23 06:01:13 +0000 2007
return DateTimeFormat::utc($str, "D M d H:i:s +0000 Y");
}
/** /**
* Register a function to be the endpoint for defined API path. * Register a function to be the endpoint for defined API path.
* *
@ -288,7 +275,7 @@ function api_rss_extra($arr, $user_info)
'alternate' => $user_info['url'], 'alternate' => $user_info['url'],
'self' => DI::baseUrl() . "/" . DI::args()->getQueryString(), 'self' => DI::baseUrl() . "/" . DI::args()->getQueryString(),
'base' => DI::baseUrl(), 'base' => DI::baseUrl(),
'updated' => api_date(null), 'updated' => DateTimeFormat::utc(null, DateTimeFormat::API),
'atom_updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), 'atom_updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
'language' => $user_info['lang'], 'language' => $user_info['lang'],
'logo' => DI::baseUrl() . "/images/friendica-32.png", 'logo' => DI::baseUrl() . "/images/friendica-32.png",
@ -1925,7 +1912,7 @@ function api_format_messages($item, $recipient, $sender)
'sender_id' => $sender['id'], 'sender_id' => $sender['id'],
'text' => "", 'text' => "",
'recipient_id' => $recipient['id'], 'recipient_id' => $recipient['id'],
'created_at' => api_date($item['created'] ?? DateTimeFormat::utcNow()), 'created_at' => DateTimeFormat::utc($item['created'] ?? DateTimeFormat::utcNow(), DateTimeFormat::API),
'sender_screen_name' => $sender['screen_name'], 'sender_screen_name' => $sender['screen_name'],
'recipient_screen_name' => $recipient['screen_name'], 'recipient_screen_name' => $recipient['screen_name'],
'sender' => $sender, 'sender' => $sender,
@ -2459,7 +2446,7 @@ function api_format_item($item, $type = "json", $status_user = null, $author_use
$status = [ $status = [
'text' => $converted["text"], 'text' => $converted["text"],
'truncated' => false, 'truncated' => false,
'created_at'=> api_date($item['created']), 'created_at'=> DateTimeFormat::utc($item['created'], DateTimeFormat::API),
'in_reply_to_status_id' => $in_reply_to['status_id'], 'in_reply_to_status_id' => $in_reply_to['status_id'],
'in_reply_to_status_id_str' => $in_reply_to['status_id_str'], 'in_reply_to_status_id_str' => $in_reply_to['status_id_str'],
'source' => (($item['app']) ? $item['app'] : 'web'), 'source' => (($item['app']) ? $item['app'] : 'web'),
@ -2558,7 +2545,7 @@ function api_format_item($item, $type = "json", $status_user = null, $author_use
$retweeted_status['text'] = $rt_converted["text"]; $retweeted_status['text'] = $rt_converted["text"];
$retweeted_status['statusnet_html'] = $rt_converted["html"]; $retweeted_status['statusnet_html'] = $rt_converted["html"];
$retweeted_status['friendica_html'] = $rt_converted["html"]; $retweeted_status['friendica_html'] = $rt_converted["html"];
$retweeted_status['created_at'] = api_date($retweeted_item['created']); $retweeted_status['created_at'] = DateTimeFormat::utc($retweeted_item['created'], DateTimeFormat::API);
if (!empty($quoted_status)) { if (!empty($quoted_status)) {
$retweeted_status['quoted_status'] = $quoted_status; $retweeted_status['quoted_status'] = $quoted_status;

View file

@ -48,7 +48,7 @@ class RateLimitStatus extends BaseApi
'reset_time_in_seconds' => strtotime('now + 1 hour'), 'reset_time_in_seconds' => strtotime('now + 1 hour'),
'remaining_hits' => '150', 'remaining_hits' => '150',
'hourly_limit' => '150', 'hourly_limit' => '150',
'reset_time' => api_date(DateTimeFormat::utc('now + 1 hour', DateTimeFormat::ATOM)), 'reset_time' => DateTimeFormat::utc('now + 1 hour', DateTimeFormat::API),
]; ];
} }

View file

@ -26,6 +26,7 @@ use Friendica\Content\ContactSelector;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Proxy; use Friendica\Util\Proxy;
/** /**
@ -124,7 +125,7 @@ class User extends BaseDataTransferObject
$this->followers_count = $apcontact['followers_count'] ?? 0; $this->followers_count = $apcontact['followers_count'] ?? 0;
$this->friends_count = $apcontact['following_count'] ?? 0; $this->friends_count = $apcontact['following_count'] ?? 0;
$this->listed_count = 0; $this->listed_count = 0;
$this->created_at = api_date($publicContact['created']); $this->created_at = DateTimeFormat::utc($publicContact['created'], DateTimeFormat::API);
$this->favourites_count = 0; $this->favourites_count = 0;
$this->verified = $uid != 0; $this->verified = $uid != 0;
$this->statuses_count = $apcontact['statuses_count'] ?? 0; $this->statuses_count = $apcontact['statuses_count'] ?? 0;

View file

@ -35,6 +35,7 @@ class DateTimeFormat
const MYSQL = 'Y-m-d H:i:s'; const MYSQL = 'Y-m-d H:i:s';
const HTTP = 'D, d M Y H:i:s \G\M\T'; const HTTP = 'D, d M Y H:i:s \G\M\T';
const JSON = 'Y-m-d\TH:i:s.v\Z'; const JSON = 'Y-m-d\TH:i:s.v\Z';
const API = 'D M d H:i:s +0000 Y';
static $localTimezone = 'UTC'; static $localTimezone = 'UTC';

View file

@ -275,7 +275,7 @@ class ApiTest extends FixtureTest
*/ */
public function testApiDate() public function testApiDate()
{ {
self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', api_date('1990-10-10')); self::assertEquals('Wed Oct 10 00:00:00 +0000 1990', DateTimeFormat::utc('1990-10-10', DateTimeFormat::API));
} }
/** /**