How to interpret the sleepTime and wakeTime in userProfile?

Former Member
Former Member
How should the sleepTime and wakeTime be interpreted from Class: Toybox::UserProfile::Profile ?
Unfortunately it is not documented.
Is it the most recent sleepTime and wakeTime from resp. yesterday and today?
  • My guess is that these are the "Normal Sleep Times" configured in the user profile rather than anything detected from previous days.
  • Former Member
    Former Member over 9 years ago
    I would also like to know what these are. They are Duration objects and hold an immutable time span. So you can call the value() function on them and it returns the number of seconds in the duration. Perhaps it is the amount of time sleep or awake is active based on the user settings of Sleep time and Awake time? I would like to be able to actually access the time that the user has set for sleep and awake time. Does anyone know of a way to get that information? For instance I have my sleep time set to 11pm and my wake time to 7am. Is there a way to get those times? I think the sleepTime would return a duration of 8 hours and wakeTime would be 16 hours. This information is not all that helpful for what I want to do, if I could get the actual times I could figure out the duration myself as well as being able to calculate how much wake time or sleep time is left from the current time.
  • Former Member
    Former Member over 9 years ago
    My guess is that these are the "Normal Sleep Times" configured in the user profile rather than anything detected from previous days.


    This is exactly what the API is returning.

    For instance I have my sleep time set to 11pm and my wake time to 7am. Is there a way to get those times?


    Yes, the API returns these values. The durations are equal to the offset of the sleep/wake times from midnight. For the example you gave wakeTime would be equal to 7 hours, and sleepTime would be equal to 23 hours.
  • I would also like to know what these are. They are Duration objects and hold an immutable time span. So you can call the value() function on them and it returns the number of seconds in the duration. Perhaps it is the amount of time sleep or awake is active based on the user settings of Sleep time and Awake time? I would like to be able to actually access the time that the user has set for sleep and awake time. Does anyone know of a way to get that information? For instance I have my sleep time set to 11pm and my wake time to 7am. Is there a way to get those times? I think the sleepTime would return a duration of 8 hours and wakeTime would be 16 hours. This information is not all that helpful for what I want to do, if I could get the actual times I could figure out the duration myself as well as being able to calculate how much wake time or sleep time is left from the current time.


    I looked at this a while back, and it is the configured sleep time. (it would be something like wake time is 7:00, and sleep time is 23:00). Seems the watch itself also uses these times for things like suppressing the "move alerts"

    Once you have the seconds, you can convert that into hh:mm fairly easily., or you can convert the current hh:mm into seconds quite easily to do math with seconds with wake/sleep times.

    Here's the code from the UserProfile sample in the SDK:
    hours = profile.wakeTime.divide( 3600 ).value();
    minutes = profile.wakeTime.value() - ( hours * 3600 );
    seconds = profile.wakeTime.value() - ( hours * 3600 ) - ( minutes * 60 );
    string = "Wake Time: " + hours.format("%02u") + ":" + minutes.format("%02u") + ":" + seconds.format("%02u");
  • Former Member
    Former Member over 9 years ago
    @Brian, That is very helpful. Would be good if that piece of information was in the documentation. I had no idea what the numbers I was getting were supposed to be. Thanks for the quick response.
  • Former Member
    Former Member over 9 years ago
    @Brian, That is very helpful. Would be good if that piece of information was in the documentation. I had no idea what the numbers I was getting were supposed to be. Thanks for the quick response.


    ditto
  • We have a task to get the documentation for this improved. Just FYI! :)