Skip to content

Commit

Permalink
refactor: rewritten Format::dateTimeReadable usages 2
Browse files Browse the repository at this point in the history
* Use Format::dateIntlReadable to replace all advance Format::dateTimeReadable
  usages.
* Add unit test for fidelity checks.
  • Loading branch information
yookoala committed Nov 21, 2023
1 parent c7255bf commit 82b5cf2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion modules/Attendance/attendance_future_byPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
}
});
$table->addColumn('staff', __('Recorded By'))->format(Format::using('name', ['', 'preferredName', 'surname', 'Staff', false, true]));
$table->addColumn('timestamp', __('On'))->format(Format::using('dateTimeReadable', 'timestampTaken', '%R, %b %d'));
$table->addColumn('timestamp', __('On'))->format(Format::using('dateIntlReadable', 'timestampTaken', 'HH:mm, MMM dd'));

$table->addActionColumn()
->addParam('gibbonPersonID', $gibbonPersonIDList[0] ?? '')
Expand Down
4 changes: 2 additions & 2 deletions modules/Attendance/attendance_take_byPerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@
if (empty($log['timestampTaken'])) return Format::small(__('N/A'));

return $currentDate != substr($log['timestampTaken'], 0, 10)
? Format::dateTimeReadable($log['timestampTaken'], '%H:%M, %b %d')
: Format::dateTimeReadable($log['timestampTaken'], '%H:%M');
? Format::dateIntlReadable($log['timestampTaken'], 'HH:mm, MMM dd')
: Format::dateIntlReadable($log['timestampTaken'], 'HH:mm');
});

$table->addColumn('direction', __('Attendance'))
Expand Down
4 changes: 2 additions & 2 deletions modules/Students/firstAidRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@
$output = '';
if ($person['description'] != '') $output .= '<b>'.__('Description').'</b><br/>'.nl2br($person['description']).'<br/><br/>';
if ($person['actionTaken'] != '') $output .= '<b>'.__('Action Taken').'</b><br/>'.nl2br($person['actionTaken']).'<br/><br/>';
if ($person['followUp'] != '') $output .= '<b>'.__("Follow Up by {name} at {date}", ['name' => Format::name('', $person['preferredNameFirstAider'], $person['surnameFirstAider']), 'date' => Format::dateTimeReadable($person['timestamp'], '%H:%M, %b %d %Y')]).'</b><br/>'.nl2br($person['followUp']).'<br/><br/>';
if ($person['followUp'] != '') $output .= '<b>'.__("Follow Up by {name} at {date}", ['name' => Format::name('', $person['preferredNameFirstAider'], $person['surnameFirstAider']), 'date' => Format::dateIntlReadable($person['timestamp'], 'HH:mm, MMM dd yyyy')]).'</b><br/>'.nl2br($person['followUp']).'<br/><br/>';
$resultLog = $firstAidGateway->queryFollowUpByFirstAidID($person['gibbonFirstAidID']);
foreach ($resultLog AS $rowLog) {
$output .= '<b>'.__("Follow Up by {name} at {date}", ['name' => Format::name('', $rowLog['preferredName'], $rowLog['surname']), 'date' => Format::dateTimeReadable($rowLog['timestamp'], '%H:%M, %b %d %Y')]).'</b><br/>'.nl2br($rowLog['followUp']).'<br/><br/>';
$output .= '<b>'.__("Follow Up by {name} at {date}", ['name' => Format::name('', $rowLog['preferredName'], $rowLog['surname']), 'date' => Format::dateIntlReadable($rowLog['timestamp'], 'HH:mm, MMM dd yyyy')]).'</b><br/>'.nl2br($rowLog['followUp']).'<br/><br/>';
}

return $output;
Expand Down
4 changes: 2 additions & 2 deletions modules/Students/firstAidRecord_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
if ($gibbonFirstAidID == '') {
$page->addError(__('You have not specified one or more required parameters.'));
} else {

$data = array('gibbonSchoolYearID' => $session->get('gibbonSchoolYearID'), 'gibbonFirstAidID' => $gibbonFirstAidID);
$sql = "SELECT gibbonFirstAid.*, patient.gibbonPersonID AS gibbonPersonIDPatient, patient.surname AS surnamePatient, patient.preferredName AS preferredNamePatient, firstAider.title, firstAider.surname AS surnameFirstAider, firstAider.preferredName AS preferredNameFirstAider
FROM gibbonFirstAid
Expand Down Expand Up @@ -124,7 +124,7 @@
if (!empty($values['followUp'])) {
$row = $form->addRow();
$column = $row->addColumn();
$column->addLabel('followUp0', __("Follow Up by {name} at {date}", ['name' => Format::name('', $values['preferredNameFirstAider'], $values['surnameFirstAider']), 'date' => Format::dateTimeReadable($values['timestamp'], '%H:%M, %b %d %Y')]));
$column->addLabel('followUp0', __("Follow Up by {name} at {date}", ['name' => Format::name('', $values['preferredNameFirstAider'], $values['surnameFirstAider']), 'date' => Format::dateIntlReadable($values['timestamp'], 'HH:mm, MMM dd yyyy')]));
$column->addContent($values['followUp'])->setClass('fullWidth');
}

Expand Down
15 changes: 15 additions & 0 deletions tests/unit/Services/FormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ public function testFormatsReadableDates()
// Note: %e has a leading space for single digit days, but cannot do the same with intl date formats.
$this->assertEquals('Sat 3 Feb, 2018', Format::dateReadable($dateString, '%a %e %b, %Y'));
$this->assertEquals('Sat 3 Feb, 2018', Format::dateIntlReadable($dateString, 'EEE d MMM, yyyy'));

// modules/Attendance/attendance_future_byPerson.php
// modules/Attendance/attendance_take_byPerson.php
$this->assertEquals('13:24, Feb 03', Format::dateTimeReadable($dateString, '%R, %b %d'));
$this->assertEquals('13:24, Feb 03', Format::dateTimeReadable($dateString, '%H:%M, %b %d'));
$this->assertEquals('13:24, Feb 03', Format::dateIntlReadable($dateString, 'HH:mm, MMM dd'));

// modules/Students/firstAidRecord_edit.php
// modules/Students/firstAidRecord.php
$this->assertEquals('13:24, Feb 03 2018', Format::dateTimeReadable($dateString, '%H:%M, %b %d %Y'));
$this->assertEquals('13:24, Feb 03 2018', Format::dateIntlReadable($dateString, 'HH:mm, MMM dd yyyy'));

// modules/Attendance/attendance_take_byPerson.php
$this->assertEquals('13:24', Format::dateTimeReadable($dateString, '%H:%M'));
$this->assertEquals('13:24', Format::dateIntlReadable($dateString, 'HH:mm'));
}

public function testFormatsDateRanges()
Expand Down

0 comments on commit 82b5cf2

Please sign in to comment.