Question about dates
|
|
Jerry Ubble
Registered User
Join date: 6 Mar 2009
Posts: 6
|
04-16-2009 12:35
I have a list in which i have stored names and birthdays. Now I need to make a function that will find the oldest one. If I just substract I only get the year. And if two persons are from the same year, I would have to check the months and days also.
Does anyone have a solution, or any tips on how I could make that work
|
|
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
|
04-16-2009 13:11
There are several solutions to this, and it depends on how you store your dates. Why not store them as a strided list, with YYYY-MM-DD as first element, and Avatar Name as second element, then just call llListSort with a stride of 2. Only down sides are that month and day if a single digit have to be forced to 2 digist, 01 instead of 1, 02 instead of 2, etc, and then equal dates, will be sorted alphebetically by the Avatar name. list bDays = ["1970-04-05", "Evil Joe", "1970-02-04", "Jon Doe", "1981-04-05", "Jane Doe", "1965-12-25", "Christmas Special"];
default { state_entry() { bDays = llListSort(bDays, 2, TRUE); llOwnerSay(llDumpList2String(bDays, ",")); } }
Your result will be: 1965-12-25,Christmas Special,1970-02-04,Jon Doe,1970-04-05,Evil Joe,1981-04-05,Jane Doe
|
|
Jerry Ubble
Registered User
Join date: 6 Mar 2009
Posts: 6
|
04-16-2009 13:36
Thank you.
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
04-16-2009 13:37
Never mind. Yours works just fine Lazink.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
|
04-16-2009 13:47
Store the dates as an integer.
Year * 10000 + Month * 100 + Day
ie 24-06-1957 = 19570624
then just sort them
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
04-16-2009 14:02
From: Beverly Ultsch Store the dates as an integer.
Year * 10000 + Month * 100 + Day
ie 24-06-1957 = 19570624
then just sort them That was one of my other trains of thought. But surprisingly Lazink's strings are being sorted correctly.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
|
04-16-2009 14:55
That was just my gut feeling, if the strings work go with them
Edit: the important thing is to get then into yyyymmdd format, then they will sort corectly
|
|
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
|
04-16-2009 20:13
From: Jesse Barnett That was one of my other trains of thought. But surprisingly Lazink's strings are being sorted correctly. SURPRISINGLY!?!?!? (note the sarcasm) I have been known to come up with SOME things that work occasionally. But yes, wasn't sure if the strings would work myself tell I tested it in world first. 
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
04-16-2009 20:25
From: Lazink Maeterlinck SURPRISINGLY!?!?!? (note the sarcasm) I have been known to come up with SOME things that work occasionally. But yes, wasn't sure if the strings would work myself tell I tested it in world first.  Hey! Even a blind hog can find a peanut every now and then The surprise pertained to the string sort, not the scripter who came up with it. All I can say is that your way was one heck of a lot better then what I had posted at first and then turned around and deleted in embarrassment.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
04-16-2009 20:29
From: Lazink Maeterlinck SURPRISINGLY!?!?!? (note the sarcasm) I have been known to come up with SOME things that work occasionally. But yes, wasn't sure if the strings would work myself tell I tested it in world first.  lol I dun think she meant it was purprise that YOU came up with it... ... more like surprising that LSL did something that could normally be expected by a more... stable... language, which in lsl is pretty shocking, but then many things in lsl are, at least in their failures... which makes it kinda par for the course, and yet not. oh the vagueries of lowered expectations.... ETA: speaking of deleting in embarassment... must type faster, must NOT walk away from computer whilst posting.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
|
04-16-2009 20:52
OH I knew what she was meaning, just having fun. Yeah why I tested it in world first to see if it was even the right way to go 
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
04-16-2009 21:18
It kind of feels like old times around here today. Strife popping in, Suezzanne showed up and even saw Newfie's name in RA and the playful banter across the threads here. It was wonderful but then I started thinking(which I am prone to do every now and then). *sighs* I miss the old forum with bbcode and a whole bunch of people answering and trying to outdo each in regards to readability and efficiency AND arguing about readability and efficiency  . I miss Newgie and Ordinal and all the other names here. I do love all the regulars here and the new ones that are contributing now, just wish there were more of us still.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
04-16-2009 21:52
me too
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
|
04-16-2009 23:28
From: Jesse Barnett It kind of feels like old times around here today. Strife popping in, Suezzanne showed up and even saw Newfie's name in RA and the playful banter across the threads here. It was wonderful but then I started thinking(which I am prone to do every now and then). *sighs* I miss the old forum with bbcode and a whole bunch of people answering and trying to outdo each in regards to readability and efficiency AND arguing about readability and efficiency  . I miss Newgie and Ordinal and all the other names here. I do love all the regulars here and the new ones that are contributing now, just wish there were more of us still. This gives me an idea, why not start a thread with like a weekly challenge, just for fun. Come up with some simple yet creative problem, that deals with common questions with LSL and scripts, and just see what people come up with, and how to improve it for different categories, like speed, memory usage, readability, etc. Might be fun to do.
|
|
Jerry Ubble
Registered User
Join date: 6 Mar 2009
Posts: 6
|
04-17-2009 01:16
One more thing... What if I have to find the one that had birthday last in that string?
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
04-17-2009 04:36
From: Jerry Ubble One more thing... What if I have to find the one that had birthday last in that string? bDays = llListSort(bDays, 2, FALSE);
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
|
04-17-2009 11:23
From: Jerry Ubble One more thing... What if I have to find the one that had birthday last in that string? What exactly do you mean by this, Jesse's suggestion will get you the youngest person in the list. But I'm reading this as finding the person who last had a birthday, regardless of the year they were born.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
04-17-2009 16:29
remove the year, resort, loop the list against llGetDate (with the year removed) checking list item <= current date. (assuming you have thei B-Day as a single element, instead of separate elements)
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
04-17-2009 16:38
From: Lazink Maeterlinck This gives me an idea, why not start a thread with like a weekly challenge, just for fun. Come up with some simple yet creative problem, that deals with common questions with LSL and scripts, and just see what people come up with, and how to improve it for different categories, like speed, memory usage, readability, etc. Might be fun to do. I like it... and for fun (since I offered a vanity prize) we can start here? /54/1f/316557/1.htmlwhat do you think the best day to start/end it would be? maybe run it 5 days, the sixth for testing, the seventh for new suggestions?
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
|
04-17-2009 17:41
From: Void Singer what do you think the best day to start/end it would be? maybe run it 5 days, the sixth for testing, the seventh for new suggestions? Well, I think starting on Thursday or Friday would be best, gives people the weekend to think about it, so Friday through Wed, Thursday to do some testing, and Friday, you say which ones were most efficient etc, and then Friday pick a new problem. The hard part, which I can honestly say I don't know the LSL ins and outs enough is a good way to test (what to add to test speed, efficiency and what not) but there has to be a simple template to use. And if some people find the problems too easy, or too difficult, maybe we'll have to make two, one general and one for more of a challenge. Or it can be set up like a programming comp is, with a problem, and the expected solution. I didn't want to go in that direction though because I think it would be good to have these little snippets of code for anyone to grab and use, why I suggested making it related to common problems/questions we see in this forum. I'm open to lots of suggestions of how to do this, don't be afraid to chime in people with ideas, or even if you even think this is a terrible idea 
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
04-17-2009 20:00
From: Lazink Maeterlinck Well, I think starting on Thursday or Friday would be best, gives people the weekend to think about it, so Friday through Wed, Thursday to do some testing, and Friday, you say which ones were most efficient etc, and then Friday pick a new problem. The hard part, which I can honestly say I don't know the LSL ins and outs enough is a good way to test (what to add to test speed, efficiency and what not) but there has to be a simple template to use. And if some people find the problems too easy, or too difficult, maybe we'll have to make two, one general and one for more of a challenge. Or it can be set up like a programming comp is, with a problem, and the expected solution. I didn't want to go in that direction though because I think it would be good to have these little snippets of code for anyone to grab and use, why I suggested making it related to common problems/questions we see in this forum. I'm open to lots of suggestions of how to do this, don't be afraid to chime in people with ideas, or even if you even think this is a terrible idea  well there's a wonderful script for testing speed on the LSL Portal, with a few tweaks it could easily be converted to make it easier to just plug in tests (I actually have that in my inventory if I can stay in long enough to grab it. the test for memory size (both on load and in use) are pretty easy to build, but aren't quite accurate in mono ATM. I say run with it =). I'll post back here with my test rig. should be able to get it one script. for clarity I think people can repost just their fragment, and not the whole test bed. new thread each time? it'll make searching for specific code easier (or we could just post the winner as "Library:xyz function" and credit the winner. any volunteers for a new topic out there? if not, I've got one to propose. it's been done before, but I'd love to see if someone can do better.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
04-17-2009 20:07
From: Void Singer well there's a wonderful script for testing speed on the LSL Portal, with a few tweaks it could easily be converted to make it easier to just plug in tests (I actually have that in my inventory if I can stay in long enough to grab it.
the test for memory size (both on load and in use) are pretty easy to build, but aren't quite accurate in mono ATM. I say run with it =). I'll post back here with my test rig. should be able to get it one script. for clarity I think people can repost just their fragment, and not the whole test bed.
new thread each time? it'll make searching for specific code easier (or we could just post the winner as "Library:xyz function" and credit the winner.
any volunteers for a new topic out there? if not, I've got one to propose. it's been done before, but I'd love to see if someone can do better. Maybe put [bounty] in the subject line? This is what solved the unsolvable problems with libsl. I think it is a great idea and should get newer scripters to give it a try and learn at the same time. My proudest moment early on in scripting was posting a script that was faster then one of Strife's(he must have been having a bad day).
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
|
04-17-2009 20:37
@void: I can see a library post for each function working well, as for testing, we should be able to either find something, or come up with something really robust enough to handle anything, posting just the fragment is what I had in mind too, that way testing is more controllable.
@Jesse: Yeah, want to keep this in the simple to moderate range for new people who are learning the language, or wanting to learn, get them involved more. As I posted earlier, maybe if it's too easy for most people, do a more challenging problem for the more experienced people along with the simpler form.
OH, also, as Hewee pointed out in one thread, Readability I think should be important too, maybe we should use a rule if you use some trick or some neat shortcut, to at least comment what exactly you are doing, so even novices can follow.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
04-17-2009 21:26
From: Lazink Maeterlinck OH, also, as Hewee pointed out in one thread, Readability I think should be important too, maybe we should use a rule if you use some trick or some neat shortcut, to at least comment what exactly you are doing, so even novices can follow. absolutely, if people can't understand it, it's not useful, even just a comparison comment like: if (~found){ //-- same effect as: if (-1 != found){ if (persons_key){ //-- test to see if the key provided is really a key I like Jesse's suggestion too, but a bounty implies a reward, for which we'll need sponsors, and a very clear definition of criteria for the prize... sometimes the smallest code isn't the fastest, or vice versa. unfortunately I'm income limited ATM so I can't contribute much as a sponsor (but I have no qualms about turning around on any I might pick up and using them to sponsor further prizes, or just inserting a NO_PRIZE comment to let it fall to the next best version... sorta like an A_for_effort thing)
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
04-17-2009 21:34
From: Void Singer absolutely, if people can't understand it, it's not useful, even just a comparison comment like: if (~found){ //-- same effect as: if (-1 != found){ if (persons_key){ //-- test to see if the key provided is really a key
I like Jesse's suggestion too, but a bounty implies a reward, for which we'll need sponsors, and a very clear definition of criteria for the prize... sometimes the smallest code isn't the fastest, or vice versa. unfortunately I'm income limited ATM so I can't contribute much as a sponsor (but I have no qualms about turning around on any I might pick up and using them to sponsor further prizes, or just inserting a NO_PRIZE comment to let it fall to the next best version... sorta like an A_for_effort thing) Thinking about and even a flag like: [Challenge] would work without a bounty. If we really were doing it for the money, we wouldn't be posting here. And I agree with the comment suggestion, even though I HATE to comment my scripts. The point of the exercise is for people to learn and see the different ways to script the same project. This used to happen on a regular basis and helped me tremendously.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|