Skip to content

Commit

Permalink
MDL-62049 core_privacy: use correct lang string for date
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Apr 23, 2018
1 parent 20bf0c4 commit 63d1706
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion privacy/classes/local/request/transform.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function datetime($datetime) {
* @return string The translated string.
*/
public static function date($date) {
return userdate($date, get_string('strftimetime', 'langconfig'));
return userdate($date, get_string('strftimedate', 'langconfig'));
}

/**
Expand Down
27 changes: 25 additions & 2 deletions privacy/tests/request_transform_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,37 @@ public function test_user() {
* Test that the datetime is translated into a string.
*/
public function test_datetime() {
$this->assertInternalType('string', transform::datetime(1));
$time = 1;

$datestr = transform::datetime($time);

// Assert it is a string.
$this->assertInternalType('string', $datestr);

// To prevent failures on MAC where we are returned with a lower-case 'am' we want to convert this to 'AM'.
$datestr = str_replace('am', 'AM', $datestr);

// Assert the formatted date is correct.
$dateobj = new DateTime();
$dateobj->setTimestamp($time);
$this->assertEquals($dateobj->format('l, j F Y, g:i A'), $datestr);
}

/**
* Test that the date is translated into a string.
*/
public function test_date() {
$this->assertInternalType('string', transform::date(1));
$time = 1;

$datestr = transform::date($time);

// Assert it is a string.
$this->assertInternalType('string', $datestr);

// Assert the formatted date is correct.
$dateobj = new DateTime();
$dateobj->setTimestamp($time);
$this->assertEquals($dateobj->format('j F Y'), $datestr);
}

/**
Expand Down

0 comments on commit 63d1706

Please sign in to comment.