#30 Add more date formats

This commit is contained in:
Mark Nelson 2017-06-01 16:51:50 +08:00
parent 84610ea418
commit a17bb41307

View file

@ -228,12 +228,23 @@ class element extends \mod_customcert\element {
* @return array the list of date formats * @return array the list of date formats
*/ */
public static function get_date_formats() { public static function get_date_formats() {
$dateformats = array(); $date = time();
$dateformats[1] = 'January 1, 2000';
$dateformats[2] = 'January 1st, 2000'; $dateformats = array(
$dateformats[3] = '1 January 2000'; 'strftimedate' => userdate($date, get_string('strftimedate', 'langconfig')),
$dateformats[4] = 'January 2000'; 'strftimedatefullshort' => userdate($date, get_string('strftimedatefullshort', 'langconfig')),
$dateformats[5] = get_string('userdateformat', 'customcertelement_date'); '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'))
);
return $dateformats; return $dateformats;
} }
@ -246,6 +257,8 @@ class element extends \mod_customcert\element {
* @return string * @return string
*/ */
protected function get_date_format_string($date, $dateformat) { protected function get_date_format_string($date, $dateformat) {
// Keeping for backwards compatibility.
if (is_number($dateformat)) {
switch ($dateformat) { switch ($dateformat) {
case 1: case 1:
$certificatedate = userdate($date, '%B %d, %Y'); $certificatedate = userdate($date, '%B %d, %Y');
@ -263,6 +276,12 @@ class element extends \mod_customcert\element {
default: default:
$certificatedate = userdate($date, get_string('strftimedate', 'langconfig')); $certificatedate = userdate($date, get_string('strftimedate', 'langconfig'));
} }
}
// Ok, so we must have been passed the actual format in the lang file.
if (!isset($certificatedate)) {
$certificatedate = userdate($date, get_string($dateformat, 'langconfig'));
}
return $certificatedate; return $certificatedate;
} }