Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
fix(download-tab): Displays correct duration
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-heimbuch committed Apr 7, 2018
1 parent 4b284e6 commit 9096834
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/tabs/download/Download.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script>
import { compose } from 'lodash'
import store from 'store'
import { calcHours, calcMinutes, localeDate } from 'utils/time'
import { calcHours, calcMinutes, localeDate, fromPlayerTime } from 'utils/time'
import ButtonComponent from 'shared/Button'
import InputSelectComponent from 'shared/InputSelect'
Expand Down
6 changes: 3 additions & 3 deletions src/components/tabs/info/Info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</template>

<script>
import { calcHours, calcMinutes, localeDate, localeTime, millisecondsToSeconds } from 'utils/time'
import { calcHours, calcMinutes, localeDate, localeTime } from 'utils/time'
import CalendarIcon from 'icons/CalendarIcon'
import ClockIcon from 'icons/ClockIcon'
Expand All @@ -53,8 +53,8 @@
computed: {
episodeDuration () {
return {
hours: calcHours(millisecondsToSeconds(this.duration)),
minutes: calcMinutes(millisecondsToSeconds(this.duration))
hours: calcHours(this.duration),
minutes: calcMinutes(this.duration)
}
},
sectionStyle () {
Expand Down
10 changes: 4 additions & 6 deletions src/utils/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@ export const toPlayerTime = (time = '0') => {
return (hours * 60 * 60 * 1000) + (minutes * 60 * 1000) + (seconds * 1000) + milliseconds
}

export const calcSeconds = (time = 0) => parseInt(time % 60)
export const calcMinutes = (time = 0) => parseInt(time / 60) % 60
export const calcHours = (time = 0) => parseInt(time / 3600) % 24

export const localeDate = (timestamp, locale) => new Date(timestamp).toLocaleDateString(locale)
export const localeTime = (timestamp, locale) => new Date(timestamp).toLocaleTimeString(locale, {hour: '2-digit', minute: '2-digit'})

const leadingZero = time => time > 9 ? `${time}` : `0${time}`

// Transforms milliseconds to (hh:)mm:ss
export const fromPlayerTime = (time = 0) => {
time = time < 0 ? 0 : time / 1000

let hours = compose(calcHours, toInt)(time)
let minutes = compose(calcMinutes, toInt)(time)
let seconds = compose(calcSeconds, toInt)(time)
Expand All @@ -54,3 +48,7 @@ export const fromPlayerTime = (time = 0) => {
export const secondsToMilliseconds = compose(toInt, input => input * 1000, toFloat)
export const millisecondsToSeconds = compose(toFloat, input => input / 1000, toInt)
export const parseDate = (utcDate) => utcDate ? new Date(utcDate).getTime() : null

export const calcSeconds = compose((time = 0) => parseInt(time % 60), millisecondsToSeconds)
export const calcMinutes = compose((time = 0) => parseInt(time / 60) % 60, millisecondsToSeconds)
export const calcHours = compose((time = 0) => parseInt(time / 3600) % 24, millisecondsToSeconds)

0 comments on commit 9096834

Please sign in to comment.