Enhance playtime formatting to include hours and minutes; update localization for time in English and Chinese

This commit is contained in:
2025-10-04 18:32:06 +08:00
parent 0174ac83e9
commit 89f18d1641
3 changed files with 15 additions and 20 deletions

View File

@@ -122,15 +122,18 @@ function App() {
.catch(error => console.error('Error fetching top players:', error)) .catch(error => console.error('Error fetching top players:', error))
}, []) }, [])
// Format playtime from seconds to hours // Format playtime from seconds to hours and minutes
const formatPlayTime = (seconds: number) => { const formatPlayTime = (seconds: number) => {
const hours = Math.floor(seconds / 3600) const hours = Math.floor(seconds / 3600)
if (hours >= 1000000) { const minutes = Math.floor((seconds % 3600) / 60)
return `${(hours / 1000000).toFixed(1)}M`
} else if (hours >= 1000) { if (hours > 0) {
return `${(hours / 1000).toFixed(1)}K` if (minutes > 0) {
return `${hours}${t('time.hours')} ${minutes}${t('time.minutes')}`
}
return `${hours}${t('time.hours')}`
} }
return hours.toLocaleString() return `${minutes}${t('time.minutes')}`
} }
// Format time ago from timestamp // Format time ago from timestamp

View File

@@ -51,13 +51,9 @@
"joinForum": "Join Forum", "joinForum": "Join Forum",
"viewFriends": "View Friends" "viewFriends": "View Friends"
}, },
"activity": { "time": {
"title": "Recent Activity", "hours": "h",
"topPlayers": "Top Players by Playtime", "minutes": "m"
"serverInfo": "Server Info",
"serverStatus": "Status: Online ✓",
"currentMap": "Map: de_dust2",
"nextRestart": "Restart: 6h 30m"
}, },
"footer": { "footer": {
"community": "🎯 CS Community", "community": "🎯 CS Community",

View File

@@ -50,13 +50,9 @@
"joinForum": "加入论坛", "joinForum": "加入论坛",
"viewFriends": "查看友链" "viewFriends": "查看友链"
}, },
"activity": { "time": {
"title": "最近活动", "hours": "小时",
"topPlayers": "游戏时长排行榜", "minutes": "分钟"
"serverInfo": "服务器信息",
"serverStatus": "状态:在线 ✓",
"currentMap": "地图de_dust2",
"nextRestart": "重启6小时30分钟"
}, },
"footer": { "footer": {
"community": "🎯 CS 社区", "community": "🎯 CS 社区",