Neverworld Grid

You are not logged in. Would you like to login or register?



6/10/2019 6:04 pm  #1


Get the time and date then do something with the data

The area below "default" is filled with examples of it's use

/*
    Get The Date/Time and Do Something With It
    Copylefted Apr/20/2019 - Logan "Smexypants" Stargazer

    I needed these subroutines for a script. I share them with you.
*/
 
//   Get The Time Routines

 integer  GetYear()
 {return llList2Integer(llParseString2List(llGetTimestamp(),["-",":"],["T"]),0);}

 integer  GetMonthNumber()
 {return llList2Integer(llParseString2List(llGetTimestamp(),["-",":"],["T"]),1);}
 
string GetMonthName()
 {return llList2String(["FOO","January","February","March","April","May","June","July","August","September","October","November","December"], GetMonthNumber());}

integer  GetDay()
 {return llList2Integer(llParseString2List(llGetTimestamp(),["-",":"],["T"]),2);}

// Hour returns UTC   Correct for your application
//   Example:   GetHour() -5  for CST or GetHour()-7 for PST/SL/Opensim Time
integer  GetHour()
 {return llList2Integer(llParseString2List(llGetTimestamp(),["-",":"],["T"]),4);}

integer  GetMinute()
 {return llList2Integer(llParseString2List(llGetTimestamp(),["-",":"],["T"]),5);}

integer  GetSecond()
 {return (integer)llList2Float(llParseString2List(llGetTimestamp(),["-",":"],["T"]),6);}

float  GetExactSecond()
 {return llList2Float(llParseString2List(llGetTimestamp(),["-",":"],["T"]),6);}

string GetDayOfWeek(integer year, integer month, integer day)
{
 
 if (month <= 2) {--year; month += 12;}
 
  return llList2String(["Sun","Mon","Tues","Wednes","Thurs","Fri","Satur"],
    ((((day + (((month + 1) * 26) / 10) + year +
        (year / 4) + (6 * (year / 100)) + (year / 400)) %
       7) + 6) % 7)
       ) + "day";
}
//  End of routines

// DEMO CODE

default
{
    state_entry()
    {
        llSetTimerEvent(30); // A 30 second cycle should be good enough. That's twice
                             // per minute. No need slam the server. If you need high
                             // precision make it 1 second.
    }
    
    timer()
    {
         if (GetMonthName() == "April" && GetDay() == 12)
        {
            llOwnerSay("Happy Birthday!");
            llOwnerSay("Today is " + GetDayOfWeek(GetYear(),GetMonthNumber(),GetSecond()) + ". You are " + (string)(GetYear() - 1985) + " years old today.");
        }
         //  Corrected for CST
         if ((GetHour()-5) == 8 && GetMinute() == 00)
        {
            llOwnerSay("Take your medicine.");
        }
        //  Corrected for PST
         if ((GetHour()-7) == 14 && GetMinute() == 45)
        {
            llOwnerSay("Pick up the rugrats at school.");
        }

         if (GetYear() > 2000 && GetYear() < 2101)
        {
            llOwnerSay("Great Scott, it's the 21st Century already!");
        }
    } 
}
 

 

Board footera

 

Powered by Boardhost. Create a Free Forum