Skip to content

Commit 4b8ada7

Browse files
committed
Improve CustomChat.NiceTime
1 parent 9012854 commit 4b8ada7

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

lua/custom_chat/client/main.lua

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,38 @@ end
3434

3535
function CustomChat.NiceTime( time )
3636
local L = CustomChat.GetLanguageText
37-
local s = time % 60
3837

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
5152
end
5253

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] )
5557
end
5658

57-
if h > 0 then
58-
return h .. " " .. L( "time.hours" )
59+
if #selectedUnits == 0 then
60+
return "0 " .. L( "time.seconds" )
5961
end
6062

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 ) )
6366
end
6467

65-
return s .. " " .. L( "time.seconds" )
68+
return table.concat( parts, ", " )
6669
end
6770

6871
function CustomChat.PrintMessage( text )

resource/localization/en/custom_chat.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ custom_chat.server_theme.tip=This action will force all players (including those
147147
custom_chat.friend_spawned1=Your friend
148148
custom_chat.friend_spawned2=has spawned in.
149149
custom_chat.last_seen1=last played
150+
custom_chat.time.years=years
151+
custom_chat.time.months=months
150152
custom_chat.time.weeks=weeks
151153
custom_chat.time.days=days
152154
custom_chat.time.hours=hours

resource/localization/pt-br/custom_chat.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ custom_chat.server_theme.tip=Esta ação forçará todos os jogadores (incluindo
146146
custom_chat.friend_spawned1=Seu amigo
147147
custom_chat.friend_spawned2=acabou de aparecer aqui.
148148
custom_chat.last_seen1=jogou pela última vez há
149+
custom_chat.time.years=anos
150+
custom_chat.time.months=meses
149151
custom_chat.time.weeks=semanas
150152
custom_chat.time.days=dias
151153
custom_chat.time.hours=horas

resource/localization/ru/custom_chat.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ custom_chat.server_theme.tip=Это действие заставит всех
146146
custom_chat.friend_spawned1=Ваш друг
147147
custom_chat.friend_spawned2=загрузился.
148148
custom_chat.last_seen1=заходил последний раз
149+
custom_chat.time.years=лет
150+
custom_chat.time.months=месяцев
149151
custom_chat.time.weeks=нед.
150152
custom_chat.time.days=д.
151153
custom_chat.time.hours=ч.

resource/localization/tr/custom_chat.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ custom_chat.server_theme.tip=Bu işlem, tüm oyuncuları (daha sonra katılanlar
147147
custom_chat.friend_spawned1=Arkadaşın
148148
custom_chat.friend_spawned2=burada.
149149
custom_chat.last_seen1=en son
150+
custom_chat.time.years=yıl
151+
custom_chat.time.months=aylar
150152
custom_chat.time.weeks=hafta
151153
custom_chat.time.days=gün
152154
custom_chat.time.hours=saat

0 commit comments

Comments
 (0)