localMoment - Could not find symbol?

Hi,

I am trying to use Time.Gregroian.localMoment() according to the API Reference. Here is my Code:

var options = {
    :year   => 2018,
    :month  => 2,
    :day    => 24,
    :hour   => 0,
    :min    => 12
};

var when = Time.Gregorian.moment(options);
var where = new Pos.Location({
    :latitude  =>  loc[0],
    :longitude => loc[1],
    :format    => :radians,
});

var local = Time.Gregorian.localMoment(when, where);

I am importing "using Toybox.Time as Time;" but I tried to import Gregroian directly and it's always the same error:

Error: Symbol Not Found Error
Details: Could not find symbol 'localMoment'

I'm on SDK 4.1.2, developing for target API Level 4.0.

Is localMoment working at all?

Thank you so much,

Bob

  • localMoment is a System 5 API (Since API Level 3.3.0).  What target device are you trying to use?  With you setting a target API level of 4.0. it's actually got to be a target with 4.1 in the sim.

    4.0 devices do not have System 5 APIs - only devices with 3.3.x or 4.1.x

  • Hi and as always, thank you so much for your help!

    In the API Docs it says:

    Since:

    API Level 3.3.0

    Does that not mean what I think it does? 

    I will try to target 4.1, I'm always only developing for epix gen2... But that means that it will only be available to those using the beta firmware which supports system5?

    Thank you so much! 

  • Having 3.3.x or 4.1.x on a device means System 5 APIs.  If you want to publish for an Epix2 which may or may noy have a 4.1 VM, use "has" to see if localMoment is available at run time.

  • Thank you so much! I guess I was just not expecting this to be a new system5 feature, being on a watch.

    I used getClockTime in the end to make it available to everybody.

    I hope Garmin sends you a new watch for free every once in a while! You are the soul of this dev forum! Thank you!! 

  • I'm getting a different problem when wrangling localMoment.

    It's the first time I have tried so I went back to the doco and found my problem is revealed when running the sample from the doco:

    if (Gregorian has :localMoment){	
        var options = {
    		:year   => 2018,
    		:month  => 2,
    		:day    => 24,
    		:hour   => 0,
    		:min    => 12
    	};
    		var when = Gregorian.moment(options);
    	
    		var where = new Position.Location({
        		:latitude  =>  38.85391,
        		:longitude => -94.79630,
        		:format    => :degrees,
    		});
    
    var local = Gregorian.localMoment(when, where);
    }

    It crashes on line 17 with "UnexpectedTypeException: Expected Number, given Object"

    And also reports "Unable to detect scope 'Position.Location' for the symbol 'initialize'." on the line 11.

    Running in the sim for Epix2 and Fenix7, connectiq-sdk-mac-4.1.3-2022-05-10

  • try

    when.value()

    maybe position permission is necessary

  • Nope, same crash, but you may be on to something. "when" is definitely an object, not a Number, but it has a property "mDateTime" which is a Number.

    However when I use when.mDateTime , it crashes with "Could not find symbol 'mDateTime'" even though the Debug Console is ha[ppy with when.mDateTime:

    It didn't like .toNumber() either.

    Not position permission issue as it's specified in the manifest.

    And what about the warning: Unable to detect scope 'Position.Location' for the symbol 'initialize'. ?

    Something odd here...?

  • Nope, same crash, but you may be on to something. "when" is definitely an object, not a Number, but it has a property "mDateTime" which is a Number.

    However when I use when.mDateTime , it crashes with "Could not find symbol 'mDateTime'" even though the Debug Console is ha[ppy with when.mDateTime:

    It didn't like .toNumber() either.

    Not position permission issue as it's specified in the manifest.

    And what about the warning: Unable to detect scope 'Position.Location' for the symbol 'initialize'. ?

    Something odd here...?

    it even crashes "UnexpectedTypeException: Expected Number, given Object" with a specific number, like

    var local = Gregorian.localMoment(1653283388, where);

  • And what about the warning: Unable to detect scope 'Position.Location' for the symbol 'initialize'. ?

    Do you have an import or using statement for Toybox.Position?

    using Toybox.Position;

    or

    import Toybox.Position;

  • No I didn't, but when I added "using Position;" it made no difference, it still crashed "UnexpectedTypeException: Expected Number, given Object".

    Anyway, I would have thought that if it was required, line 11

    var where = new Position.Location({...

    would have failed, and it didn't. Another oddity?

    Are you able to get the code working?