From 3f881ab1f53e757f509008bc892a8491c2b24aa1 Mon Sep 17 00:00:00 2001 From: ebremner <ebremner@uwaterloo.ca> Date: Tue, 8 Dec 2020 15:21:03 -0500 Subject: [PATCH] ISTWCMS-4212: adding function to get correct short month name --- src/Service/UWService.php | 42 +++++++++++++++++++++++++++--- src/Service/UWServiceInterface.php | 12 +++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/Service/UWService.php b/src/Service/UWService.php index 362e36d1..94d06d24 100644 --- a/src/Service/UWService.php +++ b/src/Service/UWService.php @@ -117,10 +117,17 @@ class UWService implements UWServiceInterface { // field_uw_<content_type>_date. $field_name = 'field_uw_' . trim($teaser_type) . '_date'; - // Set the date variable, once returned to the calling function, they - // can change the date format as required (i.e. change it to long-date - // or date-time). - $variables['date'] = $node->$field_name->getString(); + if (trim($teaser_type) == 'event') { + $variables['date'] = $node->$field_name->getValue(); + } + else { + + // Set the date variable, once returned to the calling function, they + // can change the date format as required (i.e. change it to long-date + // or date-time). + $variables['date'] = $node->$field_name->getString(); + } + break; case 'author': @@ -368,4 +375,31 @@ class UWService implements UWServiceInterface { } } + /** + * {@inheritDoc} + */ + public function uwMonthNameShort(int $month = NULL) { + + static $months = [ + 1 => 'Jan.', + 2 => 'Feb.', + 3 => 'Mar.', + 4 => 'Apr.', + 5 => 'May', + 6 => 'June', + 7 => 'July', + 8 => 'Aug.', + 9 => 'Sep.', + 10 => 'Oct.', + 11 => 'Nov.', + 12 => 'Dec.', + ]; + if ($month) { + return $months[$month]; + } + else { + return $months; + } + } + } diff --git a/src/Service/UWServiceInterface.php b/src/Service/UWServiceInterface.php index ba589055..93714b1b 100644 --- a/src/Service/UWServiceInterface.php +++ b/src/Service/UWServiceInterface.php @@ -147,4 +147,16 @@ interface UWServiceInterface { */ public function uwCountMenuItems(array $menu, int &$menu_items_count): void; + /** + * A function to return the month short name. + * + * @param int $month + * An integer of the month. + * + * @return mixed + * A mixed variable that will either be a string of the short + * month with a period or array of all short months. + */ + public function uwMonthNameShort(int $month = NULL); + } -- GitLab