Rev 6775 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
const getYears = () => {
const date = new Date()
const currentYear = date.getFullYear()
let years = []
for (let index = currentYear; index > currentYear - 100; index--) {
years = [...years, index]
}
return years
}
const getMonths = () => {
const months = Array.from({ length: 12 }, (item, i) => {
return new Date(0, i).toLocaleString('es-ES', { month: 'long' })
})
return months
}
const getMonthName = (monthNumber) => {
const date = new Date()
date.setMonth(monthNumber - 1)
const month = date.toLocaleString('es-ES', { month: 'long' })
return month
}
const DATE_UNITS = {
year: 31557600,
month: 2628000,
day: 86000,
hour: 3600,
minute: 60,
second: 1,
}
const rft = new Intl.RelativeTimeFormat('en', { numeric: 'auto' })
const getRelativeTime = (time) => {
const started = new Date(time + 1000).getTime()
const now = new Date().getTime()
const elapsed = (started - now) / 1000
for (const unit in DATE_UNITS) {
const absoluteElapsed = Math.abs(elapsed)
if (absoluteElapsed > DATE_UNITS[unit] || unit === 'second') {
return rft.format(Math.floor(elapsed / DATE_UNITS[unit]), unit)
}
}
return ''
}
export { getYears, getMonthName, getMonths, getRelativeTime }