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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson