Sorting by date

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
exheusden
Posts: 170
Joined: Fri Oct 09, 2009 5:03 pm
Contact:

Sorting by date

Post by exheusden » Thu Mar 06, 2014 5:41 pm

For several years I've had a piece of script that has, I believe worked:

Code: Select all

 set the useSystemDate to true
   set the itemDelimiter to ":"
   sort lines of dateHTML descending dateTime by item 1 of each
Now, however, the lines are not sorted at all, but remain in their original sequence. as can be seen at http://davidneale.eu/elvis/originals/origmods.html

The list (dateHTML) is built originally in alphabetic sequence of title and the idea is to sort it by date, with the most recent date appearing first, hence sort lines of dateHTML descending… etc.

I am using LiveCode Community Edition 6.5.2.

What am I doing wrong, please?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: Sorting by date

Post by dunbarx » Thu Mar 06, 2014 6:26 pm

The code works for me.

I copied some of the list from the website and worked it locally.

Craig Newman

exheusden
Posts: 170
Joined: Fri Oct 09, 2009 5:03 pm
Contact:

Re: Sorting by date

Post by exheusden » Thu Mar 06, 2014 6:33 pm

In System Preferences, what are your settings for Language and Region and specifically for Date and Time?

Image
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: Sorting by date

Post by dunbarx » Thu Mar 06, 2014 6:55 pm

Hi.

Language = English, Region = US, Date is "short", time is "short"

I saw what I thought was a problem, but it turns out that one of the lines from the webpage starts with "Tursday". This sorted to the bottom of the list, as empty would, I suppose.

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Sorting by date

Post by bn » Thu Mar 06, 2014 7:35 pm

Hi Exheusden,

I don't know why it does not sort.

But a workaround would be

Code: Select all

on mouseUp
   put field 1 into tData
   set the itemDelimiter to ":"
   sort tData ascending dateTime by convertToDateTimeFormat (item 1 of each)
   put tData into field 2
end mouseUp

function convertToDateTimeFormat pDate
   put word 1 of pDate & space & word 3 of pDate & space & word 2 of pDate & comma & space & word 4 of pDate into tNewDate
   return tNewDate
end convertToDateTimeFormat
I just convert the data into the long english date format and then sort dateTime. It uses the form of the sort command where you can define a function that returns what to sort on.

I did this on the htmlText of the site you indicated on just the part with the dates and titles and it worked.

Kind regards

exheusden
Posts: 170
Joined: Fri Oct 09, 2009 5:03 pm
Contact:

Re: Sorting by date

Post by exheusden » Thu Mar 06, 2014 8:22 pm

Thanks for that, bn, I shall give it a try. (Have done so and it works a treat. Many thanks for a quick solution.)

I wonder if the error has anything to do with OS X 10.9.2, which I use. I have done numerous tests with the sort function in a little test site and it all works fine until I try dateTime together with set the useSystemDate to true, then nothing happens. I admit that my Language & Region and Date and Time setting are rather strange, too.

Post Reply