Created
August 30, 2018 17:09
-
-
Save bwente/75cacfad980e52eb2f0b3077678ddc17 to your computer and use it in GitHub Desktop.
MODX output filter to convert months to years
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$years = floor($input/12); | |
$months = $input%12; | |
$yearsDisplay = $years.($years > 1 ? ' years' : ' year'); | |
if($years == 0) { | |
$yearsDisplay = ''; | |
} | |
$monthsDisplay = $months.($months > 1 ? ' months' : ' month'); | |
if($months == 0) { | |
$monthsDisplay = ''; | |
} | |
$output = $yearsDisplay . ($years > 0 && $months > 0 ? ', ' : ' ') . $monthsDisplay; | |
return $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment