Difference between revisions of "Input number of seconds, get a string back that shows days, hours, minutes, seconds"
Jump to navigation
Jump to search
Fire Centaur (talk | contribs) (getTime) |
m (increasing readability, adding syntax highlighting) |
||
Line 1: | Line 1: | ||
<lsl> /* | |||
* Submitted Opensource under GPL 3.0 | * Submitted Opensource under GPL 3.0 | ||
* 2010 Fire Centaur | * 2010 Fire Centaur | ||
Line 7: | Line 7: | ||
*/ | */ | ||
string getTime(integer secs){ | |||
string timeStr; | |||
integer days; | |||
integer hours; | |||
integer minutes; | |||
if (secs>=86400){ | |||
days=llFloor(secs/86400); | |||
secs=secs%86400; | |||
timeStr=(string)days+" day"; | |||
if (days!=1) {timeStr="s";} | |||
if(secs>0) {timeStr+=", ";} | |||
} | |||
if(secs>=3600){ | |||
hours=llFloor(secs/3600); | |||
secs=secs%3600; | |||
timeStr+=(string)hours+" hour"; | |||
if(hours!=1){timeStr+="s";} | |||
if(secs>0){timeStr+=", ";} | |||
} | |||
if(secs>=60){ | |||
minutes=llFloor(secs/60); | |||
secs=secs%60; | |||
timeStr+=(string)minutes+" minute"; | |||
if(minutes!=1){timeStr+="s";} | |||
if(secs>0){timeStr+=", ";} | |||
} | |||
timeStr+=(string)secs+" second"; | |||
if(secs!=1){timeStr+="s";} | |||
return timeStr; | |||
}</lsl> |
Revision as of 03:04, 1 September 2010
<lsl> /*
* Submitted Opensource under GPL 3.0 * 2010 Fire Centaur * Description: * * Input number of seconds, function will return a string with Days, Hours, Minutes, Seconds */
string getTime(integer secs){
string timeStr; integer days; integer hours; integer minutes; if (secs>=86400){ days=llFloor(secs/86400); secs=secs%86400; timeStr=(string)days+" day"; if (days!=1) {timeStr="s";} if(secs>0) {timeStr+=", ";} } if(secs>=3600){ hours=llFloor(secs/3600); secs=secs%3600; timeStr+=(string)hours+" hour"; if(hours!=1){timeStr+="s";} if(secs>0){timeStr+=", ";} } if(secs>=60){ minutes=llFloor(secs/60); secs=secs%60; timeStr+=(string)minutes+" minute"; if(minutes!=1){timeStr+="s";} if(secs>0){timeStr+=", ";} } timeStr+=(string)secs+" second"; if(secs!=1){timeStr+="s";} return timeStr;
}</lsl>