Day of week - Is Sunday always 1 regardless the device config?

Former Member
Former Member
Hi there,

There is an option on my watch to setup the start of week (Settings / System / Formats / Start of Week). Can I read that value, or should I?

If I am correct to get the day of week vaule is the following:
Time.Gregorian.info(Time.now(), Time.FORMAT_SHORT).day_of_week

The return value is a number from 1 to 7, where 1 is Sunday and 7 is Saturday. I tested on my watch and it seems regardless what's my system setup, it always 1=Sunday , 2=Monday ..., 7=Saturday.

Can you comfirm that?
  • Hi there,

    There is an option on my watch to setup the start of week (Settings / System / Formats / Start of Week). Can I read that value, or should I?

    If I am correct to get the day of week vaule is the following:
    Time.Gregorian.info(Time.now(), Time.FORMAT_SHORT).day_of_week

    The return value is a number from 1 to 7, where 1 is Sunday and 7 is Saturday. I tested on my watch and it seems regardless what's my system setup, it always 1=Sunday , 2=Monday ..., 7=Saturday.

    Can you comfirm that?


    Yes. The API returns consistent values that are not affected by watch configuration, with the exception of the values returned from the methods within DeviceSettings (such as DeviceSettings.temperatureUnits).

    Furthermore, because the API does not currently allow access to the configured start of the week (which, really should always be Monday but I digress *grin*), you will need to add a user configuration within your app for start of the week that the user can then change based on their preference.

    Cheers,
    Douglas
  • Former Member
    Former Member over 8 years ago
    I see, thank you so much! I agree, Monday should be number 1.
  • If you want monday to be number one then adjust it.

    var day_of_week = 1 + (gregorianInfo.day_of_week + 5) % 7;

    // Now Monday=1 and Sunday=7.
  • Former Member
    Former Member over 8 years ago
    If you want monday to be number one then adjust it.

    var day_of_week = 1 + (gregorianInfo.day_of_week + 5) % 7;

    // Now Monday=1 and Sunday=7.

    Thank you!
  • Would like to see an updated SDK documentation (html file in the Connect IQ V2.3.4), actually you will see:

    ____________________________________________________

    day_of_week -> Toybox::Lang::Number, Toybox::Lang::String
    • FORMAT_SHORT Number(0, 1, 2, etc.)

    ____________________________________________________

    I believe that there are some typos here (at least the comma before 'etc.') and I would prefer to see (1, 2, 3 etc.) or (1, 2, 3,... 7) instead of (0, 1, 2, etc.)



  • It's even worse than that.

    https://developer.garmin.com/downloads/connect-iq/monkey-c/doc/Toybox/Time/Gregorian/Info.html#day_of_week-instance_method
    [h=3]day_of_week ⇒ Toybox::Lang::Number, Toybox::Lang::String[/h]
    The day of the week (e.g. Monday, Tuesday, Wednesday, etc,).

    Returns:
    • (Toybox::Lang::Number, Toybox::Lang::String) ?

      The day of the week in the specified format:
      • FORMAT_SHORT Number (0, 1, 2, etc.)
      • FORMAT_MEDIUM String (Sun, Mon, Tue, etc.)
      • FORMAT_LONG String (Sun, Mon, Tue, etc.)

      Medium and Long formatting are currently equivalent.

    The summary could be interpreted as implying that Monday is the first day of the week, while the text for FORMAT_MEDIUM (correctly) implies that Sunday is the first day. And of course, the text for FORMAT_SHORT is completely wrong, as pointed out.

    But nowhere does it explicitly say what the first day of the week is.

    Let's say it were changed as follows:
    • FORMAT_SHORT Number (1, 2, 3, etc.)
    • FORMAT_MEDIUM String (Sun, Mon, Tue, etc.)


    The doc for FORMAT_SHORT still wouldn't stand on its own, because you'd still have to look at the doc for FORMAT_MEDIUM and deduce that 1 = Sunday, which rests on the assumption that the two lists are intended to line up. Seems like a reasonable assumption to make, but of course there's the list in the summary which starts with Monday instead of Sunday.

    I feel like I shouldn't have to read about FORMAT_MEDIUM if I want to use FORMAT_SHORT (unless the doc explicitly says there's a connection between the two).

    I feel like the Garmin docs rely heavily on examples (which are nice), but some of these examples are vague enough that you have to guess the intent of the author. It would be nice if some
    things were explicitly spelled out. As a bonus, when certain things are explicitly spelled out, it's easier to catch this kind of mistake (IMO).

    I would like to see something like this.

    [h=3]day_of_week ⇒ Toybox::Lang::Number, Toybox::Lang::String[/h]
    The day of the week [e.g. Sunday] as a number [1] or a string ["Sun"].

    Returns:
    • (Toybox::Lang::Number, Toybox::Lang::String) ?

      The day of the week in the specified format:
      • FORMAT_SHORT Number: A number in the range 1 to 7. 1 = Sunday, 2 = Monday, ..., 7 = Saturday
      • FORMAT_MEDIUM String. The abbreviated day of the week: "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
      • FORMAT_LONG String: Currently the same as FORMAT_MEDIUM


    If that's too much, then even something as simple as "Sunday is the first day of the week" would be helpful.

    BTW, it's generally accepted that there should be a comma before etc.
    https://english.stackexchange.com/questions/1469/when-ending-a-list-with-etc-should-there-be-a-comma-before-etc
  • I believe that there are some typos here (at least the comma before 'etc.') and I would prefer to see (1, 2, 3 etc.) or (1, 2, 3,... 7) instead of (0, 1, 2, etc.)


    It's standard to have a comma precede "etc.", so no typos here. :) I agree that it's probably better to explicitly state the range for FORMAT_SHORT, though. We should also explain what '0' means rather than imply it through the other formatting options. I'll create a ticket to have this addressed.


  • Thanks for the good discussion here. Our documentation is always open to improvement, so we welcome the feedback.

    The summary could be interpreted as implying that Monday is the first day of the week, while the text for FORMAT_MEDIUM (correctly) implies that Sunday is the first day.


    Agreed--we shouldn't allow room for such implications in the API docs. As I mentioned above, we'll refine this.

    And of course, the text for FORMAT_SHORT is completely wrong, as pointed out.


    I'm not sure what's completely wrong about the FORMAT_SHORT docs, aside from not being explicit enough. I appreciate your suggestion, though, and will probably adapt it because it's a better approach than what we have.

    Just to provide a little more context (and perhaps hope), we already have a ticket open to differentiate FORMAT_MEDIUM and FORMAT_LONG. At the moment, they behave exactly the same, so that's how they're documented. I also have a ticket to add 'Start of Week' to the DeviceSettings API so apps can use the device settings, allowing users to make Monday the start of the week if they prefer (even though they're totally wrong).

    Kidding, kidding. ;)


  • . We should also explain what '0' means rather than imply it through the other formatting options.

    I'm not sure what's completely wrong about the FORMAT_SHORT docs, aside from not being explicit enough. I appreciate your suggestion, though, and will probably adapt it because it's a better approach than what we have.


    Thanks, I appreciate that!

    Maybe I'm missing something, but according to the OP and my own (pretty brief) testing, FORMAT_SHORT returns:
    - 1 for Sunday
    - 7 for Saturday

    What does 0 mean?



  • Not sure how, but I completely missed that detail in the thread. Looks like FORMAT_SHORT is probably wrong after all. :) I remember 0 == Sunday, but I'll double check it and correct the docs.