I am trying to figure out how to properly output a variable that was created
using CreateTimeSpan in a readable format. Here is the initial code:
<cfset MyTime = #CreateTimeSpan(0,0,30,0)#>
And lower on the page:
<cfouput>#MyTime#</cfoutput>
Which unfortunately results in showing this:
0.0208333333333
But I want it to show as
30 minutes
Without going into too much detail, the short is I am trying to output this
for the user and only need to know how I can format 0.0208333333333 to the
appropriate amount of time *i.e. 30 minutes, 2 hours 30 minutes, 2 days, etc.
Any help on this is greatly appreciated!
Dan Bracuk - 28 Jul 2007 12:35 GMT
Try this
Set a string variable to "0,0,30,0"
cfset YourTime=CreatetimeSpan(#yourvariable#)
Loop through your variable with some if/else logic to display your timespan.
bhakala - 28 Jul 2007 18:53 GMT
That would work, but I am looking for a more efficient way to code it out.
There has got to be some sort of DateFormat type function available that
parses it to how it should be displayed on screen I would hope.
Azadi - 28 Jul 2007 21:18 GMT
as was very rightly mentioned by BKBK in your other (very similar) post
in the getting started forum, createtimespan() function returns number
of DAYS
so the integer part of the value returned (left of the decimal point)
will be number of full days, which you could get with #listfirst(MyTime,
".")#
the decimal part (right of the decimal point) can be converted to hours
and minutes:
#listfirst(24*listlast(MyTime, "."), ".")# will give you hours, while
#60*listlast(24*listlast(MyTime, "."), ".")# will give you minutes
the integer part of the above value is number of hours, while 60*decimal
part of the above value is minutes
using conditional logic (cfif/cfelse) and formatting (i.e. numberforat()
function) with the above you can display the result in the format you want
keep in mind, though, that on a server with a different locale set as
default, the decimal separator may not be a . [dot]
---
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
bhakala - 28 Jul 2007 22:52 GMT
Yes I did have a very similar post in another section regarding several issues
and this was one of them. However since I was not getting any responses on that
one, I opted to work on the other issues myself....leaving only this one which
I posted here :).
Your code logic works well. The end result of what I ended up using, as
suggested by another user, which worked out fine was the following code:
To protect your security you will be asked to re-enter your login details
after <cfoutput>#sessiontimeout *24*60# minutes</cfoutput> without any online
activity.
And the end result is the page below (see bottom box):
http://www.pc-productions.net/admin2/
As always I appreciate everyones input on this issue and we shall consider
this closed, unless anyone else wants it open for discussion.
Azadi - 28 Jul 2007 23:08 GMT
good job!
yes, i have seen that other suggestion.
in my suggestion i was - fbased on your other post - assuming that the
timeout value was going to be set by a user of the admin area and could
measure in days... i guess i just misread your other post...
---
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
bhakala - 28 Jul 2007 23:39 GMT
Well you weren't as far off as you think :). Initially I was going to want to
do it so it dynamically figured if it should display as days, hours, minutes,
etc....but I decided that was good enough for the moment.
Also I do intend to allow the admin user to indicate the timeout value, but
not as you might think. Basically I have an /install/ folder which will
automatically launch if value on application.cfm
<cfparam name="application.install" default="FALSE">
Within that set of self contained pages, it will take them through a series of
questions and the end results will:
1. Test database connection.
2. Allow them to indicate whether they want to offer support or not (i.e. can
indicate a support email address and if so, then a support form shows within
the admin tools + sends out automated emails on any errors).
3. Allow them to indicate their own time out value.
Upon completion of all of these things, it will then either write to the
application.cfm OR if CFFILE is turned off, give them the code to copy and
paste into the application.cfm, save and upload...which in turn includes the
timeout variable.
I am extremely thorough on my applications and previously at bottom of the
page had it hard coded as "will time out in 30 minutes" but decided that should
be determined during install and dynamically show.
Have lots of work to do on that application before launch yet, so I didn't
want to waste too much time on that single item :). THanks again!