Updating clock on the minute exactly

Posted on
  • Hi,

    I've only written one clock so far (and editing another), but it was fun! I had a a question about the best way to update the clock face:

    On the pebble, there was a function rocky.on('minutechange', function(event) { that would fire every minute, on the minute. Is there a similar function for the bangle?
    I know I can set a timer to go off every sixty seconds, but is there a way to start at 0 seconds past the minute? Or on exactly 0 seconds and 30 seconds past?

    Thank you.

  • I know I can set a timer to go off every sixty seconds, but is there a way to start at 0 seconds past the minute? Or on exactly 0 seconds and 30 seconds past?

    Clocks usually use the setTimeout method like this: https://github.com/espruino/BangleApps/b­lob/c4f9d7757912442df66b21038322ee65acf5­3b53/apps/waveclk/app.js#L21-L24

    The 60000 - (Date.now() % 60000) part returns the millis to the next minute.

  • Ah, thank you Alessandro, I hadn't seen that before but it's exactly what I need!

  • If your watch gains or loses time noticeably, I suggest installing the widget Adjust Clock by @malaire, which enables accurate timekeeping. Use of that would change Alessandro's statement slightly.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Updating clock on the minute exactly

Posted by Avatar for Sir_Indy @Sir_Indy

Actions