mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Merge pull request #4493 from advplyr/localize_durations
Localize elapsed duration on sessions tables
This commit is contained in:
		
						commit
						e25e2b238f
					
				| @ -68,7 +68,7 @@ | ||||
|               <p class="text-xs truncate" v-html="getDeviceInfoString(session.deviceInfo)" /> | ||||
|             </td> | ||||
|             <td class="text-center w-24 min-w-24 sm:w-32 sm:min-w-32"> | ||||
|               <p class="text-xs font-mono">{{ $elapsedPretty(session.timeListening) }}</p> | ||||
|               <p class="text-xs font-mono">{{ $elapsedPrettyLocalized(session.timeListening) }}</p> | ||||
|             </td> | ||||
|             <td class="text-center hover:underline w-24 min-w-24" @click.stop="clickCurrentTime(session)"> | ||||
|               <p class="text-xs font-mono">{{ $secondsToTimestamp(session.currentTime) }}</p> | ||||
|  | ||||
| @ -40,7 +40,7 @@ | ||||
|                 <p class="text-xs truncate" v-html="getDeviceInfoString(session.deviceInfo)" /> | ||||
|               </td> | ||||
|               <td class="text-center"> | ||||
|                 <p class="text-xs font-mono">{{ $elapsedPretty(session.timeListening) }}</p> | ||||
|                 <p class="text-xs font-mono">{{ $elapsedPrettyLocalized(session.timeListening) }}</p> | ||||
|               </td> | ||||
|               <td class="text-center hover:underline" @click.stop="clickCurrentTime(session)"> | ||||
|                 <p class="text-xs font-mono">{{ $secondsToTimestamp(session.currentTime) }}</p> | ||||
|  | ||||
| @ -37,6 +37,48 @@ Vue.prototype.$elapsedPretty = (seconds, useFullNames = false, useMilliseconds = | ||||
|   return `${hours} ${useFullNames ? `hour${hours === 1 ? '' : 's'}` : 'hr'} ${minutes} ${useFullNames ? `minute${minutes === 1 ? '' : 's'}` : 'min'}` | ||||
| } | ||||
| 
 | ||||
| Vue.prototype.$elapsedPrettyLocalized = (seconds, useFullNames = false, useMilliseconds = false) => { | ||||
|   if (isNaN(seconds) || seconds === null) return '' | ||||
| 
 | ||||
|   try { | ||||
|     const df = new Intl.DurationFormat(Vue.prototype.$languageCodes.current, { | ||||
|       style: useFullNames ? 'long' : 'short' | ||||
|     }) | ||||
| 
 | ||||
|     const duration = {} | ||||
| 
 | ||||
|     if (seconds < 60) { | ||||
|       if (useMilliseconds && seconds < 1) { | ||||
|         duration.milliseconds = Math.floor(seconds * 1000) | ||||
|       } else { | ||||
|         duration.seconds = Math.floor(seconds) | ||||
|       } | ||||
|     } else if (seconds < 3600) { | ||||
|       // 1 hour
 | ||||
|       duration.minutes = Math.floor(seconds / 60) | ||||
|     } else if (seconds < 86400) { | ||||
|       // 1 day
 | ||||
|       duration.hours = Math.floor(seconds / 3600) | ||||
|       const minutes = Math.floor((seconds % 3600) / 60) | ||||
|       if (minutes > 0) { | ||||
|         duration.minutes = minutes | ||||
|       } | ||||
|     } else { | ||||
|       duration.days = Math.floor(seconds / 86400) | ||||
|       const hours = Math.floor((seconds % 86400) / 3600) | ||||
|       if (hours > 0) { | ||||
|         duration.hours = hours | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     return df.format(duration) | ||||
|   } catch (error) { | ||||
|     // Handle not supported
 | ||||
|     console.warn('Intl.DurationFormat not supported, not localizing duration') | ||||
|     return Vue.prototype.$elapsedPretty(seconds, useFullNames, useMilliseconds) | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| Vue.prototype.$secondsToTimestamp = (seconds, includeMs = false, alwaysIncludeHours = false) => { | ||||
|   if (!seconds) { | ||||
|     return alwaysIncludeHours ? '00:00:00' : '0:00' | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user