aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-03-07 17:06:00 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-03-18 11:17:59 +0100
commitf0a3988066f72a28bb44520af072f18d91d77dde (patch)
treedfa3a92102557b567530c5dd014c90866621140a /client/src/assets/player/utils.ts
parent830b4faff15fb9c81d88e8e69fcdf94aad32bef8 (diff)
downloadPeerTube-f0a3988066f72a28bb44520af072f18d91d77dde.tar.gz
PeerTube-f0a3988066f72a28bb44520af072f18d91d77dde.tar.zst
PeerTube-f0a3988066f72a28bb44520af072f18d91d77dde.zip
Add to playlist dropdown
Diffstat (limited to 'client/src/assets/player/utils.ts')
-rw-r--r--client/src/assets/player/utils.ts20
1 files changed, 15 insertions, 5 deletions
diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts
index 8d87567c2..54f131310 100644
--- a/client/src/assets/player/utils.ts
+++ b/client/src/assets/player/utils.ts
@@ -42,7 +42,7 @@ function timeToInt (time: number | string) {
42 if (!time) return 0 42 if (!time) return 0
43 if (typeof time === 'number') return time 43 if (typeof time === 'number') return time
44 44
45 const reg = /^((\d+)h)?((\d+)m)?((\d+)s?)?$/ 45 const reg = /^((\d+)[h:])?((\d+)[m:])?((\d+)s?)?$/
46 const matches = time.match(reg) 46 const matches = time.match(reg)
47 47
48 if (!matches) return 0 48 if (!matches) return 0
@@ -54,18 +54,27 @@ function timeToInt (time: number | string) {
54 return hours * 3600 + minutes * 60 + seconds 54 return hours * 3600 + minutes * 60 + seconds
55} 55}
56 56
57function secondsToTime (seconds: number) { 57function secondsToTime (seconds: number, full = false, symbol?: string) {
58 let time = '' 58 let time = ''
59 59
60 const hourSymbol = (symbol || 'h')
61 const minuteSymbol = (symbol || 'm')
62 const secondsSymbol = full ? '' : 's'
63
60 let hours = Math.floor(seconds / 3600) 64 let hours = Math.floor(seconds / 3600)
61 if (hours >= 1) time = hours + 'h' 65 if (hours >= 1) time = hours + hourSymbol
66 else if (full) time = '0' + hourSymbol
62 67
63 seconds %= 3600 68 seconds %= 3600
64 let minutes = Math.floor(seconds / 60) 69 let minutes = Math.floor(seconds / 60)
65 if (minutes >= 1) time += minutes + 'm' 70 if (minutes >= 1 && minutes < 10 && full) time += '0' + minutes + minuteSymbol
71 else if (minutes >= 1) time += minutes + minuteSymbol
72 else if (full) time += '00' + minuteSymbol
66 73
67 seconds %= 60 74 seconds %= 60
68 if (seconds >= 1) time += seconds + 's' 75 if (seconds >= 1 && seconds < 10 && full) time += '0' + seconds + secondsSymbol
76 else if (seconds >= 1) time += seconds + secondsSymbol
77 else if (full) time += '00'
69 78
70 return time 79 return time
71} 80}
@@ -131,6 +140,7 @@ export {
131 getRtcConfig, 140 getRtcConfig,
132 toTitleCase, 141 toTitleCase,
133 timeToInt, 142 timeToInt,
143 secondsToTime,
134 buildVideoLink, 144 buildVideoLink,
135 buildVideoEmbed, 145 buildVideoEmbed,
136 videoFileMaxByResolution, 146 videoFileMaxByResolution,