Quantcast
WoWInterface - View Single Post - sort by date
Thread: sort by date
View Single Post
06-17-20, 10:03 PM   #4
Ketho
A Molten Giant
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 962
I think you should do what Gello said and store it in a more manageable format. There is probably a better approach to all this

As for sorting your example, this sorts DDMMYY
Lua Code:
  1. SAVES = {
  2.     ["150620"] = 51745398698,
  3.     ["140620"] = 51547835967,
  4.     ["130620"] = 51534872357,
  5.     ["110116"] = 51534872357,
  6.     ["130619"] = 51534872357,
  7.     ["250618"] = 51534872357,
  8.     ["160620"] = 51989680638,
  9.     ["170620"] = 52179106978,
  10.     ["150618"] = 51534872357,
  11.     ["150517"] = 51534872357,
  12.     ["250518"] = 51534872357,
  13.     ["110517"] = 51534872357,
  14. }
  15.  
  16. local t = {}
  17. for timestamp in pairs(SAVES) do
  18.     table.insert(t, timestamp)
  19. end
  20. table.sort(t, function(a, b)
  21.     local day1, month1, year1 = a:match("(%d%d)(%d%d)(%d%d)")
  22.     local day2, month2, year2 = b:match("(%d%d)(%d%d)(%d%d)")
  23.     if year1 ~= year2 then
  24.         return year1 < year2
  25.     elseif month1 ~= month2 then
  26.         return month1 < month2
  27.     elseif day1 ~= day2 then
  28.         return day1 < day2
  29.     end
  30. end)
  31.  
  32. for _, timestamp in pairs(t) do
  33.     print(timestamp, SAVES[timestamp])
  34. end
Code:
110116  51534872357
110517  51534872357
150517  51534872357
250518  51534872357
150618  51534872357
250618  51534872357
130619  51534872357
130620  51534872357
140620  51547835967
150620  51745398698
160620  51989680638
170620  52179106978
  Reply With Quote