Skip to content

Commit

Permalink
fix: format of last_updated, wp is picky (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckadams authored Feb 15, 2025
1 parent 1fa094e commit 190415b
Showing 1 changed file with 13 additions and 2 deletions.
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);
}
}

0 comments on commit 190415b

Please sign in to comment.