Numbers converter


4thorder(TM)Code Snippets and Full Scripts
4thorder(TM) Code Snippets and Full Scripts (click to visit)
[Cold Fusion] CF Time Span Calculation [Version 1]
Basic Description:
Script allows developers to easily embed the functionality of calculating end time from a given start time and span into in 1/2 hour increments.
Features List:
  • REQUIRES Cold Fusion 5.0 or MX to run
  • Uses "CreateTimeSpan" to translate both start time and time span into minutes.  That way only a simple addition is required to determine end time.
  • "TimeFormat" is then used to return the start time and end time back to a HH:MM based time format.
  • Several of the "TimeFormat" formatting options are provided with this script.
  • Page "actions" back to itself, therefore, "cfparam" is required to setup two default parameters (RequestTimeStart, RequestTimeAmount) for initial page load.
Demonstration of Code:
Start Time: Amount of Time: Hours
Start Time:
12 hour: #timeformat(x,'hh:mm TT')#
24 hour: #timeformat(x,'HH:mm')#
End Time (Start Time + Amount):
12 hour: #timeformat(z,'hh:mm TT')#
24 hour: #timeformat(z,'HH:mm')#
Code considerations:
The primary function centers around the following:

<!--- Functions to determine end time --->
<cfset x=CreateTimeSpan(0, 0, RequestTimeStart, 0)>
<cfset y=CreateTimeSpan(0, 0, RequestTimeAmount, 0)>
<cfset z=x+y>

Within the parenthesis of the CreateTimeSpan, the variables (gathered from the above form set as minutes) are placed in the "minutes" spot.  "x" is the start time in minutes.  "y" is the time span in minutes.  Adding these together give a total minutes for end time.

Note: if the end time is past 12:00 am then it is obviously the next day, but the function still works fine.  Additional code is required to calculate whether the end time is in the next day or not if required.

To get the values in an HH:MM format, TimeFormat is used accordingly.

Modifikuar Nga Rinia:
RiniA