Acknowledged

Maybe a bug in Toybox.Weather in SDK4.2.1 or higher

I found a weird behavior in Toybox.Weather module.

According to the instruction below, return type of Dailyforecast.highTemperature is Time.Moment.

https://developer.garmin.com/connect-iq/api-docs/Toybox/Weather/DailyForecast.html

On the other hand, lowTemperature is Lang.Number.

In the program, highTemperature works as Time.Moment and

it causes an error for my app.

This occurs from SDK4.2.1 and higer.

I mean highTemperature is regrded as Lang.Number in SDK4.1.7 or lower.

Is this a bug?

  • You are correct.  getDailyForecast does return an array.  I was wrong.

  • Hi Jim,

    Thank you again!

    Oh, I'm afraid you are saying about "getCurrentConditions()"

    Accoring to the document below, "getDailyForecast()" return Lang.Array, because it includes forecast for next 5 days.

    developer.garmin.com/.../Weather.html

    Excuse me for making you confused.

    Thanks!

  • What you get back from Weather.getDailyForcast() isn't an array, so your "w.size()" doesn't make sense.  Try "if(w!=null)" instead,

    then, wherever you have w[1], just use w.  I.e.

    w.lowTemperature

  • Hi Jim and SHN!

    I appriciate both of you for replying, so much!

    I made a new project and just added below for a test.

            var w =  Weather.getDailyForecast();
            if (w.size() >= 2) {
                var temperature = w[1].lowTemperature + 1;
                //var temperature = w[1].highTemperature + 1;
                //var temperature = w[1].highTemperature.toString().toNumber() + 1;
                System.println(temperature);
            }
     
    Then, I tried to run the commented out lines one by one.
    1st attempt,  var temperature = w[1].lowTemperature + 1; is OK
    2nd attempt, var temperature = w[1].highTemperature + 1;, here I had some errors below.
    ERROR: vivoactive4: C:\EclipseIQconnect\TestPJ00\TestPJ00\source\TestPJ00View.mc:33,12: Cannot perform operation 'add' on types 'PolyType<Null or $.Toybox.Time.Moment>' and '$.Toybox.Lang.Number'.
    ERROR: vivoactive4: C:\EclipseIQconnect\TestPJ00\TestPJ00\source\TestPJ00View.mc:35,12: Value may not be initialized.
    ERROR: vivoactive4: C:\EclipseIQconnect\TestPJ00\TestPJ00\source\TestPJ00View.mc:35,12: Invalid 'Uninitialized' passed as parameter 1 of type 'PolyType<Null or $.Toybox.Lang.Object>'.
    3rd attempt, var temperature = w[1].highTemperature.toString().toNumber() + 1; is OK again.
    I think w[1].highTemperature is regarded as "types 'PolyType<Null or $.Toybox.Time.Moment>'" and it matches the information in the document...
    Excuse me for bothering you again but I appreciate if you have any idea.
    Thanks!
  • Yes, there are a couple of things wrong in the doc, like for highTempature it says it returns the low temperature, and for highTemperature it has "as Time.Moment or Null" (where Time.Moment makes zero sense for a high temperature value) and it says 

    "Returns:

    Lang Number -- or null"

    at the end