From 2d6e99e5d36864461dfc158c16270138984d380a Mon Sep 17 00:00:00 2001 From: Alexander <33549680+selenir@users.noreply.github.com> Date: Mon, 4 Mar 2019 14:55:16 +0100 Subject: [PATCH] fix: misplacement of current time indicator (#1239) Hello, It looked like PR for this issue (#1054) was abandoned and the bug still exists so I've decided to continue jdaberkow's work. Also I've added check for `getNow` prop, because when you want to implement timezones you may have different `getNow` function depending on which timezone is selected. When user changes the timezone indicator should move to correct position for that timezone. --- src/DayColumn.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/DayColumn.js b/src/DayColumn.js index 2cb50365d..c0ea5ec5d 100644 --- a/src/DayColumn.js +++ b/src/DayColumn.js @@ -44,13 +44,22 @@ class DayColumn extends React.Component { } componentDidUpdate(prevProps, prevState) { - if (prevProps.isNow !== this.props.isNow) { + const getNowChanged = !dates.eq( + prevProps.getNow(), + this.props.getNow(), + 'minutes' + ) + + if (prevProps.isNow !== this.props.isNow || getNowChanged) { this.clearTimeIndicatorInterval() if (this.props.isNow) { - this.setTimeIndicatorPositionUpdateInterval( + const tail = + !getNowChanged && + dates.eq(prevProps.date, this.props.date, 'minutes') && prevState.timeIndicatorPosition === this.state.timeIndicatorPosition - ) + + this.setTimeIndicatorPositionUpdateInterval(tail) } } }