Skip to content

Commit c650578

Browse files
committed
Only show second time if we're above a month
1 parent 4b8ada7 commit c650578

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lua/custom_chat/client/main.lua

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,20 @@ function CustomChat.GetLanguageText( id )
3232
return language.GetPhrase( "custom_chat." .. id )
3333
end
3434

35+
local year = 60 * 60 * 24 * 365
36+
local month = 60 * 60 * 24 * 30
37+
local day = 60 * 60 * 24
38+
local hour = 60 * 60
39+
local minute = 60
3540
function CustomChat.NiceTime( time )
3641
local L = CustomChat.GetLanguageText
3742

3843
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 = math.floor( time / year ), name = "time.years" },
45+
{ value = math.floor( time / month ) % 12, name = "time.months" },
46+
{ value = math.floor( time / day ) % 30, name = "time.days" },
47+
{ value = math.floor( time / hour ) % 24, name = "time.hours" },
48+
{ value = math.floor( time / minute ) % 60, name = "time.minutes" },
4449
{ value = time % 60, name = "time.seconds" }
4550
}
4651

@@ -52,7 +57,11 @@ function CustomChat.NiceTime( time )
5257
end
5358

5459
local selectedUnits = {}
55-
for i = 1, math.min( 2, #nonZeroUnits ) do
60+
local unitsToShow = 1
61+
if time > month then
62+
unitsToShow = 2
63+
end
64+
for i = 1, math.min( unitsToShow, #nonZeroUnits ) do
5665
table.insert( selectedUnits, nonZeroUnits[i] )
5766
end
5867

0 commit comments

Comments
 (0)