Enhance playtime formatting to include hours and minutes; update localization for time in English and Chinese
This commit is contained in:
15
src/App.tsx
15
src/App.tsx
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user