This project is archived and is in readonly mode.

#752 ✓resolved
Octopus Inc

Incorrect behavior Date Method: diff

Reported by Octopus Inc | September 20th, 2009 @ 06:09 PM

today.diff(tomorrow, 'minute');

Returns nearest rounded integer from comparison.
Should give math.floor not math.round as half of a minute is not a minute.

View behavior with .periodical

Comments and changes to this ticket

  • Scott Kyle

    Scott Kyle September 20th, 2009 @ 10:21 PM

    • State changed from “new” to “open”
    • Milestone cleared.
    • Assigned user set to “Scott Kyle”

    Is it standard behavior in other Date implementations to floor rather than round? If so, please provide an example(s). I'd be glad to change it if that's the case. Thanks

  • Octopus Inc

    Octopus Inc September 20th, 2009 @ 10:43 PM

    I would need to do some research to provide specific examples, but I know that the behavior was obviously wrong when I was building with it today.

    Here is the scenario:
    I had two dates that I was running a diff on in a periodical. One was the current time and the other was a date in the future. As they counted down towards one another there was conflicting behavior out of the box. The year didn't round up if there was more than six months worth of extra time. My calculations called modulo 12 on the month resolution, to chop off extra years, modulo 24 on the hour resolution for extra days, mod 60 on second and so on. This was the tone that was being set by the resolution parameter. However, when I got to minutes I had to use Math.floor(now.diff(later, 'second') / 60) % 60. This was necessary because the minute would only decrement after leftover seconds plus more than half of the next minute expired. This event obviously happened at 30 seconds and not at 0. I wouldn't classify this as correct using only the standard that the framework had been displaying up until this point.

  • Octopus Inc
  • Scott Kyle

    Scott Kyle September 21st, 2009 @ 05:19 PM

    • State changed from “open” to “resolved”

    Thanks, I did some thinking and research, and you were right. So I have corrected it here:

    This will be in the next release.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket