dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

[Feature request] `duration.asObject()`

Open KaKi87 opened this issue 1 month ago • 1 comments

Hi,

It would be nice to have an asObject method on durations, e.g. to convert a number of milliseconds into { years, months, weeks, days, hours, minutes, seconds }.

That would be a shorthand for the following :

const durationAsObject = duration => ({
    years: duration.years(),
    months: duration.months(),
    days: duration.days(),
    hours: duration.hours(),
    minutes: duration.minutes(),
    seconds: duration.seconds()
});

Thanks

KaKi87 avatar Nov 16 '25 18:11 KaKi87

Hi @KaKi87 , thanks for the great feature suggestion!

I've just submitted a Pull Request that implements this feature, including the new method, TypeScript definitions, and a full test suite.

bhavyajain-glitch avatar Nov 17 '25 20:11 bhavyajain-glitch