Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minute calculation for a running timer #10

Merged
merged 5 commits into from
Jun 26, 2023

Conversation

KaylaKremer
Copy link
Member

@KaylaKremer KaylaKremer commented Jun 23, 2023

This is in response to an issue brought up on our mobile repo.

With a running timer, when the time changes from 1:59 to 2:00 for example, the time briefly displays at 1:00 instead of as 2:00 until another minute goes by, reverting back to the correct display time of 2:01.

This is due to the use of Math.round which causes the minutes to display as :00 a bit too soon before the hour calculation increases by 1 since it will round up when the remainder value is 59.5 or greater.

I added an if conditional to instead use Math.floor when the remainder value is between 59.5 and 60 to keep the value displaying as :59 until the hour value increases by 1.

@KaylaKremer KaylaKremer self-assigned this Jun 23, 2023
@KaylaKremer KaylaKremer requested review from evanwalsh and a team June 23, 2023 16:41
@pusewicz
Copy link

Could we please add a test to cover this scenario? Thanks!

@KaylaKremer
Copy link
Member Author

KaylaKremer commented Jun 23, 2023

@pusewicz

Added the tests!

Copy link

@braddunbar braddunbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me! We should probably port this to clockwork and Harvestapp.

@pusewicz
Copy link

@KaylaKremer Thank you!

const minutes = Math.round(total) % 60
let minutes = total % 60
if (minutes >= 59.5 && minutes < 60) {
minutes = Math.floor(minutes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, we could just hardcode 59 here since it's a known value.

@KaylaKremer KaylaKremer merged commit e23d6ad into harvesthq:main Jun 26, 2023
3 checks passed
@KaylaKremer KaylaKremer mentioned this pull request Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants