Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*---------------------------------------------------
- v0.2
- This function takes minutes as an input, and returns a
- readable string, fully formatted with plurals of words
- that need it. It should be easy to expand this to take
- seconds as input. If you need help, contact me on my
- website.
- Made by Mikkel Jeppesen from http://snuletek.org
- Please don't remove the above line, thanks and enjoy :)
- ---------------------------------------------------*/
- function minutesSplitter($minutes)
- {
- $daySingular = 'day';
- $dayPlural = 'days';
- $hourSingular = 'hour'; //Allows you to change the word used for the singularium of hour.
- $hourPlural = 'hours'; //Allows you to change the word used for the plural of hour.
- $minutePlural = 'minutes'; //Allows you to change the word used for the singularium of minute.
- $minuteSingular = 'minute'; //Allows you to change the word used for the plural of minute.
- $andStr = 'and'; //Allows you to change the word used to combine the hours and minutes string.
- $days = 0;
- $hours = 0;
- if($minutes > 59)
- {
- $hours = floor($minutes / 60);
- $minutes = $minutes % 60;
- }
- if($hours > 23)
- {
- $days = floor($hours / 24);
- $hours = $hours % 24;
- }
- if($days > 1)
- {
- $dayStr = $days.' '.$dayPlural;
- }
- else if($days = 1)
- {
- $dayStr = $days.' '.$daySingular;
- }
- else
- {
- $dayStr = '';
- }
- if($hours > 1)
- {
- $hourStr = $hours.' '.$hourPlural;
- }
- else if($hours = 1)
- {
- $hourStr = $hours.' '.$hourSingular;
- }
- else
- {
- $hourStr = '';
- }
- if($minutes > 1)
- {
- $minuteStr = $minutes. ' ' . $minutePlural;
- }
- else if($minutes = 1)
- {
- $minuteStr =$minutes. ' ' . $minuteSingular;
- }
- else if($minutes == 0 && !$hours)
- {
- $minuteStr =$minutes. ' ' . $minutePlural;
- }
- else
- {
- $minuteStr = '';
- }
- if($dayStr != '' && $hourStr != '')
- {
- $daysHoursComma = ', ';
- }
- else
- {
- $daysHoursComma = '';
- }
- if($hourStr != '' && $minutes != '')
- {
- $andStr =' '. $andStr .' ';
- }
- else
- {
- $andStr = '';
- }
- return $dayStr . $daysHoursComma . $hourStr . $andStr . $minuteStr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement