2019-03-31 18:56:48 +00:00
|
|
|
/**
|
|
|
|
|
* Return the relative time betweeen a chosen moment and the current time
|
|
|
|
|
* @param previous : time we want to get difference
|
|
|
|
|
*/
|
|
|
|
|
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-08-23 14:48:16 +00:00
|
|
|
return Math.round(elapsed / 1000) + 's'
|
2019-03-31 18:56:48 +00:00
|
|
|
} else if (elapsed < msPerHour) {
|
2019-08-23 14:48:16 +00:00
|
|
|
return Math.round(elapsed / msPerMinute) + 'm'
|
2019-03-31 18:56:48 +00:00
|
|
|
} else if (elapsed < msPerDay) {
|
2019-08-23 14:48:16 +00:00
|
|
|
return Math.round(elapsed / msPerHour) + 'h'
|
2019-03-31 18:56:48 +00:00
|
|
|
} else if (elapsed < msPerWeek) {
|
2019-08-23 14:48:16 +00:00
|
|
|
return Math.round(elapsed / msPerDay) + 'j'
|
2019-03-31 18:56:48 +00:00
|
|
|
} else {
|
2019-08-23 14:48:16 +00:00
|
|
|
const oldDate = new Date(previous)
|
|
|
|
|
const day = oldDate.getDate() < 10 ? '0' + oldDate.getDate() : oldDate.getDate()
|
|
|
|
|
const month = oldDate.getMonth() < 9 ? '0' + (oldDate.getMonth() + 1) : (oldDate.getMonth() + 1)
|
|
|
|
|
return day + '.' + month + '.' + oldDate.getFullYear().toString().substr(-2)
|
2019-03-31 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return time in a formatted way
|
|
|
|
|
* @param sec : time in seconds to convert
|
|
|
|
|
*/
|
|
|
|
|
export function secToTime(sec) {
|
2019-08-23 14:48:16 +00:00
|
|
|
const min = Math.floor(sec / 60)
|
|
|
|
|
const newSec = sec - min * 60
|
|
|
|
|
return min + ':' + (newSec < 10 ? '0' + newSec : newSec) //
|
2019-03-31 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the link of the rank image
|
|
|
|
|
* @param soloQStats : stats in soloQ of the player
|
|
|
|
|
*/
|
|
|
|
|
export function getRankImg(soloQStats) {
|
|
|
|
|
if (!soloQStats) {
|
2019-08-23 14:48:16 +00:00
|
|
|
return 'https://cdn.valentinkaelin.ch/riot/tier-icons/provisional.png'
|
2019-03-31 18:56:48 +00:00
|
|
|
}
|
2019-08-23 14:48:16 +00:00
|
|
|
return 'https://cdn.valentinkaelin.ch/riot/tier-icons/Emblem_' + capitalize(soloQStats.tier.toLowerCase()) + '.png'
|
2019-04-04 20:29:37 +00:00
|
|
|
}
|
2019-03-31 18:56:48 +00:00
|
|
|
|
2019-04-04 20:29:37 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Capitalize first letter of params string
|
|
|
|
|
* @param string : string to capitalize
|
|
|
|
|
*/
|
|
|
|
|
function capitalize(string) {
|
2019-08-23 14:48:16 +00:00
|
|
|
return string.charAt(0).toUpperCase() + string.slice(1)
|
2019-03-31 18:56:48 +00:00
|
|
|
}
|