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.)
m (<lsl> tag to <source>)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
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.
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>
<source lang="lsl2">
integer GetDaysInMonth(integer month, integer year)
integer GetDaysInMonth(integer month, integer year)
{
{
     if(month == 2)
     if(month == 2)
         return 28 + !(year % 4) - !(year % 100) + !(year % 400);
         return 28 + !(year % 4) - !(year % 100) + !(year % 400);
     return 30 | (month & 1) ^ (month > 6);
     if(month >= 1 && month <= 12)
        return 30 | (month & 1) ^ (month > 7);
    return 0;
}
}


Line 20: Line 22:
         string  date  = llGetDate();
         string  date  = llGetDate();
         list    date_info = llParseString2List(date,["-"],[" "]);
         list    date_info = llParseString2List(date,["-"],[" "]);
         integer year  = llList2Float(date_info,0);
         integer year  = llList2Integer(date_info,0);
         integer month = llList2Integer(date_info,1);
         integer month = llList2Integer(date_info,1);
         integer day  = llList2Integer(date_info,2);
         integer day  = llList2Integer(date_info,2);
Line 28: Line 30:
     }
     }
}
}
</lsl>
</source>
{{LSLC|Library|Days in Month}}
{{LSLC|Library|Days in Month}}

Latest revision as of 19:51, 24 January 2015

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.

integer GetDaysInMonth(integer month, integer year)
{
    if(month == 2)
        return 28 + !(year % 4) - !(year % 100) + !(year % 400);
    if(month >= 1 && month <= 12)
        return 30 | (month & 1) ^ (month > 7);
    return 0;
}

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  = llList2Integer(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");
    }
}