Difference between revisions of "TimeAgo"
Jump to navigation
Jump to search
Ugleh Ulrik (talk | contribs) |
(for great justice (and a scone)) |
||
Line 12: | Line 12: | ||
integer dif = llGetUnixTime()-tm; //difference in seconds | integer dif = llGetUnixTime()-tm; //difference in seconds | ||
if (dif == 0)//Small bug fix if dif is 0 | if (dif == 0)//Small bug fix if dif is 0 | ||
return "0 seconds"; | |||
list pds = ["second","minute","hour","day","week","month","year","decade"]; | list pds = ["second","minute","hour","day","week","month","year","decade"]; | ||
list lngh = [1,60,3600,86400,604800,2630880,31570560,315705600];//the number equivalent to pds | list lngh = [1,60,3600,86400,604800,2630880,31570560,315705600];//the number equivalent to pds | ||
integer | integer v = llGetListLength(lngh)-1; | ||
integer no; | |||
string dd = llList2String(pds,v); | while((v >= 0)&&(no = dif/llList2Integer(lngh,v)<=1)) | ||
integer ntime = dif / llList2Integer(lngh,llListFindList(pds, [dd])); //this will get the correct time in pds, then divide the dif | --v; | ||
if(no != 1) | string dd = llList2String(pds,v); | ||
dd = (string)ntime + " "+ dd; //This produces the finished output | integer ntime = dif / llList2Integer(lngh,llListFindList(pds, [dd])); //this will get the correct time in pds, then divide the dif | ||
if(no != 1)//if integer 'no' is not equal to 1 then it should have an s at the end | |||
dd +="s"; | |||
dd = (string)ntime + " "+ dd; //This produces the finished output | |||
return dd; | return dd; | ||
} | } |
Revision as of 23:36, 25 May 2010
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: string TimeAgo( integer tm );Returns a string that will give you the difference in time.
• integer | tm | – | Unix Time used for difference |
See also: llGetUnixTime
Specification
<lsl> //Created by Ugleh Ulrik string TimeAgo(integer tm) {
integer dif = llGetUnixTime()-tm; //difference in seconds if (dif == 0)//Small bug fix if dif is 0 return "0 seconds"; list pds = ["second","minute","hour","day","week","month","year","decade"]; list lngh = [1,60,3600,86400,604800,2630880,31570560,315705600];//the number equivalent to pds integer v = llGetListLength(lngh)-1; integer no; while((v >= 0)&&(no = dif/llList2Integer(lngh,v)<=1)) --v; string dd = llList2String(pds,v); integer ntime = dif / llList2Integer(lngh,llListFindList(pds, [dd])); //this will get the correct time in pds, then divide the dif if(no != 1)//if integer 'no' is not equal to 1 then it should have an s at the end dd +="s"; dd = (string)ntime + " "+ dd; //This produces the finished output return dd;
} </lsl>
Examples
<lsl> //Created by Ugleh Ulrik default {
touch_start(integer total_number) { integer time = llGetUnixTime() - 180; llSay(0, TimeAgo(time) + " ago"); }
}
//integer time is the current unix time minus 180 seconds (3 minutes)