Now that I ranted, let me ask my question.. I had just finished writting the following function which is supposed to return the time in 'hh:mm' format, with leading zeros.
CODE
// fncSec2Time does the opposite of the above. It converts integer of seconds to a string
// formatted as "hh:mm".
string fncSec2Time(integer intSeconds)
{
integer intHours = intSeconds / 3600; // Get hours
integer intMins = (intSeconds % 3600) / 60; // And minutes
string strTime = "";
if (llStringLength((string)intHours) < 2)
{
strTime = strTime + "0";
}
strTime = strTime + (string)intHours + ":";
if (llStringLength((string)intMins) < 2)
{
strTime = strTime + "0";
}
strTime = strTime + (string)intMins;
return strTime;
}
Now, as i go through that, I know it'll work, but it looks way too long, inefficient.. There's gotta be some way to clean that up some. (I know I could use strTime+= args; but i'm trying to see if this form will save memory, like it does with lists.)
I wouldn't mind being able to do the math, add leading zeros, and create the string all in one shot, but I also know that I need to keep it readable. I was looking at the llDumpString2List function in the wikki when they suddenly took it offline. My thought at the moment was that I could create a list such as ["leading zero", intHours, ":", "leading zero", intMins] and dump it into a string quickly.. That would make for some cleaner code.
But then comes the fact that I gotta check if a leading zero is needed at all. If Hours is less than 10, or if Mins is left than 10, then yes i need leading zero, otherwise no i don't.
anyone have any idea's of how I could do this effeciently?
:note: oh, and yes, I realize this would return 24 hour clock format, 0 through 23 instead of 1 through 12 am/pm. That's ok, as that's what I'm going to use for this script anyway.