Closed
Description
Lets say i have the time of now: 16th may 16:44 and using addDays with an uneven number like 1.3 i expect the function to add 1.3 days to 16:44 resulting in something around 16th may 21:01 with the exact amount of minutes an seconds.
This works fine in Chrome. But using Firefox addDays does NOT change the minutes/seconds/ms. The reason is the usage of Date.setDate()
Example:
https://codepen.io/MickL/pen/GdYrvw
Tests should be updated to include date with hours/minutes and an uneven number of days.
Activity
leshakoss commentedon May 16, 2018
@MickL I would say it should
Math.floor
the amount of days. So it sounds like a bug to meMickL commentedon May 16, 2018
Can you confirm addDays sets minutes, hours and ms to 0 on Firefox but not on Chrome?
MickL commentedon May 16, 2018
I think the problem is that addDays() is using Date.setDate. I tried on Chrome with a float it works, but Firefox does not change the hours/minutes:
Its not a bug but i think
addDays()
should be changed to not useDate.setDate()
which does not work with decimal numbers.Created an example here:
https://codepen.io/MickL/pen/GdYrvw
MickL commentedon May 16, 2018
Workaround: Use addMinutes / addSeconds instead
kossnocorp commentedon May 25, 2018
This is looks like a Chrome bug if I read the spec correctly.
I believe that
addDays
shouldn't change any units except days. The passed argument should be rounded usingfloor
. We should apply this not only toaddDays
but also to alladd
/sub
functions for consistency sake.@MickL not sure what was your original intention when you were adding 1.3 days, but please use
addHours
/addMinutes
/etc. for that.kossnocorp commentedon May 25, 2018
I've opened an issue in the Chromium issue tracker: https://bugs.chromium.org/p/chromium/issues/detail?id=846723
Refine the way arguments are processed (closes date-fns#746, closes d…