views:

64

answers:

1

I've got an array items[] Each item in items[] is a struct. item has keys id, date, value (i.e., item.id, item.date, item.value)

I want to use StructSort to sort the item collection by a date

Is this the best way to do it in ColdFusion 8:

<cfset allStructs = StructNew()>
<cfloop array = #items# index = "item">
    <cfset allStructs[item.id] = item>
    <cfset unixtime = DateDiff("s", CreateDate(1970,1,1), item.date)>
    <cfset allStructs[item.id].unixtime = unixtime>
</cfloop>
<cfset allStructs = StructSort(allStructs, "numeric", "desc", "unixtime")>

It's going to be dreadfully slow

+3  A: 

You will still need to convert to unixtime, but ArrayOfStructsSort might be faster. At least you can compare the two options.

Lawrence Barsanti
Ooooh thanks. I'll do a comparison. Right now I decided to cache the sorted struct into the session, so only the initial load for the session is slow (~3-5s avg). (also not using application scope because these are session specific values already and i don't need a bunch of crazy locking)
davidosomething