CFLib.org – Common Function Library Project

utcOffsetToMinutes(offset)

Last updated January 8, 2015

author

Mosh Teitelbaum

Version: 1 | Requires: CF10 | Library: DateLib

Description:
Converts UTC Offset to minutes.

Return Values:
Returns a number.

Example:

<cfoutput>
#utcOffsetToMinutes("UTC-05:00")# = -300<br />
#utcOffsetToMinutes("UTC+0500")# = 300<br />
#utcOffsetToMinutes("05")# = 300<br />
</cfoutput>

Parameters:

Name Description Required
offset The formatted UTC offset to be converted to minutes. Yes

Full UDF Source:

<!---
Converts UTC Offset to minutes.

@param offset The formatted UTC offset to be converted to minutes. (Required)
@return Returns a number.
@author Mosh Teitelbaum (mosh.teitelbaum@evoch.com)
@version 1, 1/8/2015
--->

<cffunction name="utcOffsetToMinutes" returntype="numeric" output="no" description="Converts UTC Offset to minutes.">
    <cfargument name="offset" type="string" required="yes" hint="The formatted UTC offset to be converted to minutes.">

	<!--- Initialize local variables --->
	<cfset var h = 0>															<!--- hours --->
	<cfset var m = 0>															<!--- minutes --->
	<cfset var s = 1>															<!--- sign --->
	<cfset var str = ReReplaceNoCase(arguments.offset, "[^-:0-9]", "", "ALL")>	<!--- offset with non-important characters removed --->

	<!--- If first character is "-", adjust sign --->
	<cfif Compare(Left(str, 1), "-") EQ 0>
		<cfset s = -1>
		<cfset str = Right(str, Len(str) - 1)>
	</cfif>

	<!--- Determine number of hours and minutes --->
	<cfif ListLen(str, ":") EQ 2>
		<cfset h = ListFirst(str, ":")>
		<cfset m = ListLast(str, ":")>
	<cfelseif Len(str) EQ 2>
		<cfset h = str>
	<cfelseif Len(str) EQ 3>
		<cfset h = Left(str, 1)>
		<cfset m = Right(str, 2)>
	<cfelseif Len(str) EQ 4>
		<cfset h = Left(str, 2)>
		<cfset m = Right(str, 2)>
	</cfif>

	<!--- Return number of minutes --->
	<cfreturn s * ((h * 60) + m)>
</cffunction>
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