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

time counting error #10

Closed
fjun99 opened this issue Feb 14, 2024 · 1 comment · Fixed by #11
Closed

time counting error #10

fjun99 opened this issue Feb 14, 2024 · 1 comment · Fixed by #11

Comments

@fjun99
Copy link
Contributor

fjun99 commented Feb 14, 2024

Great project!

There is a time counting error.

When it is 00:59, the next second will show as 2:00.

When it is 01:59, the next second will show as 4:00.

We may choose to use totalSeconds instead of minutes and seconds.

const [totalSeconds, setTotalSeconds] = useState(0);
useEffect(() => {
  let interval: NodeJS.Timeout;

  if (isRunning) {
    interval = setInterval(() => {
      setTotalSeconds((prevTotalSeconds) => prevTotalSeconds + 1);
    }, 1000);
  }

  return () => {
    if (interval) {
      clearInterval(interval);
    }
  };
}, [isRunning]);
function formatTime(time: number): string {
  return time < 10 ? `0${time}` : `${time}`;
}

...
{formatTime(Math.floor(totalSeconds / 60))}:{formatTime(totalSeconds % 60)}

A pull request submitted.

@fjun99
Copy link
Contributor Author

fjun99 commented Feb 15, 2024

notes: NotesGPT at https://usenotesgpt.com/record displays the correct time. However, in a local deployment on a MacBook, I consistently encounter this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant