Jump to content

Number of seconds between a future date/time and now


You are about to reply to a thread that has been inactive for 112 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I'm trying to make a reminder system so I need to calculate the number of seconds between now and a future date/time so I can then use that result in a timer event which can then send the reminder at the appropriate time.

llGetUnixTime will give me the number of seconds from 00:00 hours, Jan 1, 1970 till now.  Is there a way I can do another llGetUnixTime based on a future date/time and so all I have to do is to take the difference between these two results to get the number of seconds between now and a future date/time?
 

Link to post
Share on other sites
Posted (edited)

Hi Wulfie - up to 1 year in the future.  I want to start with a variable that contained the future date/time first.  From this date/time, I want to calculate the number of seconds between now and then.

 

[Edit] I've since found some functions in the Date Library - in particular 'gday' which turns a date into a date number.  Looks like I can do

gday(y2,m2,d2) - gday(y1,m1,d1)

which will give me the number of days between dates (x 24 x 60 x 60 to get seconds) - I'll now work on the time element to determine number of extra seconds to add or subtract to get final result - on right path?

Edited by GloriaGlitter
Update
  • Like 1
Link to post
Share on other sites

if you wanted to play with json & http you could get utc  really quick with...

 

string url = "http://worldclockapi.com/api/json/utc/now";
key req;
default
{
    state_entry()
    {
    }
    touch_start(integer total_number)
    {
        llOwnerSay("Current UTC time...");
        req =  llHTTPRequest(url ,  
            [HTTP_USER_AGENT, "XML-Getter/1.0 (Mozilla Compatible)", 
             HTTP_METHOD, "GET", 
             HTTP_MIMETYPE, "application/json", 
             HTTP_BODY_MAXLENGTH,16384,
             HTTP_PRAGMA_NO_CACHE,TRUE], "");   
    }
    http_response(key request_id, integer status, list metadata, string body)
    {
       string test1 = llJsonGetValue(body,["currentDateTime"]);
       string test2 = llJsonGetValue(body,["dayOfTheWeek"]);
       llOwnerSay("UTC: " + test1  + " * " + test2);
    }
}

 

Edited by Xiija
Link to post
Share on other sites

I think you could do this without calculating at all!  You could also have multiple reminders scheduled. Since you already know when you want to trigger a reminder, simply create a list of future time stamp strings... maybe a strided list which includes reminder text after each string.

Then, simply run a 60-sec timer that searches the list for llGetTimeStamp() once per minute.  If the there’s a match shout the reminder string, or whatever.

i should note that you would trim the seconds out of the TimeStamps unless you need that precision - which would require a speedier timer.

Edited by DoteDote Edison
Clarity
Link to post
Share on other sites
1 hour ago, animats said:

Remember the Year 2038 problem. Some time in the next 18 years, Second Life has to go to 64-bit time values. So, no reminders can be set later than 18 January 2038.

SL won't exist in 2038 because its primary paying customer/target audience will have died out and since LL has no intention of actually trying to attract younger users with features that interest them, SL will become a page in history or something for then 30 & 40 yo millennials to continue to laugh at.

  • Haha 1
Link to post
Share on other sites

Would it not be much easier to periodically check whether the current date matches the one you need (which I think is what @DoteDote Edison is referring to).

This is a script I made in 2015 for a quick and easy notecard-based rezday calendar.... it's a bit rough around the edges, but I was in a hurry and never got back to it.

 

list lstRezdays;
list lstCelebrants;
list lstDayToCheck;
list lstMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

integer intLine;
string strNote;
string strText;

PerformChecks()
{
    strText = "";
    string strDate = llGetDate();
    integer intDay = (integer)llGetSubString(strDate, 8, 9);
    integer intMonth = (integer)llGetSubString(strDate, 5, 6);
    
    integer i;
    do
    {
        string strDateToCheck = CalcDate(intDay, intMonth, i);
        CheckList(strDateToCheck, i);
    }
    while(++i <= 14);
}

CheckList(string strDateToCheck, integer intDifference)
{
    integer i; 
    for (i = 0; i < llGetListLength(lstRezdays); ++i)
    {        
        string strDate = llList2String(lstRezdays, i);
        if (strDate == strDateToCheck)
        {
            if (intDifference)
            {
                strText += (llList2String(lstCelebrants, i) + " in " + (string)intDifference + " days\n");
            }
            else
            {
                strText += (llList2String(lstCelebrants, i) + ": TODAY!!!\n");
            }
        }
    }
    SetText(strText);
}

ClearLists()
{
    lstRezdays = [];
    lstCelebrants = [];
}

SetText(string strText)
{
    llSetText(strText, <0.0, 1.0, 0.0>, 1.0);
}

string CreateDateString(integer intDay, integer intMonth)
{
    string strDay;
    string strMonth;
    if (intDay >= 10)
    {
        strDay = (string)intDay;
    }
    else
    {
        strDay = "0" + (string)intDay;
    }
    
    if (intMonth >= 10)
    {
        strMonth = (string)intMonth;
    }
    else
    {
        strMonth = "0" + (string)intMonth;
    }
    return (strDay + "-" + strMonth);
}

string CalcDate(integer intDay, integer intMonth, integer intIncrement)
{
    integer intMax = llList2Integer(lstMonthDays, intMonth - 1);
    integer intNewDate = intDay + intIncrement;
    if (intNewDate > intMax)
    {
        intNewDate = intNewDate - intMax;
        ++intMonth;
    }
    return CreateDateString(intNewDate, intMonth);
}

default
{
    state_entry()
    {
        SetText("Configuring...");
        ClearLists();
        intLine = 0;
        if (llGetInventoryNumber(INVENTORY_NOTECARD) == 0)
        {
            llOwnerSay("No notecard detected.");
            return;
        }        
        strNote = llGetInventoryName(INVENTORY_NOTECARD, 0);
        llGetNotecardLine(strNote, intLine);
    }
    
    changed(integer change)
    {
        if (change & (CHANGED_OWNER | CHANGED_INVENTORY))
        {
            llResetScript();
        }
    }
    
    dataserver(key req, string data)
    {
        if (data != EOF)
        {
            if ((data != "") && (llGetSubString(data, 0, 0) != "#"))
            {
                list lstEntry = llCSV2List(data);
                lstCelebrants += llList2String(lstEntry, 0);                
                lstRezdays += llList2String(lstEntry, 1);
            }
            llGetNotecardLine(strNote, ++intLine);
        }
        else
        {
            state ready;
        }
    }
}

state ready
{
    state_entry()
    {
        SetText("");
        PerformChecks();
        llSetTimerEvent(24 * 3600);
    }
    
    timer()
    {
        PerformChecks();
    }
    
    changed(integer change)
    {
        if (change & (CHANGED_OWNER | CHANGED_INVENTORY))
        {
            llResetScript();
        }
    }
}

Example of notecard:

 

Quote

#Enter the rezdays in the following format: Name, dd-mm
#Example: Bugs Larnia, 02-06

Bugs, 02-06

 

Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 112 days.

Please take a moment to consider if this thread is worth bumping.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...