Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Issue with multiple clock granularitys

ANSWERED

I have a bit of a strange issue in the clockface I am trying to build. I have been following the sdk-moment example repo on Github, on there they have a `simpleClock` component, which has a clock granularity set to minutes, and then an `simpleActivity` component with a clock granularity of seconds. Technically speaking I want to do that in the opposite way and have the clock every second but activity data every minute so it doesn't hammer battery usage too much.

The issue I find (and this happens with the example code too) is that the granularity is global depending on the last granularity to be set. Is there a way to have these run  independently? or would I perhaps have to have one listener that is called every second globally, that then calls other things (like activity data) when the seconds value is 00? instead of linking them to "ticks" in their own right

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

You're on the right track. granularity is a property of the clock object, of which there is only one instance.

Testing for seconds==0 is slightly risky because the clockface may not be active at exactly that moment (and I've seen it skip seconds too). Keeping track of the last hour and minute values, and then seeing if there's been a change every second, works. Or you could get fancier and keep track of a Date value that indicates when you next want to update activity data.

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
3 REPLIES 3

You're on the right track. granularity is a property of the clock object, of which there is only one instance.

Testing for seconds==0 is slightly risky because the clockface may not be active at exactly that moment (and I've seen it skip seconds too). Keeping track of the last hour and minute values, and then seeing if there's been a change every second, works. Or you could get fancier and keep track of a Date value that indicates when you next want to update activity data.

Peter McLennan
Gondwana Software
Best Answer

Hi @stefanwright88  - the issue as mentioned by @Gondwana is the clock stops when the display is off.

However using a setInterval will activate even if the display is off.

Using a combination of a seconds granularity and a 60 second interval (in ms) will give you roughly what you need. The interval can drift but should be good enough to trigger about once a minute.

Author | ch, passion for improvement.

Best Answer

Thanks you @Gondwana and @Guy_ sorry it took so long to get back to you. Appreciate the help, I assumed a setInterval was the way to go but I thought i'd check. That example repo isn't very clear that you can't have multiple instances of clock with different granularities

Best Answer
0 Votes