@@ -241,19 +241,21 @@ export function formatDuration(duration: number): string {
241241 // hace 10 horas/hace 2 días/hace 3 semanas/hace 1 mes/hace 1 año
242242 // biggest unit, round down
243243 const units = [
244- { label : 'año' , value : 1000 * 60 * 60 * 24 * 365 } ,
245- { label : 'mes' , value : 1000 * 60 * 60 * 24 * 30 } ,
246- { label : 'semana' , value : 1000 * 60 * 60 * 24 * 7 } ,
247- { label : 'día' , value : 1000 * 60 * 60 * 24 } ,
248- { label : 'hora' , value : 1000 * 60 * 60 } ,
249- { label : 'minuto' , value : 1000 * 60 } ,
250- { label : 'segundo' , value : 1000 } ,
244+ { label : 'año' , plural : 'años' , value : 1000 * 60 * 60 * 24 * 365 } ,
245+ { label : 'mes' , plural : 'meses' , value : 1000 * 60 * 60 * 24 * 30 } ,
246+ { label : 'semana' , plural : 'semanas' , value : 1000 * 60 * 60 * 24 * 7 } ,
247+ { label : 'día' , plural : 'días' , value : 1000 * 60 * 60 * 24 } ,
248+ { label : 'hora' , plural : 'horas' , value : 1000 * 60 * 60 } ,
249+ { label : 'minuto' , plural : 'minutos' , value : 1000 * 60 } ,
250+ { label : 'segundo' , plural : 'segundos' , value : 1000 } ,
251251 ]
252+ const diffMs = Math . abs ( Date . now ( ) - duration )
252253 for ( const unit of units ) {
253- const diff = Math . abs ( Date . now ( ) - duration ) / unit . value
254+ const diff = diffMs / unit . value
254255 if ( diff >= 1 ) {
255- return `${ Math . floor ( diff ) } ${ unit . label } ${ Math . floor ( diff ) > 1 ? 's' : '' } `
256+ const count = Math . floor ( diff )
257+ return `hace ${ count } ${ count > 1 ? unit . plural : unit . label } `
256258 }
257259 }
258- return 'un instante'
259- }
260+ return 'hace un instante'
261+ }
0 commit comments