Skip to content

Instantly share code, notes, and snippets.

@christianvmm
Created March 4, 2024 04:47
Show Gist options
  • Select an option

  • Save christianvmm/ddbedece8ef3fb236013c0fd2bd39944 to your computer and use it in GitHub Desktop.

Select an option

Save christianvmm/ddbedece8ef3fb236013c0fd2bd39944 to your computer and use it in GitHub Desktop.
timeago.js en español
import { type LocaleFunc, type TDate, format, register } from 'timeago.js'
const localeFunc: LocaleFunc = (_: number, idx: number, __?: number) => {
// number: the timeago / timein number;
// index: the index of array below;
// totalSec: total seconds between date to be formatted and today's date;
return [
['justo ahora', 'justo ahora'],
['hace %s segundos', 'en %s segundos'],
['hace 1 minuto', 'en 1 minuto'],
['hace %s minutos', 'en %s minutos'],
['hace 1 hora', 'en 1 hora'],
['hace %s horas', 'en %s horas'],
['hace 1 día', 'en 1 día'],
['hace %s días', 'en %s días'],
['hace 1 semana', 'en 1 semana'],
['hace %s semanas', 'en %s semanas'],
['hace 1 mes', 'en 1 mes'],
['hace %s meses', 'en %s meses'],
['hace 1 año', 'en 1 año'],
['hace %s años', 'en %s años'],
][idx] as [string, string]
}
register('es', localeFunc)
export function timeago(date: TDate) {
return format(date, 'es')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment