mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-07 23:40:21 -05:00
2333d04a54
- fixes #1264 - fixes #1321 - fixes #1799 - fixes #2689 - fixes #2688 - fixes #2687 - fixes #2686
78 lines
1.2 KiB
JavaScript
78 lines
1.2 KiB
JavaScript
const moment = require('moment')
|
|
const pluralize = require('pluralize')
|
|
|
|
const parse = function (ms) {
|
|
let mins = 0
|
|
|
|
const duration = moment.duration(ms)
|
|
|
|
const hours = duration.hours()
|
|
|
|
mins = hours * 60
|
|
|
|
return {
|
|
mins,
|
|
hours,
|
|
duration,
|
|
}
|
|
}
|
|
|
|
const long = function (ms, alwaysIncludeSeconds = true) {
|
|
let word
|
|
const msg = []
|
|
|
|
let { mins, duration } = parse(ms)
|
|
|
|
mins += duration.minutes()
|
|
|
|
if (mins) {
|
|
word = pluralize('minute', mins)
|
|
msg.push(`${mins} ${word}`)
|
|
}
|
|
|
|
const secs = duration.seconds()
|
|
|
|
if (alwaysIncludeSeconds || (secs > 0)) {
|
|
word = pluralize('second', secs)
|
|
msg.push(`${secs} ${word}`)
|
|
}
|
|
|
|
return msg.join(', ')
|
|
}
|
|
|
|
const short = function (ms) {
|
|
const msg = []
|
|
|
|
let { mins, duration } = parse(ms)
|
|
|
|
mins += duration.minutes()
|
|
|
|
if (mins) {
|
|
msg.push(`${mins}m`)
|
|
}
|
|
|
|
const secs = duration.seconds()
|
|
|
|
if (secs) {
|
|
msg.push(`${secs}s`)
|
|
} else {
|
|
if (!mins) {
|
|
const millis = duration.milliseconds()
|
|
|
|
if (millis) {
|
|
msg.push(`${millis}ms`)
|
|
} else {
|
|
msg.push(`${secs}s`)
|
|
}
|
|
}
|
|
}
|
|
|
|
return msg.join(', ')
|
|
}
|
|
|
|
module.exports = {
|
|
long,
|
|
|
|
short,
|
|
}
|