Repository navigation
useTime: floor the current second instead of rounding it up - #151
Open
Shaisolaris wants to merge 1 commit into
Open
Shaisolaris wants to merge 1 commit into
Shaisolaris wants to merge 1 commit into
Conversation
getFormattedTimeFromMilliseconds used the countdown rounding (Math.ceil), so useTime showed the clock one second ahead whenever the current time was not on an exact second, e.g. 14:59:59.600 displayed as 15:00:00.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
useTimeshows the clock one second ahead whenever the current time is not on an exact second boundary.getFormattedTimeFromMillisecondscallsgetTimeFromMilliseconds(milliseconds)with the defaultisCountDown = true, which usesMath.ceilon the seconds. That rounding suits a countdown, but a clock needs to round down. So at 14:30:45.500useTime()returnsseconds: 46instead of 45, and at 14:59:59.600 it returnshours: 15, minutes: 0, seconds: 0. With the default 1000 ms interval the ticks rarely land on an exact second, so in practice the displayed time is usually one second fast.This passes
falseso the time is floored, which is whatuseStopwatchalready does.Tests: I added two cases to
__tests__/useTime.test.tswith sub-second system times. Both fail on master (Expected: 45, Received: 46andExpected: 14, Received: 15) and pass with the change. The existing tests all used whole seconds, which is why this went unnoticed.npx jestgives 70 passed locally, andeslint srcis clean.