Page 1 of 1

Sorting by date

Posted: Thu Mar 06, 2014 5:41 pm
by exheusden
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?

Re: Sorting by date

Posted: Thu Mar 06, 2014 6:26 pm
by dunbarx
The code works for me.

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

Craig Newman

Re: Sorting by date

Posted: Thu Mar 06, 2014 6:33 pm
by exheusden
In System Preferences, what are your settings for Language and Region and specifically for Date and Time?

Image
Image

Re: Sorting by date

Posted: Thu Mar 06, 2014 6:55 pm
by dunbarx
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

Re: Sorting by date

Posted: Thu Mar 06, 2014 7:35 pm
by bn
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

Re: Sorting by date

Posted: Thu Mar 06, 2014 8:22 pm
by exheusden
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.