godate
godate copied to clipboard
Bug with getting difference as WEEK
Whenever the difference between dates is being requested as WEEK and above there is a slight offset of about 1 millisecond. Due to this issue, a Millisecond was added in the tests file when testing the difference.
For reference run the TestGoDate_DifferenceFromNowForHumans()
method in the tests without the .Add(1,Unit(time.Millisecond))
in this line
nextWeek := now.Add(1,WEEK).Add(1,Unit(time.Millisecond))
I'm a bit confused @kofoworola
Isn't is actually supposed to fall slightly short of 7 days exact (168 hours) based on how the test is written?
Unlike AbsDifferenceForHumans
that receives the reference goDate, DifferenceFromNowForHumans
generates an internal Now()
reference goDate which happens about a millisecond (leaving 167.999+ hours) short of when the first Now()
.(used to generate nextWeek
) was called.
The issue isn't necessarily with DifferenceFromNow
in my opinion, it's trying to use the logic of AbsoluteDiff
within it as AbsoluteDiff
makes hard distinctive cuts such as 168.000 hours being a week (as it's supposed to). A possible solution might be to give DifferenceFromNow
it's own distinct internal logic and assumptions to make (approximations and roundoffs) but that will introduce inconsistencies. Every duration could also atleast show the preceeding unit e.g YEAR showing "x years, y months", WEEK showing "x weeks, y days"
The best solution for me is to internalize the behaviour of DifferenceFromNow
in the documentation, showing users that the Now()
being used by the fn is not any Now()
previously used in scope, but rather an internal Now()
so as to avoid possible confusion