This function converts an integer value in seconds into a string of the form:
h hours, m minutes and s seconds
depending on the value, results as
1 hour
3 hours and 1 minute
1 hour, 10 minutes and 1 second
2 hours and 10 seconds
20 minutes and 42 seconds
...
are automatically generated.
SecondsToTextOptions:FunctionReturnType:TextParametersSeconds=0<Integer>GrammarText:SecondsToText(Seconds)HintText:(None)CustomScriptCodeLocalVariablesh=0<Integer>m=0<Integer>s=0<Integer>result=NoText<Text>ActionsVariable-Sets=SecondsGeneral-If(Conditions)thendo(Actions)elsedo(Actions)Ifs>=3600ThenVariable-Seth=(s/3600)Variable-Sets=(smod3600)Variable-Setresult=((Text(h))+" hour")General-If(Conditions)thendo(Actions)elsedo(Actions)Ifh>1ThenVariable-Setresult=(result+"s")ElseElseGeneral-If(Conditions)thendo(Actions)elsedo(Actions)Ifs>=60ThenVariable-Setm=(s/60)Variable-Sets=(smod60)General-If(Conditions)thendo(Actions)elsedo(Actions)Ifh>0ThenGeneral-If(Conditions)thendo(Actions)elsedo(Actions)Ifs>0ThenVariable-Setresult=(result+", ")ElseVariable-Setresult=(result+" and ")ElseVariable-Setresult=((result+(Text(m)))+" minute")General-If(Conditions)thendo(Actions)elsedo(Actions)Ifm>1ThenVariable-Setresult=(result+"s")ElseElseGeneral-If(Conditions)thendo(Actions)elsedo(Actions)IfOrConditionsh>0m>0ThenVariable-Setresult=(result+" and ")ElseVariable-Setresult=(result+((Text(s))+" second"))General-If(Conditions)thendo(Actions)elsedo(Actions)Ifs>1ThenVariable-Setresult=(result+"s")ElseGeneral-Returnresult
Unfortunately, it appears you just reinvented the wheel.
// TextTimeFormat converts a time value, in seconds, to text using a format string// - The time format string should use the following tokens://// <hour/> = hour count, rounded down// <hour2/> = hour count, rounded down, always two digits// <hourtotal/> = total hour count, rounded down// <hourtotaln/> = total hour count, rounded to nearest// <hourtotalu/> = total hour count, rounded up// <min/> = minute count, rounded down// <min2/> = minute count, rounded down, always two digits// <mintotal/> = total minute count, rounded down// <mintotaln/> = total minute count, rounded to nearest// <mintotalu/> = total minute count, rounded up// <sec/> = second count// <sec2/> = second count, always two digits// <sectotal/> = total second count// <short/> = one of "<hour/>h", "<min/>m", or "<sec/>s"//// Examples (these all represent the same value):// "<hour/>:<min2/>:<sec2/>" -> 1:08:38 (this is the default format)// "<mintotaln/> minutes" -> 69 minutes// "<mintotal/>:<sec2/>" -> 68:38// "<short/>" -> 1h//nativetextTextTimeFormat(textinFormat,intinSecs);
Is it possible to achieve the exact same thing with the TextTimeFormat function as I did?
I don't think that it will correctly differentiate between singular and plural.
Also it won't add ","s and "and"s at the right places.
This function converts an integer value in seconds into a string of the form:
depending on the value, results as
are automatically generated.
I hope this might be of use for someone ;)
Isn't this from the Campaign dependancy under general section?
Unfortunately, it appears you just reinvented the wheel.
Is it possible to achieve the exact same thing with the TextTimeFormat function as I did? I don't think that it will correctly differentiate between singular and plural. Also it won't add ","s and "and"s at the right places.
@Pfaeff: Go
Just make the format string "<hour/> hours, <min/> minutes, <sec> seconds"?
Seems to work for me.
Worst case you check if hours == 0, and remove it from the format string, minutes == 0 and remove it from the string, etc.
But it will also result in this: 1 hours, 1 minutes, 1 seconds
where my algorithm will give the following result: 1 hour, 1 minute and 1 second
let minutes = 0, then it will result in (if you manually remove the minutes): 1 hours, 1 seconds
my algorithm: 1 hour and 1 second
It just looks less technical and is easier to read.