aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/misc/utils.ts13
-rw-r--r--client/src/app/shared/video/video.model.ts16
2 files changed, 15 insertions, 14 deletions
diff --git a/client/src/app/shared/misc/utils.ts b/client/src/app/shared/misc/utils.ts
index 018271efe..c8b7ebc67 100644
--- a/client/src/app/shared/misc/utils.ts
+++ b/client/src/app/shared/misc/utils.ts
@@ -51,6 +51,18 @@ function dateToHuman (date: string) {
51 return datePipe.transform(date, 'medium') 51 return datePipe.transform(date, 'medium')
52} 52}
53 53
54function durationToString (duration: number) {
55 const hours = Math.floor(duration / 3600)
56 const minutes = Math.floor((duration % 3600) / 60)
57 const seconds = duration % 60
58
59 const minutesPadding = minutes >= 10 ? '' : '0'
60 const secondsPadding = seconds >= 10 ? '' : '0'
61 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
62
63 return displayedHours + minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
64}
65
54function immutableAssign <A, B> (target: A, source: B) { 66function immutableAssign <A, B> (target: A, source: B) {
55 return Object.assign({}, target, source) 67 return Object.assign({}, target, source)
56} 68}
@@ -114,6 +126,7 @@ function sortBy (obj: any[], key1: string, key2?: string) {
114 126
115export { 127export {
116 sortBy, 128 sortBy,
129 durationToString,
117 objectToUrlEncoded, 130 objectToUrlEncoded,
118 getParameterByName, 131 getParameterByName,
119 populateAsyncUserVideoChannels, 132 populateAsyncUserVideoChannels,
diff --git a/client/src/app/shared/video/video.model.ts b/client/src/app/shared/video/video.model.ts
index d80c10459..80794faa6 100644
--- a/client/src/app/shared/video/video.model.ts
+++ b/client/src/app/shared/video/video.model.ts
@@ -2,7 +2,7 @@ import { User } from '../'
2import { Video as VideoServerModel, VideoPrivacy, VideoState } from '../../../../../shared' 2import { Video as VideoServerModel, VideoPrivacy, VideoState } from '../../../../../shared'
3import { Avatar } from '../../../../../shared/models/avatars/avatar.model' 3import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
4import { VideoConstant } from '../../../../../shared/models/videos/video-constant.model' 4import { VideoConstant } from '../../../../../shared/models/videos/video-constant.model'
5import { getAbsoluteAPIUrl } from '../misc/utils' 5import { durationToString, getAbsoluteAPIUrl } from '../misc/utils'
6import { peertubeTranslate, ServerConfig } from '../../../../../shared/models' 6import { peertubeTranslate, ServerConfig } from '../../../../../shared/models'
7import { Actor } from '@app/shared/actor/actor.model' 7import { Actor } from '@app/shared/actor/actor.model'
8import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model' 8import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model'
@@ -70,18 +70,6 @@ export class Video implements VideoServerModel {
70 return '/videos/watch/' + videoUUID 70 return '/videos/watch/' + videoUUID
71 } 71 }
72 72
73 private static createDurationString (duration: number) {
74 const hours = Math.floor(duration / 3600)
75 const minutes = Math.floor((duration % 3600) / 60)
76 const seconds = duration % 60
77
78 const minutesPadding = minutes >= 10 ? '' : '0'
79 const secondsPadding = seconds >= 10 ? '' : '0'
80 const displayedHours = hours > 0 ? hours.toString() + ':' : ''
81
82 return displayedHours + minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString()
83 }
84
85 constructor (hash: VideoServerModel, translations = {}) { 73 constructor (hash: VideoServerModel, translations = {}) {
86 const absoluteAPIUrl = getAbsoluteAPIUrl() 74 const absoluteAPIUrl = getAbsoluteAPIUrl()
87 75
@@ -95,7 +83,7 @@ export class Video implements VideoServerModel {
95 this.state = hash.state 83 this.state = hash.state
96 this.description = hash.description 84 this.description = hash.description
97 this.duration = hash.duration 85 this.duration = hash.duration
98 this.durationLabel = Video.createDurationString(hash.duration) 86 this.durationLabel = durationToString(hash.duration)
99 this.id = hash.id 87 this.id = hash.id
100 this.uuid = hash.uuid 88 this.uuid = hash.uuid
101 this.isLocal = hash.isLocal 89 this.isLocal = hash.isLocal