From 5f80f246cb88d19ae56499c2cd6cb365dfc360a9 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Fri, 13 Jul 2018 12:17:35 +0800 Subject: [PATCH] #210 Allow short dates with leading zeros --- element/date/classes/element.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/element/date/classes/element.php b/element/date/classes/element.php index bdbead9..e03e655 100644 --- a/element/date/classes/element.php +++ b/element/date/classes/element.php @@ -256,7 +256,9 @@ class element extends \mod_customcert\element { * @return array the list of date formats */ public static function get_date_formats() { - $date = time(); + // Hard-code date so users can see the difference between short dates with and without the leading zero. + // Eg. 06/07/18 vs 6/07/18. + $date = 1530849658; $suffix = self::get_ordinal_number_suffix(userdate($date, '%d')); @@ -268,9 +270,11 @@ class element extends \mod_customcert\element { $strdateformats = [ 'strftimedate', 'strftimedatefullshort', + 'strftimedatefullshortwleadingzero', 'strftimedateshort', 'strftimedatetime', 'strftimedatetimeshort', + 'strftimedatetimeshortwleadingzero', 'strftimedaydate', 'strftimedaydatetime', 'strftimedayshort', @@ -282,7 +286,13 @@ class element extends \mod_customcert\element { ]; foreach ($strdateformats as $strdateformat) { - $dateformats[$strdateformat] = userdate($date, get_string($strdateformat, 'langconfig')); + if ($strdateformat == 'strftimedatefullshortwleadingzero') { + $dateformats[$strdateformat] = userdate($date, get_string('strftimedatefullshort', 'langconfig'), 99, false); + } else if ($strdateformat == 'strftimedatetimeshortwleadingzero') { + $dateformats[$strdateformat] = userdate($date, get_string('strftimedatetimeshort', 'langconfig'), 99, false); + } else { + $dateformats[$strdateformat] = userdate($date, get_string($strdateformat, 'langconfig')); + } } return $dateformats; @@ -319,7 +329,13 @@ class element extends \mod_customcert\element { // Ok, so we must have been passed the actual format in the lang file. if (!isset($certificatedate)) { - $certificatedate = userdate($date, get_string($dateformat, 'langconfig')); + if ($dateformat == 'strftimedatefullshortwleadingzero') { + $certificatedate = userdate($date, get_string('strftimedatefullshort', 'langconfig'), 99, false); + } else if ($dateformat == 'strftimedatetimeshortwleadingzero') { + $certificatedate = userdate($date, get_string('strftimedatetimeshort', 'langconfig'), 99, false); + } else { + $certificatedate = userdate($date, get_string($dateformat, 'langconfig')); + } } return $certificatedate;