Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Hash sorting with dates and 12 hour time format.

by gwadej (Chaplain)
on Sep 15, 2009 at 21:09 UTC ( #795477=note: print w/ replies, xml ) Need Help??

in reply to Hash sorting with dates and 12 hour time format.

When working on a multi-key sort, it's important to text the items in the right order. In this case, you need to do the comparisons in the following order:

  1. month (9)
  2. day (10)
  3. am/pm (PM)
  4. hour (12)
  5. minute (45)

In addition, you will need to deal with the fact that 12:01 AM should sort to less than 1:00 AM. Your months also won't sort nicely ('10' sorting to less than '9').

You could break this string into a series of sub-keys and compare them in order, or pack them up into a fixed-field string that sorts how you want.

Once you've figured out your key, you'll want to apply either the Schwartzian Transform or the Guttman Rosler Transform to the problem.

Update: Added links for the algorithms.

G. Wade

Comment on Re: Hash sorting with dates and 12 hour time format.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://795477]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2016-02-14 17:47 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (470 votes), past polls