@saxnpaule said in Date / Time difference expressions and calculation:
Please see #14
Thanks for pointer. I read the post, but overlooked the important part at the end. Sorry about that.
Regarding the use of Math.round() or Math.ceil() there needs to be a further discussion. I would suggest to use ceil() for positive differences and round() for negative ones.
That means the difference in days will be at least 1 as long as it isn’t <=0.
Half a day after passing the scheduled date, the difference will be -1 days.
By using always the round() function, the difference will be 0, 12 hours before and after the configured “schedule”.
Ok, I see the point, but it in my opinion it is counter-intuitive and may raise a user question even if the behavior is documented. Actually, I am in favor of the point @Heizelmann made as he suggested to return rational number and let the user decide how the result should be handled. However, it tricky as calling round() does not suffice in all cases. It depends on whether the result is negative or positive.
"It always takes longer than you expect, even when you take into account Hofstadter's Law.", Hofstadter's Law