Hacker News new | ask | show | jobs
by sokoloff 2002 days ago
> Milliseconds are converted to seconds by dividing by 1000 and rounding down like so

It seems like the simpler explanation is that the iPhone actually rounds to the closest integer rather than rounding down. (Whether they do this invisibly by adding 0.5s and rounding down is an implementation detail.)

3 comments

Correctly rounding to the nearest second is exactly the behaviour that I expect from a timer.

It's not "fake".

Exactly. Seems like the author is suggesting a timer with 4.9 seconds left should tell you it has 4 seconds left instead of 5. Not sure why anyone would think this.

The tidbit about it displaying 1 even if there is 0.01 left is interesting though. Makes sense.

reddit works like this if you get downvoted and only get to post every 10 minutes. it tells you you have to wait 1 more minute, and then a minute later it tells you you have to wait 59 more seconds, very counterintuitive. gets me every time when I have a post typed out and it's putting me on timeout for going against the grain (like e.g. suggesting that mob justice is bad)
> reddit works like this if you get downvoted and only get to post every 10 minutes.

Oh, so that's why it's telling me to wait... I always wondered that whenever I got into an argument with someone.

Unless you pause it... In which case it rounds up...
Only at 0:00. That's a separate feature, showing 0:01 at a minimum for a paused timer (presumably to make it very clear that you aren't looking at an expired timer, even though the UI disappears for an expired timer.)
Ah. I see that my Apple app does do that, but it's not my preference.

I would much prefer "0 seconds remaining" to mean 0 to 0.5 seconds remaining, than any other possible case. I would find it much easier to parse.

(Alternatively, please show more accuracy for this case, where it's likely relevant)

The sentence quoted is for the first example in the post, not the iPhone timer.

That’s most likely what it does indeed, much more elegant than keeping track of the extra 500ms.

I realize that. It seems like the entire blog post could be summarized as "I thought about doing something this way and when it didn't give me what I and everyone else expects out of a timer, my mental model adjusted to conclude that Apple was doing some weird gymnastics involving adding 500ms to some of their timer code and using Math.floor() but not to the time the timer actually goes off rather than adjusting my mental model to match the simpler way that humans expect rounding to work in a timer using [the equivalent of] Math.round()."
Agreed, to my eyes it seems clear that the display shows both “5” and “0” for half a second, which means the total duration is still 5 seconds, not 5.5 seconds.