From 1f79d25ffcef2a740453f0d69f57223c03a50b79 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 18 Nov 2021 21:43:13 +0000 Subject: [PATCH] Replaced "api_date" --- include/api.php | 21 ++++--------------- .../Api/Twitter/Account/RateLimitStatus.php | 2 +- src/Object/Api/Twitter/User.php | 3 ++- src/Util/DateTimeFormat.php | 1 + tests/legacy/ApiTest.php | 2 +- 5 files changed, 9 insertions(+), 20 deletions(-) diff --git a/include/api.php b/include/api.php index 0536e7a75..929900f49 100644 --- a/include/api.php +++ b/include/api.php @@ -103,19 +103,6 @@ function api_source() 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. * @@ -288,7 +275,7 @@ function api_rss_extra($arr, $user_info) 'alternate' => $user_info['url'], 'self' => DI::baseUrl() . "/" . DI::args()->getQueryString(), 'base' => DI::baseUrl(), - 'updated' => api_date(null), + 'updated' => DateTimeFormat::utc(null, DateTimeFormat::API), 'atom_updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM), 'language' => $user_info['lang'], 'logo' => DI::baseUrl() . "/images/friendica-32.png", @@ -1925,7 +1912,7 @@ function api_format_messages($item, $recipient, $sender) 'sender_id' => $sender['id'], 'text' => "", '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'], 'recipient_screen_name' => $recipient['screen_name'], 'sender' => $sender, @@ -2459,7 +2446,7 @@ function api_format_item($item, $type = "json", $status_user = null, $author_use $status = [ 'text' => $converted["text"], '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_str' => $in_reply_to['status_id_str'], '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['statusnet_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)) { $retweeted_status['quoted_status'] = $quoted_status; diff --git a/src/Module/Api/Twitter/Account/RateLimitStatus.php b/src/Module/Api/Twitter/Account/RateLimitStatus.php index e38ffb061..9a275cecb 100644 --- a/src/Module/Api/Twitter/Account/RateLimitStatus.php +++ b/src/Module/Api/Twitter/Account/RateLimitStatus.php @@ -48,7 +48,7 @@ class RateLimitStatus extends BaseApi 'reset_time_in_seconds' => strtotime('now + 1 hour'), 'remaining_hits' => '150', 'hourly_limit' => '150', - 'reset_time' => api_date(DateTimeFormat::utc('now + 1 hour', DateTimeFormat::ATOM)), + 'reset_time' => DateTimeFormat::utc('now + 1 hour', DateTimeFormat::API), ]; } diff --git a/src/Object/Api/Twitter/User.php b/src/Object/Api/Twitter/User.php index 8972d7583..75263e9b7 100644 --- a/src/Object/Api/Twitter/User.php +++ b/src/Object/Api/Twitter/User.php @@ -26,6 +26,7 @@ use Friendica\Content\ContactSelector; use Friendica\Content\Text\BBCode; use Friendica\Core\Protocol; use Friendica\Model\Contact; +use Friendica\Util\DateTimeFormat; use Friendica\Util\Proxy; /** @@ -124,7 +125,7 @@ class User extends BaseDataTransferObject $this->followers_count = $apcontact['followers_count'] ?? 0; $this->friends_count = $apcontact['following_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->verified = $uid != 0; $this->statuses_count = $apcontact['statuses_count'] ?? 0; diff --git a/src/Util/DateTimeFormat.php b/src/Util/DateTimeFormat.php index cf3216a15..141fa37f6 100644 --- a/src/Util/DateTimeFormat.php +++ b/src/Util/DateTimeFormat.php @@ -35,6 +35,7 @@ class DateTimeFormat const MYSQL = 'Y-m-d H:i:s'; const HTTP = 'D, d M Y H:i:s \G\M\T'; const JSON = 'Y-m-d\TH:i:s.v\Z'; + const API = 'D M d H:i:s +0000 Y'; static $localTimezone = 'UTC'; diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index a63daee93..f4ac58d04 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -275,7 +275,7 @@ class ApiTest extends FixtureTest */ 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)); } /**