Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (11)
As of 2014-10-23 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (126 votes), past polls