Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix format of Plugin::last_updated #165

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions app/Http/Resources/Plugins/PluginResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace App\Http\Resources\Plugins;

use App\Models\WpOrg\Plugin;
use DateTimeInterface;
use Illuminate\Http\Request;

class PluginResource extends BasePluginResource
{
public const LAST_UPDATED_DATE_FORMAT = 'Y-m-d H:ia T'; // .org's goofy format: "2024-09-27 9:53pm GMT"
public const LAST_UPDATED_DATE_FORMAT = 'Y-m-d h:ia T'; // .org's goofy format: "2024-09-27 9:53pm GMT"

/**
* Transform the resource into an array.
Expand All @@ -28,7 +29,7 @@ public function toArray(Request $request): array
'support_threads' => $plugin->support_threads,
'support_threads_resolved' => $plugin->support_threads_resolved,
'active_installs' => $plugin->active_installs,
'last_updated' => $plugin->last_updated?->format(self::LAST_UPDATED_DATE_FORMAT),
'last_updated' => self::formatLastUpdated($plugin->last_updated),
'added' => $plugin->added->format('Y-m-d'),
'homepage' => $plugin->homepage,
'tags' => $plugin->tagsArray(),
Expand Down Expand Up @@ -59,4 +60,14 @@ public function toArray(Request $request): array
default => $data,
};
}

private static function formatLastUpdated(?DateTimeInterface $lastUpdated): ?string
{
if ($lastUpdated === null) {
return null;
}
$out = $lastUpdated->format(self::LAST_UPDATED_DATE_FORMAT);
// Unfortunately this seems to render GMT as "GMT+0000" for some reason, so strip that out
return \Safe\preg_replace('/\+\d+$/', '', $out);
}
}