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))
}, [])
// Format playtime from seconds to hours
// Format playtime from seconds to hours and minutes
const formatPlayTime = (seconds: number) => {
const hours = Math.floor(seconds / 3600)
if (hours >= 1000000) {
return `${(hours / 1000000).toFixed(1)}M`
} else if (hours >= 1000) {
return `${(hours / 1000).toFixed(1)}K`
const minutes = Math.floor((seconds % 3600) / 60)
if (hours > 0) {
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