From ef285e60757e930af741615464f1348662970629 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 12 Jul 2018 16:51:10 +0800 Subject: [PATCH] #210 Improve code for adding date strings to select --- element/date/classes/element.php | 39 +++++++++++++++++++------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/element/date/classes/element.php b/element/date/classes/element.php index a466ae3..bdbead9 100644 --- a/element/date/classes/element.php +++ b/element/date/classes/element.php @@ -260,23 +260,30 @@ class element extends \mod_customcert\element { $suffix = self::get_ordinal_number_suffix(userdate($date, '%d')); - $dateformats = array( + $dateformats = [ 1 => userdate($date, '%B %d, %Y'), - 2 => userdate($date, '%B %d' . $suffix . ', %Y'), - 'strftimedate' => userdate($date, get_string('strftimedate', 'langconfig')), - 'strftimedatefullshort' => userdate($date, get_string('strftimedatefullshort', 'langconfig')), - 'strftimedateshort' => userdate($date, get_string('strftimedateshort', 'langconfig')), - 'strftimedatetime' => userdate($date, get_string('strftimedatetime', 'langconfig')), - 'strftimedatetimeshort' => userdate($date, get_string('strftimedatetimeshort', 'langconfig')), - 'strftimedaydate' => userdate($date, get_string('strftimedaydate', 'langconfig')), - 'strftimedaydatetime' => userdate($date, get_string('strftimedaydatetime', 'langconfig')), - 'strftimedayshort' => userdate($date, get_string('strftimedayshort', 'langconfig')), - 'strftimedaytime' => userdate($date, get_string('strftimedaytime', 'langconfig')), - 'strftimemonthyear' => userdate($date, get_string('strftimemonthyear', 'langconfig')), - 'strftimerecent' => userdate($date, get_string('strftimerecent', 'langconfig')), - 'strftimerecentfull' => userdate($date, get_string('strftimerecentfull', 'langconfig')), - 'strftimetime' => userdate($date, get_string('strftimetime', 'langconfig')) - ); + 2 => userdate($date, '%B %d' . $suffix . ', %Y') + ]; + + $strdateformats = [ + 'strftimedate', + 'strftimedatefullshort', + 'strftimedateshort', + 'strftimedatetime', + 'strftimedatetimeshort', + 'strftimedaydate', + 'strftimedaydatetime', + 'strftimedayshort', + 'strftimedaytime', + 'strftimemonthyear', + 'strftimerecent', + 'strftimerecentfull', + 'strftimetime' + ]; + + foreach ($strdateformats as $strdateformat) { + $dateformats[$strdateformat] = userdate($date, get_string($strdateformat, 'langconfig')); + } return $dateformats; }