Making things count


Making things count


I logged in and found a message and a note card from my neighbor, Banana Stein. He is the person who introduced Cisco Systems to Second Life and built up their region on four simulators.


D



I have a need for a “Count Down” Clock - one that states days, hours, minutes - and can be set to any time in the next three months



and if possible - it spells out and name at the end - name to be determined.



DO you think it is possible to build one? - and how much will it cost?



We will have a form for it to be placed in a a few days -



Thanks

Banana


A while back, I did something similar for Jet Burns. Jet is the guy who brought NASA into Second Life and is working at Jet Propulsion Laboratory (JPL). Jet came to me about a countdown clock he had trouble with and needed it to work for the Phoenix launch. It was originally made by Char Linden.


It was poorly designed and burdoning on the simulators resources. My guess is that Char did not know much about optimizing scripts for maximum performance. It also had a few bugs that would surely break it, including the bug that Jet was having problems with as well.


I had stood there in front of him wearing the timer clockx over top of my head as I worked on it. I couldn’t create any objects in the sim, so this was the next best way to work around it.


Jet was really happy to see the results. He had called on me one more time afterwards for a problem setting up the clock for another launch. It was a minor glitch I had overseen and was fixed quickly.


I was pleasantly surprised to see Banana’s message when I logged in. I was familiar with working on the countdown timer before so I already had some experience for this project. Instead of working with the countdown clock that I already had, I started to create a new version that would satisfy Banana’s requirements.


Everything was pretty simple except for one of the statements of work. The end-user needed to be able to be able to set the date up to three months. I needed to find a way to convert a date into format that the counter could understand.


The lindens provide a method to get the number of seconds since January first, 1970. This is usually referred to as Unix time since a common method is available on unix platforms to provide the same functionality. I had been working with this method to compare two dates. The problem is, the lindens do not provide a way to get the unix time for any date. The method llGetUnixTime() only provides the number of total seconds for the current time that it is used.


The nasa folks were actually using a special web page to figure out the unix time for any date and saving it in the count down timer script.


I started researching how to convert a date into unix time. I first created a method called GetUnixTime that expected the year, month, day, hour, minute, and seconds for a date. It is simple enough to calculate the number of seconds in a day, hour and minute. The month and year are different due to the fact that months have different number of days, and some change depending on the year.


What I really needed was a method to determine if a specified year was a leap year. There are some simple rules to determine if the current year is a leap year.


If the year is divisible by four
…and the year is not divisible by one hundred
If the year is divisible by four hundred.

integer isLeapYear(integer year)
{
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}

I then created a method to tell me how many days are in a specific year. The method that I made returns a number representing TRUE or FALSE. In other words, the number 0 and 1. Since a leap year only adds one day, I was able to add the result of the method to 365.

integer daysInYear(integer year)
{
return 365 + isLeapYear(year);
}

The next part was to determine how many days are in each month. Because the second month, February, has different days depending on what year it is, I needed to use the method that I created to determine if the month was affected by the current year. I used the same trick to return an additional day for February if it was in a leap year.

integer daysInMonth(integer month, integer year)
{
list days = [-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
if(month != 2) return llList2Integer(days, month);
return 28 + isLeapYear(year);
}

In the end, I added all the seconds together that passed since January 1, 1970. I could go into that as well, but I think most scripters who ar interested can figure that out pretty easily.

Woodbridge (93, 72) - Jan 26, 2008 (311 days ago) by Dedric Mauriac

Tags for this Snapshot

0 01 08 1 100 1970 2 2007 28 30 31 365 4 400 add added additional adds affected ar back banana bananas blockquote br break brought bug bugs build built burdoning burns calculate called card change char cisco clock clockx common compare convert cost count countdown counter create created current date dates day days daysinmonth daysinyear dbr dedricmauriac depending designed determine determined divisible due easily end enduser expected experience fact false familiar february figure find fixed folks form format found front functionality getunixtime glitch gov guess guy happy head hour hours hrefhttp htmfigure hundred including integer interested introduced isleapyear january jet jpl laboratory launch leap li life liif linden lindens list llgetunixtime lllist2integer logged made making maximum message method minor minute minutes month months monthsbr nasa needed neighbor note number objects ol olli onlineconversion optimizing originally overseen p page part passed performance person phoenix platforms pleasantly poorly pre preinteger pretty problem problems project propulsion provide quickly referred region representing requirements researching resources result results return returns rules satisfy saving script scripters scripts seconds set setting sim similar simple simulators special specific spells started statements states stein stood surely surprised systems thanksbr things time timer top total trick trouble true understand unix unixtime version wearing web woodbridge wordpress words work worked working workingundertheclock www year

Leave a Comment

You're not logged in. If you want to post a comment, please log in.