dayjs
dayjs copied to clipboard
Duration Big Bug
const endTime = dayjs.unix(1716998400).add(32, 'day'); // 2024/7/1/ 00:00:00 const now = dayjs(); // 2024/5/30 13:50:50
const duration = dayjs.duration(endTime.diff(now));
console.log(duration.hours()); // output is "0" which should be "10" // when change 32 to 30, the hours func returns 10
dayjs 1.11.11
The problem occurs when the difference become 31 days.
const now = dayjs('2024-05-02T01:00:00');
const future30 = now.add(30, 'day');
const duration30 = dayjs.duration(future30.diff(now));
console.log(duration30.hours()); // 🆗 returns 0
console.log('iso', duration30); // "P30D"
const future31 = now.add(31, 'day');
const duration31 = dayjs.duration(future31.diff(now));
console.log(duration31.hours()); // 💥 returns 14
console.log('iso', duration31); // "P1MT14H"
https://github.com/iamkun/dayjs/issues/1433#issuecomment-1898812960 https://github.com/iamkun/dayjs/issues/2565#issuecomment-1915826596