2019-03-31 18:56:48 +00:00
|
|
|
/**
|
|
|
|
|
* Return the relative time betweeen a chosen moment and the current time
|
2023-09-20 20:01:43 +00:00
|
|
|
* @param previous : time we want to get difference
|
2019-03-31 18:56:48 +00:00
|
|
|
*/
|
|
|
|
|
export function timeDifference(previous) {
|
2019-08-23 14:48:16 +00:00
|
|
|
const current = new Date()
|
|
|
|
|
const msPerMinute = 60 * 1000
|
|
|
|
|
const msPerHour = msPerMinute * 60
|
|
|
|
|
const msPerDay = msPerHour * 24
|
|
|
|
|
const msPerWeek = msPerDay * 7
|
|
|
|
|
const elapsed = current - previous
|
2019-03-31 18:56:48 +00:00
|
|
|
|
|
|
|
|
if (elapsed < msPerMinute) {
|
2019-09-20 21:32:28 +00:00
|
|
|
return Math.round(elapsed / 1000) + ' seconds ago'
|
2019-03-31 18:56:48 +00:00
|
|
|
} else if (elapsed < msPerHour) {
|
2019-09-20 21:32:28 +00:00
|
|
|
return Math.round(elapsed / msPerMinute) + ' minutes ago'
|
2019-03-31 18:56:48 +00:00
|
|
|
} else if (elapsed < msPerDay) {
|
2019-09-20 21:32:28 +00:00
|
|
|
return Math.round(elapsed / msPerHour) + ' hours ago'
|
2019-03-31 18:56:48 +00:00
|
|
|
} else if (elapsed < msPerWeek) {
|
2019-09-20 21:32:28 +00:00
|
|
|
return Math.round(elapsed / msPerDay) + ' days ago'
|
2019-03-31 18:56:48 +00:00
|
|
|
} else {
|
2020-04-03 10:40:22 +00:00
|
|
|
const dateOptions = { day: '2-digit', month: '2-digit', year: 'numeric' }
|
|
|
|
|
return new Date(previous).toLocaleString(undefined, dateOptions).replace(/\//g, '.')
|
2019-03-31 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-06-12 15:45:16 +00:00
|
|
|
|
2020-08-28 10:09:28 +00:00
|
|
|
/**
|
|
|
|
|
* Convert seconds to a readable string
|
2023-09-20 20:01:43 +00:00
|
|
|
* @param {Number} seconds
|
2020-08-28 10:09:28 +00:00
|
|
|
*/
|
|
|
|
|
export function secToTime(seconds) {
|
|
|
|
|
const min = Math.floor(seconds / 60)
|
|
|
|
|
let newSec = Math.floor(seconds - min * 60)
|
|
|
|
|
newSec = newSec < 10 ? '0' + newSec : newSec
|
2023-09-20 20:01:43 +00:00
|
|
|
|
2020-08-28 10:09:28 +00:00
|
|
|
return `${min}:${newSec}`
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-12 15:45:16 +00:00
|
|
|
/**
|
|
|
|
|
* Sort an array of players by role
|
|
|
|
|
*/
|
2020-08-28 10:09:28 +00:00
|
|
|
export function sortTeamByRole(a, b) {
|
2021-09-14 14:03:08 +00:00
|
|
|
const sortingArr = ['TOP', 'JUNGLE', 'MIDDLE', 'BOTTOM', 'UTILITY']
|
2020-06-12 15:45:16 +00:00
|
|
|
return sortingArr.indexOf(a.role) - sortingArr.indexOf(b.role)
|
|
|
|
|
}
|
2020-12-18 22:02:20 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Give the full CDragon image path from the iconPath field
|
2023-09-20 20:01:43 +00:00
|
|
|
* @param {String} iconPath
|
2020-12-18 22:02:20 +00:00
|
|
|
*/
|
|
|
|
|
export function createCDragonAssetUrl(iconPath) {
|
|
|
|
|
const name = iconPath.split('/assets/')[1].toLowerCase()
|
|
|
|
|
return `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/${name}`
|
|
|
|
|
}
|