Skip to content

Commit

Permalink
feat: 组件传入 prop 支持 milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
shoyuf committed Nov 6, 2019
1 parent 68c8e96 commit e437bf9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/count-down.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ export default {
type: Number,
default: 0
},
/**
* remain milliseconds
*/
milliseconds: {
type: Number,
default: 0
},
/**
* whether autoplay or not
*/
Expand Down
8 changes: 4 additions & 4 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const formatSpecifiers = {
seconds: 'ss',
milliseconds: 'ms'
}
const secondsIn = {
const millisecondsIn = {
days: 60 * 60 * 24 * 1000,
hours: 60 * 60 * 1000,
minutes: 60 * 1000,
Expand Down Expand Up @@ -77,8 +77,8 @@ export function formatTime(time, format) {
// 注意顺序很重要。要先从大的时间单位开始构造字符串
entries(formatSpecifiers).forEach(([k, specifier]) => {
if (includes(result, specifier)) {
const v = Math.floor(time / secondsIn[k])
time -= v * secondsIn[k]
const v = Math.floor(time / millisecondsIn[k])
time -= v * millisecondsIn[k]
result = result.replace(specifier, timeFormatter(k, v))
}
})
Expand All @@ -92,7 +92,7 @@ export function formatTime(time, format) {
*/
export function toTimeData(time) {
const timeData = {}
entries(secondsIn).forEach(([k, v]) => {
entries(millisecondsIn).forEach(([k, v]) => {
timeData[k] = Math.floor(time / v)
time -= timeData[k] * v
})
Expand Down

0 comments on commit e437bf9

Please sign in to comment.