Add airing date range to anime detail pages

This commit is contained in:
Timothy Warren 2021-10-08 19:31:40 -04:00
parent 1cb880f785
commit cfc6324971
4 changed files with 61 additions and 0 deletions

View File

@ -17,6 +17,13 @@ use function Aviat\AnimeClient\getLocalImg;
<td><?= $data['status'] ?></td>
</tr>
<?php if ( ! empty($data['airDate'])): ?>
<tr>
<td>Original Airing</td>
<td><?= $data['airDate'] ?></td>
</tr>
<?php endif ?>
<tr>
<td>Show Type</td>
<td><?= (strlen($data['show_type']) > 3) ? ucfirst(strtolower($data['show_type'])) : $data['show_type'] ?></td>

View File

@ -121,6 +121,7 @@ final class AnimeTransformer extends AbstractTransformer {
}
return AnimePage::from([
'airDate' => Kitsu::formatAirDates($base['startDate'], $base['endDate']),
'age_rating' => $base['ageRating'],
'age_rating_guide' => $base['ageRatingGuide'],
'characters' => $characters,

View File

@ -68,6 +68,57 @@ final class Kitsu {
return AnimeAiringStatus::NOT_YET_AIRED;
}
/**
* Reformat the airing date range for an Anime
*
* @param string|null $startDate
* @param string|null $endDate
* @return string
*/
public static function formatAirDates(string $startDate = NULL, string $endDate = NULL): string
{
if (empty($startDate))
{
return '';
}
$monthMap = [
'01' => 'Jan',
'02' => 'Feb',
'03' => 'Mar',
'04' => 'Apr',
'05' => 'May',
'06' => 'Jun',
'07' => 'Jul',
'08' => 'Aug',
'09' => 'Sep',
'10' => 'Oct',
'11' => 'Nov',
'12' => 'Dec',
];
[$startYear, $startMonth, $startDay] = explode('-', $startDate);
if ($startDate === $endDate)
{
return "{$monthMap[$startMonth]} $startDay, $startYear";
}
if (empty($endDate))
{
return "{$monthMap[$startMonth]} {$startYear} - ";
}
[$endYear, $endMonth] = explode('-', $endDate);
if ($startYear === $endYear)
{
return "{$monthMap[$startMonth]} - {$monthMap[$endMonth]} $startYear";
}
return "{$monthMap[$startMonth]} {$startYear} - {$monthMap[$endMonth]} {$endYear}";
}
public static function getPublishingStatus(string $kitsuStatus, string $startDate = NULL, string $endDate = NULL): string
{
$startPubDate = new DateTimeImmutable($startDate ?? 'tomorrow');

View File

@ -25,4 +25,6 @@ final class AnimePage extends Anime {
public array $links = [];
public array $staff = [];
public ?string $airDate = '';
}