Skip to content

Commit

Permalink
Merge pull request #13072 from aydun/core511_membership_dashboard
Browse files Browse the repository at this point in the history
dev/core#511 Fix wrong current month showing on Membership Dashboard
  • Loading branch information
eileenmcnaughton authored Nov 9, 2018
2 parents ffee3b9 + d2f262d commit 9467f0c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CRM/Member/Page/DashBoard.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public function preProcess() {

$this->assign('membershipSummary', $membershipSummary);
$this->assign('totalCount', $totalCount);
$this->assign('month', CRM_Utils_Date::customFormat($monthStartTs, '%B'));
$this->assign('month', CRM_Utils_Date::customFormatTs($monthStartTs, '%B'));
$this->assign('year', date('Y', $monthStartTs));
$this->assign('premonth', CRM_Utils_Date::customFormat($preMonth, '%B'));
$this->assign('currentMonth', date('F'));
Expand Down
17 changes: 17 additions & 0 deletions CRM/Utils/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,23 @@ public static function customFormat($dateString, $format = NULL, $dateParts = NU
}
}

/**
* Wrapper for customFormat that takes a timestamp
*
* @param int $timestamp
* Date and time in timestamp format.
* @param string $format
* The output format.
* @param array $dateParts
* An array with the desired date parts.
*
* @return string
* the $format-formatted $date
*/
public static function customFormatTs($timestamp, $format = NULL, $dateParts = NULL) {
return CRM_Utils_Date::customFormat(date("Y-m-d H:i:s", $timestamp), $format, $dateParts);
}

/**
* Converts the date/datetime from MySQL format to ISO format
*
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Member/Page/DashBoard.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<tr class="columnheader-dark">
<th scope="col" rowspan="2">{ts}Members by Type{/ts}</th>
{if $preMonth}
<th scope="col" colspan="3">{$premonth} &ndash; {ts}(Last Month){/ts}</th>
<th scope="col" colspan="3">{$premonth} {ts}(Last Month){/ts}</th>
{/if}
<th scope="col" colspan="3">{$month}{if $isCurrent}{ts} (MTD){/ts}{/if}</th>
<th scope="col" colspan="3">
Expand Down
44 changes: 44 additions & 0 deletions tests/phpunit/CRM/Utils/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,48 @@ public function testRelativeToAbsoluteFiscalYearRange() {
}
}

/**
* Test customFormat() function
*/
public function testCustomFormat() {
$dateTime = "2018-11-08 21:46:44";
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%b"), "Nov");
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%B"), "November");
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%d"), "08");
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%e"), " 8");
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%E"), "8");
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%f"), "th");
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%H"), "21");
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%I"), "09");
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%k"), "21");
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%l"), " 9");
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%m"), "11");
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%M"), "46");
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%p"), "pm");
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%P"), "PM");
$this->assertEquals(CRM_Utils_Date::customFormat($dateTime, "%Y"), "2018");
}

/**
* Test customFormat() function
*/
public function testCustomFormatTs() {
$ts = mktime(21, 46, 44, 11, 8, 2018);
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%b"), "Nov");
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%B"), "November");
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%d"), "08");
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%e"), " 8");
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%E"), "8");
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%f"), "th");
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%H"), "21");
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%I"), "09");
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%k"), "21");
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%l"), " 9");
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%m"), "11");
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%M"), "46");
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%p"), "pm");
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%P"), "PM");
$this->assertEquals(CRM_Utils_Date::customFormatTs($ts, "%Y"), "2018");
}

}

0 comments on commit 9467f0c

Please sign in to comment.