Skip to content

Time Scale not calculating diffs correctly #3673

@lenyy

Description

@lenyy

Hi there,
So there is a bug with the current calculation of dates in the buildLabelsDiff function of the time scale.
Currently at line 194 of scale.time.js where you have scaleLabelDiffs.push(labelMoment.diff(me.firstTick, me.tickUnit, true)); this will give you some other value different from 0 even if dates are equal, but not in all cases.
Lets imagine the scenario in this fiddle https://jsfiddle.net/lenyy/scgc7tcj/ , i create two date objects but they have one hour difference between them, so calculating the diff between them using days has unit should give zero, it does if you don't pass true has the third argument to diff function that says to diff function that you wanna use floor. Moment changed the way the used to round values https://gist.github.com/timrwood/e72f2eef320ed9e37c51#momentdiff-now-floors-instead-of-rounds
they now floor instead of round.

So the fix is to change scaleLabelDiffs.push(labelMoment.diff(me.firstTick, me.tickUnit)); without the last argument, so now when your value falls on the same value of a tick it will return 0.

I think this has lead to several other problems that i have saw in here when using bar chart that values we're shiffted and i think this might be the case when using day as your tick unit. i haven't tested for other time units, but it should be the same.

Any questions just ask :)

Cheers,
Pedro

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions