• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

Sort distance_of_time_in_words hash

I have a hash with the key generated by distance_of_time_in_words. I want to be able to sort that hash chronologically instead of alphabetically. How would I do that?

i.e., the keys in my hash are "6 days", "25 days", "5 months". I want to sort it in that order but what happens is the .sort method sorts it alphabetically and puts it "25 days", "5 months", "6 days".
0
victornegri
Asked:
victornegri
  • 3
  • 2
1 Solution
 
Andrew DoadesCommented:
Can you not use the DESC ASC after the .sort?
0
 
victornegriAuthor Commented:
DESC and ASC don't change the way the sort function works. I need to change the sort so that it sorts chronologically and not alphabetically.

Is there a way to change the results of distance_of_time_in_words back to a date value first, sort it, and then change it back to distance_of_time_in_words?
0
 
karfiCommented:
You should sort your data by the original date value and after that you can translate the date to string with distance_of_time_in_words.

By the way, you lose some information after using distance_of_time_in_words method, so sorting by the string value can give you different result from sorting by the "real" date format.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
victornegriAuthor Commented:
But then how do I group by the distance_of_time_in_words value after sorting by the original date? Do I need to write a new method?
0
 
karfiCommented:
just check the other thread, maybe there is the solution.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now