Difference between revisions of "Days in Month"

From Second Life Wiki
Jump to navigation Jump to search
(The code was so ugly and poorly organized it was just easier to rewrite from scratch.)
Line 1: Line 1:
The following script is adaptable for use in any calendrical system, particularly pertaining to tier collection systems that need to do actual monthly billings, not just 28 day or 30 day billing cycles.
The following script is adaptable for use in any calender system, particularly pertaining to tier collection systems that need to do actual monthly billings, not just 28 day or 30 day billing cycles.


<lsl>
<lsl>
string date = "";
integer GetDaysInMonth(integer month, integer year)
list date_info;
{
integer month;
    if(month == 2)
integer day;
        return 28 + !(year % 4) - !(year % 100) + !(year % 400);
string days;
    return 30 | (month & 1) ^ (month > 6);
float year;
}
list thirtydays = [4,6,9,11];
list thirtyonedays = [1,3,5,7,8,10,12];
integer index;


dayspeak()
            {
                llSay(0,days);
                index += 1;
            }
thirtytest()
            {
              do
       
                    if (month = llList2Integer(thirtydays,index))
            {
                days = "30";
                dayspeak();
            }
                while (index < 4);
            }
           
thirtyonetest()
            {
                do
                    if (month = llList2Integer(thirtyonedays,index))
            {
                days = "31";
                dayspeak();
            }
                while (index < 9);
            }
           
leapyeartest()
            {
              if (month = 2)
              {
                if ((integer)year / 4 == TYPE_INTEGER)
                {
                    days = "29";
                    dayspeak();
                }
                else
                {
                    days = "28";
                    dayspeak();
                }
                }
                else
                {
                    llSay(0,"I'm sorry you are on the wrong planet.");
                }
                   
        }
               
default
default
{
{
Line 74: Line 18:
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
         date = llGetDate();
         string  date = llGetDate();
         date_info = llParseString2List(date,["-"],[" "]);
         list    date_info = llParseString2List(date,["-"],[" "]);
         year = llList2Float(date_info,0);
         integer year = llList2Float(date_info,0);
         month = llList2Integer(date_info,1);
         integer month = llList2Integer(date_info,1);
         day = llList2Integer(date_info,2);
         integer day   = llList2Integer(date_info,2);
         integer index = 0;
 
        thirtytest();
         integer days_in_month = GetDaysInMonth(month, year);
         thirtyonetest();
         llSay(0, (string)days_in_month + " days in this month");
        leapyeartest();
       
     }
     }
}
}
</lsl>
</lsl>
{{LSLC|Library|Days in Month}}
{{LSLC|Library|Days in Month}}

Revision as of 12:56, 20 October 2008

The following script is adaptable for use in any calender system, particularly pertaining to tier collection systems that need to do actual monthly billings, not just 28 day or 30 day billing cycles.

<lsl> integer GetDaysInMonth(integer month, integer year) {

   if(month == 2)
       return 28 + !(year % 4) - !(year % 100) + !(year % 400);
   return 30 | (month & 1) ^ (month > 6);

}

default {

   state_entry()
   {
       llSay(0, "Touch to confirm the number of days in the current month!");
   }
   touch_start(integer total_number)
   {
       string  date  = llGetDate();
       list    date_info = llParseString2List(date,["-"],[" "]);
       integer year  = llList2Float(date_info,0);
       integer month = llList2Integer(date_info,1);
       integer day   = llList2Integer(date_info,2);
       integer days_in_month = GetDaysInMonth(month, year);
       llSay(0, (string)days_in_month + " days in this month");
   }

} </lsl>