import { default } from "https://deno.land/x/date_fns@v2.22.0/formatDuration/index.js";
Examples
// Format full duration
formatDuration({
years: 2,
months: 9,
weeks: 1,
days: 7,
hours: 5,
minutes: 9,
seconds: 30
})
//=> '2 years 9 months 1 week 7 days 5 hours 9 minutes 30 seconds
// Format full duration formatDuration({ years: 2, months: 9, weeks: 1, days: 7, hours: 5, minutes: 9, seconds: 30 }) //=> '2 years 9 months 1 week 7 days 5 hours 9 minutes 30 seconds
// Format partial duration
formatDuration({ months: 9, days: 2 })
//=> '9 months 2 days'
// Format partial duration formatDuration({ months: 9, days: 2 }) //=> '9 months 2 days'
// Customize the format
formatDuration(
{
years: 2,
months: 9,
weeks: 1,
days: 7,
hours: 5,
minutes: 9,
seconds: 30
},
{ format: ['months', 'weeks'] }
) === '9 months 1 week'
// Customize the format formatDuration( { years: 2, months: 9, weeks: 1, days: 7, hours: 5, minutes: 9, seconds: 30 }, { format: ['months', 'weeks'] } ) === '9 months 1 week'
// Customize the zeros presence
formatDuration({ years: 0, months: 9 })
//=> '9 months'
formatDuration({ years: 0, months: 9 }, { zero: true })
//=> '0 years 9 months'
// Customize the zeros presence formatDuration({ years: 0, months: 9 }) //=> '9 months' formatDuration({ years: 0, months: 9 }, { zero: true }) //=> '0 years 9 months'
// Customize the delimiter
formatDuration({ years: 2, months: 9, weeks: 3 }, { delimiter: ', ' })
//=> '2 years, 9 months, 3 weeks'
// Customize the delimiter formatDuration({ years: 2, months: 9, weeks: 3 }, { delimiter: ', ' }) //=> '2 years, 9 months, 3 weeks'