|
34 | 34 |
|
35 | 35 | function CustomChat.NiceTime( time )
|
36 | 36 | local L = CustomChat.GetLanguageText
|
37 |
| - local s = time % 60 |
38 | 37 |
|
39 |
| - time = Floor( time / 60 ) |
40 |
| - local m = time % 60 |
41 |
| - |
42 |
| - time = Floor( time / 60 ) |
43 |
| - local h = time % 24 |
44 |
| - |
45 |
| - time = Floor( time / 24 ) |
46 |
| - local d = time % 7 |
47 |
| - local w = Floor( time / 7 ) |
48 |
| - |
49 |
| - if w > 0 then |
50 |
| - return w .. " " .. L( "time.weeks" ) |
| 38 | + local timeUnits = { |
| 39 | + { value = math.floor( time / ( 60 * 60 * 24 * 30 * 12 ) ), name = "time.years" }, |
| 40 | + { value = math.floor( time / ( 60 * 60 * 24 * 30 ) ) % 12, name = "time.months" }, |
| 41 | + { value = math.floor( time / ( 60 * 60 * 24 ) ) % 30, name = "time.days" }, |
| 42 | + { value = math.floor( time / ( 60 * 60 ) ) % 24, name = "time.hours" }, |
| 43 | + { value = math.floor( time / 60 ) % 60, name = "time.minutes" }, |
| 44 | + { value = time % 60, name = "time.seconds" } |
| 45 | + } |
| 46 | + |
| 47 | + local nonZeroUnits = {} |
| 48 | + for _, unit in ipairs( timeUnits ) do |
| 49 | + if unit.value > 0 then |
| 50 | + table.insert( nonZeroUnits, unit ) |
| 51 | + end |
51 | 52 | end
|
52 | 53 |
|
53 |
| - if d > 0 then |
54 |
| - return d .. " " .. L( "time.days" ) |
| 54 | + local selectedUnits = {} |
| 55 | + for i = 1, math.min( 2, #nonZeroUnits ) do |
| 56 | + table.insert( selectedUnits, nonZeroUnits[i] ) |
55 | 57 | end
|
56 | 58 |
|
57 |
| - if h > 0 then |
58 |
| - return h .. " " .. L( "time.hours" ) |
| 59 | + if #selectedUnits == 0 then |
| 60 | + return "0 " .. L( "time.seconds" ) |
59 | 61 | end
|
60 | 62 |
|
61 |
| - if m > 0 and h < 1 and d < 1 then |
62 |
| - return m .. " " .. L( "time.minutes" ) |
| 63 | + local parts = {} |
| 64 | + for _, unit in ipairs( selectedUnits ) do |
| 65 | + table.insert( parts, unit.value .. " " .. L( unit.name ) ) |
63 | 66 | end
|
64 | 67 |
|
65 |
| - return s .. " " .. L( "time.seconds" ) |
| 68 | + return table.concat( parts, ", " ) |
66 | 69 | end
|
67 | 70 |
|
68 | 71 | function CustomChat.PrintMessage( text )
|
|
0 commit comments