]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/misc/utils.ts
add theming via css custom properties
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / misc / utils.ts
index 8381745f5fd4ad8394ea49949e64b269ab9d42d9..c8b7ebc67bf18eec6151f69b9636ce6f483842cb 100644 (file)
@@ -51,6 +51,18 @@ function dateToHuman (date: string) {
   return datePipe.transform(date, 'medium')
 }
 
+function durationToString (duration: number) {
+  const hours = Math.floor(duration / 3600)
+  const minutes = Math.floor((duration % 3600) / 60)
+  const seconds = duration % 60
+
+  const minutesPadding = minutes >= 10 ? '' : '0'
+  const secondsPadding = seconds >= 10 ? '' : '0'
+  const displayedHours = hours > 0 ? hours.toString() + ':' : ''
+
+  return displayedHours + minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
+}
+
 function immutableAssign <A, B> (target: A, source: B) {
   return Object.assign({}, target, source)
 }
@@ -101,7 +113,20 @@ function removeElementFromArray <T> (arr: T[], elem: T) {
   if (index !== -1) arr.splice(index, 1)
 }
 
+function sortBy (obj: any[], key1: string, key2?: string) {
+  return obj.sort((a, b) => {
+    const elem1 = key2 ? a[key1][key2] : a[key1]
+    const elem2 = key2 ? b[key1][key2] : b[key1]
+
+    if (elem1 < elem2) return -1
+    if (elem1 === elem2) return 0
+    return 1
+  })
+}
+
 export {
+  sortBy,
+  durationToString,
   objectToUrlEncoded,
   getParameterByName,
   populateAsyncUserVideoChannels,