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

  • HA! The example WRONG!

    a) It requires (where, when) not (when, where).

    b) it doesn't take a Gregorian.moment as the when argument because a Gregorian.moment is not a Number. It has to be cast as a number with .value() (also incorrectly explained in the "moment" documentation.)

    This works:

    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(where, when.value());
    		var info = Gregorian.info(local, Time.FORMAT_SHORT);
    	}

     but this doesn't:

    var local = Gregorian.localMoment(where, when);
    It's now working for me in my app with
    var mLocalMoment = Gregorian.localMoment( simulator.mLocation, timeSecs);
    where timeSecs is a Number.
    The documentation fails to specify an initializing Constructor for the LocalMoment and the author of the example got it hopelessly wrong.
    GRRRR :-(