sorting a list of dates and times (applescript)

Discussion in 'Mac Programming' started by wild4life2013, Sep 6, 2013.

  1. macrumors newbie

    Joined:
    Mar 13, 2013
    #1
    I am looking for a way to sort a list of dates and if there is a date the same then sort by time.

    Code:
    set a_RandomExampleList to {"Some Event 1/2/2014", "Another Event 2/6/2014", "Some Other Event 1/6/2014", "The Magic show 2/2/2014 14:00", "Band 2/2/2014 13:00"}
    thanks for any help
     
  2. macrumors 68000

    Joined:
    Sep 8, 2006
    #2
    I think your are going to need to post some real code for people to help you out with. If you have no examples of what you done then there is no way to help you resolve the problem.
     
  3. dmi
    macrumors regular

    Joined:
    Dec 21, 2010
    #3
    Code:
    set a_RandomExampleList to {"Some Event 1/2/2014", "Another Event 2/6/2014", "Some Other Event 1/6/2014", "The Magic show 2/2/2014 14:00", "Band 2/2/2014 13:00"}
    set old_delims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {ASCII character 10}
    set list_string to (a_RandomExampleList as string)
    set new_string to do shell script "echo " & quoted form of list_string & " | perl -e 'print map/\\0(.*)/s,sort map sprintf(qq(%4d%2d%2d%s\\0%s),(m{(.*?(\\d+)/(\\d+)/(\\d+)(.*))}s)[3,1,2,4,0]),<>'"
    set new_list to (paragraphs of new_string)
    set AppleScript's text item delimiters to old_delims
    return new_list
     

Share This Page