CFLib.org – Common Function Library Project

secondsToEnglish(iSeconds)

Last updated January 21, 2005

author

Peter Crowley

Version: 1 | Requires: CF5 | Library: DateLib

Description:
Converts seconds to nearest time unit in english rounding down.

Return Values:
Returns a string.

Example:

<cfoutput>
SecondsToEnglish(1) returns #SecondsToEnglish(1)#<br>
SecondsToEnglish(59) returns #SecondsToEnglish(59)#<br>
SecondsToEnglish(119) returns #SecondsToEnglish(119)#<br>
SecondsToEnglish(600) returns #SecondsToEnglish(600)#<br>
SecondsToEnglish(3600) returns #SecondsToEnglish(3600)#<br>
SecondsToEnglish(86400) returns #SecondsToEnglish(86400)#<br>
</cfoutput>

Parameters:

Name Description Required
iSeconds Number of seconds. Yes

Full UDF Source:

/**
 * Converts seconds to nearest time unit in english.
 * 
 * @param iSeconds 	 Number of seconds. (Required)
 * @return Returns a string. 
 * @author Peter Crowley (pcrowley@webzone.ie) 
 * @version 1, January 21, 2005 
 */
function secondsToEnglish(iSeconds) {
	var szPlural = "";
	var iTime = "";
	var szUpdate = "";
	
	if (iSeconds LTE 0) iSeconds=1;
	iTime=iSeconds \ 86400;
	if (iTime GT 0) {
		if (iTime GT 1) szPlural = 's';
		szUpdate = "#iTime# day#szPlural#";  // Days
	} else {
		iTime=iSeconds \ 3600;
		if (iTime GT 0) {
			if (iTime GT 1) szPlural = 's';
			szUpdate = "#iTime# hour#szPlural#"; // Hours
		} else {
			iTime=iSeconds \ 60;
			if (iTime GT 0) {
				if (iTime GT 1) szPlural = 's';
				szUpdate = "#iTime# minute#szPlural#"; // Minutes
			} else {
				iTime=iSeconds;
				if (iTime NEQ 1) szPlural = 's';
				szUpdate = "#iTime# second#szPlural#"; // Seconds
			}
		}
	}
	return szUpdate;
}
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