CFLib.org – Common Function Library Project

QuarterHour(minutes)

Last updated September 23, 2004

author

Dave Babbitt

Version: 1 | Requires: CF5 | Library: DateLib

Description:
Given the number of minutes to be converted,it returns a string with a mixed fraction of fourths of an hour.

Return Values:
Returns a string.

Example:

I've been working for #QuarterHour(132)# hours already today!

Parameters:

Name Description Required
minutes The number of minutes. Yes

Full UDF Source:

/**
 * Returns a string with a mixed fraction of quarters.
 * 
 * @param minutes      The number of minutes. (Required)
 * @return Returns a string. 
 * @author Dave Babbitt (dave@babbitt.org) 
 * @version 1, September 23, 2004 
 */
function QuarterHour(minutes) {
    var mixedFraction = "";
    var hours = 0;
    var quarterHours = 0;
    
    /* Get hours and let minutes be the remainder */
    hours = Int(minutes/60);
    minutes = minutes - hours*60;

    /* 15 minutes is a "quarter hour" - round up to the nearest one */
    quarterHours = Round(minutes/15);
    if(quarterHours GTE 4) {
        quarterHours = 0;
        hours = IncrementValue(hours);
    }

    /* Build the mixed fraction */
    if(quarterHours GT 0) {
        if(quarterHours EQ 2) mixedFraction = ' 1/2';
        else mixedFraction = ' ' & quarterHours & '/4';
    } else mixedFraction = '';

    mixedFraction = hours & mixedFraction;
    return mixedFraction;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson