Difference between revisions of "Talk:Unix2DateTime"

From Second Life Wiki
Jump to navigation Jump to search
(Script compiled with error, correction arises wrong result)
 
 
(5 intermediate revisions by 3 users not shown)
Line 2: Line 2:
<br/><code>    days = DaysPerMonth(mt++);</code>
<br/><code>    days = DaysPerMonth(mt++);</code>


Changing that line to:
Changed that line to:
<br/><code>    days = DaysPerMonth(mt++,year);</code>
<br/><code>    days = DaysPerMonth(year,mt++);</code>
<br/>avoids compile error, but computes wrong result. I don't know the reason.
<br/>--[[User:Huney Jewell|Huney Jewell]] 07:20, 20 September 2007 (PDT)
<br/>--[[User:Huney Jewell|Huney Jewell]] 07:20, 20 September 2007 (PDT)
== Leap Years ==
Unix time is usable from 1970 to 2037 ... so why does this script's leap year test include handling for centuries that are not multiples of 400 years?
A touch of overkill? [[User:Omei Qunhua|Omei Qunhua]] 16:09, 11 January 2013 (PST)
== Compacting ==
Any objections if I replace 3 user functions with the following compact versions?
<lsl>
// This leap year test works for all years from 1901 to 2099 (yes, including 2000)
// Which is more than enough for UnixTime computations, which only operates over the range [1970, 2038].
integer LeapYear( integer year)
{
    return !(year & 3);
}
integer DaysPerMonth(integer year, integer month)
{
    if (month == 2)  return 28 + LeapYear(year);
    return 30 + ( (month + (month > 7) ) & 1);          // Odd months up to July, and even months after July, have 31 days
}
integer DaysPerYear(integer year)
{
    return 365 + LeapYear(year);
}
</lsl>
[[User:Omei Qunhua|Omei Qunhua]] 03:49, 9 December 2013 (PST)
:I'm ok with everything but LeapYear. I've tweaked the comment so that I'm more ok with it. -- '''[[User:Strife_Onizuka|Strife]]''' <sup><small>([[User talk:Strife_Onizuka|talk]]|[[Special:Contributions/Strife_Onizuka|contribs]])</small></sup> 08:27, 9 December 2013 (PST)

Latest revision as of 08:27, 9 December 2013

Script didn't compile due to this line:
days = DaysPerMonth(mt++);

Changed that line to:
days = DaysPerMonth(year,mt++);
--Huney Jewell 07:20, 20 September 2007 (PDT)

Leap Years

Unix time is usable from 1970 to 2037 ... so why does this script's leap year test include handling for centuries that are not multiples of 400 years? A touch of overkill? Omei Qunhua 16:09, 11 January 2013 (PST)

Compacting

Any objections if I replace 3 user functions with the following compact versions?

<lsl> // This leap year test works for all years from 1901 to 2099 (yes, including 2000) // Which is more than enough for UnixTime computations, which only operates over the range [1970, 2038]. integer LeapYear( integer year) {

   return !(year & 3);

}

integer DaysPerMonth(integer year, integer month) {

   if (month == 2)  	return 28 + LeapYear(year);
   return 30 + ( (month + (month > 7) ) & 1);           // Odd months up to July, and even months after July, have 31 days

}

integer DaysPerYear(integer year) {

   return 365 + LeapYear(year);

} </lsl>

Omei Qunhua 03:49, 9 December 2013 (PST)

I'm ok with everything but LeapYear. I've tweaked the comment so that I'm more ok with it. -- Strife (talk|contribs) 08:27, 9 December 2013 (PST)