Skip to content

Commit

Permalink
fix: only return formatted date if it's set (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ned Zimmerman authored Feb 27, 2020
1 parent f990f64 commit 30d77d7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions app/Controllers/Partials/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,21 @@ public static function getPublicationDate($format = false)
if (!$format) {
$format = get_option('date_format');
}
$y = get_post_meta($post->ID, 'lc_resource_publication_year', true);
$m = get_post_meta($post->ID, 'lc_resource_publication_month', true);
$d = get_post_meta($post->ID, 'lc_resource_publication_day', true);
return date_i18n(
$format,
strtotime(implode('-', [$y, $m, $d]))
);
$y = get_post_meta($post->ID, 'lc_resource_publication_year', true);
$m = get_post_meta($post->ID, 'lc_resource_publication_month', true);
$d = get_post_meta($post->ID, 'lc_resource_publication_day', true);
$pieces = [];
foreach ([$y, $m, $d] as $piece) {
if ($piece) {
$pieces[] = $piece;
}
}
$date = implode('-', $pieces);


if (!empty($pieces)) {
return date_i18n($format, strtotime($date));
}
}

return false;
Expand Down

0 comments on commit 30d77d7

Please sign in to comment.