#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,22 +257,30 @@ 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) {
switch ($dateformat) { // Keeping for backwards compatibility.
case 1: if (is_number($dateformat)) {
$certificatedate = userdate($date, '%B %d, %Y'); switch ($dateformat) {
break; case 1:
case 2: $certificatedate = userdate($date, '%B %d, %Y');
$suffix = $this->get_ordinal_number_suffix(userdate($date, '%d')); break;
$certificatedate = userdate($date, '%B %d' . $suffix . ', %Y'); case 2:
break; $suffix = $this->get_ordinal_number_suffix(userdate($date, '%d'));
case 3: $certificatedate = userdate($date, '%B %d' . $suffix . ', %Y');
$certificatedate = userdate($date, '%d %B %Y'); break;
break; case 3:
case 4: $certificatedate = userdate($date, '%d %B %Y');
$certificatedate = userdate($date, '%B %Y'); break;
break; case 4:
default: $certificatedate = userdate($date, '%B %Y');
$certificatedate = userdate($date, get_string('strftimedate', 'langconfig')); break;
default:
$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;