Ticket Created
over 3 years ago

WERETECH-12628

LocalMoment is wrong

The documentation fails to provide an initializing Constructor and the example is wrong.

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

b) it doesn't take a Gregorian.moment as the when argument.

This, from the documentation fails:

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

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);
	}

- note (where, when), not (when, where) , and a number not a moment.

Parents
  • The latest documentation now correctly state Gregorian.localMoment(where, when)) - so the where, when order is correct.

    But it does not state to use  Gregorian.localMoment(where, when.value())

    In the simulator Gregorian.localMoment(where, when) works just fine - but when I load it to my Epix device, it causes a crash.

    If I change to my code to Gregorian.localMoment(where, when.value()) - my code still seem to work just fine in simulator - AND now also work on my Epix device... huh?

    I get really nervous here. If I implement Gregorian.localMoment(where, when.value()) can I rely on this to work also in future firmware releases/devices? Does it work for all devices and not just Epix? What is the longer term plan here?

    Alan.raceQs: Have you Apps using this in the field?

Comment
  • The latest documentation now correctly state Gregorian.localMoment(where, when)) - so the where, when order is correct.

    But it does not state to use  Gregorian.localMoment(where, when.value())

    In the simulator Gregorian.localMoment(where, when) works just fine - but when I load it to my Epix device, it causes a crash.

    If I change to my code to Gregorian.localMoment(where, when.value()) - my code still seem to work just fine in simulator - AND now also work on my Epix device... huh?

    I get really nervous here. If I implement Gregorian.localMoment(where, when.value()) can I rely on this to work also in future firmware releases/devices? Does it work for all devices and not just Epix? What is the longer term plan here?

    Alan.raceQs: Have you Apps using this in the field?

Children
  • So, as far as I see, when I build the project with SDK >= 4.1.6, localMoment requires a Time.Gregorian.moment as a second argument.

    However, given the exception mentioned above, when the app is running on the watch, localMoment requires a Number (when.value()).

    I suspect, either I am configuring something wrong, or the most recent SDK doesn't accurately simulate the watch firmware (at least for my fenix-6).

    Only workaround I found so far is to build the project with SDK 4.1.5, where localMoment still requires a Number as a second argument.

    This way both the simulator and the watch are happy using a Number and I can build the project successfully.

  • Hi, is there any recent update on this one? I am currently having the same problem.

    Trying to create a a localMoment as per documentation:

    import Toybox.Position;
    import Toybox.Time;
    
    function getLocalMoment() {
        var day = Time.Gregorian.info(Time.now(), Time.FORMAT_MEDIUM);
    
        var options = {
            :year   => day.year,
            :month  => day.month,
            :day    => day.day,
            :hour   => 0,
            :min    => 0
        };
    
        var when = Time.Gregorian.moment(options);
    
        var where = new Position.Location({
            :latitude  => 38.85391,
            :longitude => -94.79630,
            :format    => :degrees,
        });
    
        try {
            var local = Time.Gregorian.localMoment(where, when);
        } catch( ex ) {
            ex.printStackTrace();
        }
    
        return local;
    }
    "where" is a Position.Location and "when" is a Time.Gregorian.moment.

    This works perfectly fine in the simulator, but when it's side loaded to the watch (fenix6) it crashes with the following exception:
    Exception: UnexpectedTypeException: Expected Number, given Object
    Stack: 
      - pc: 0x100004bc
      - pc: 0x1000013e
      - pc: 0x1000083f


    Apparently, 
    Time.Gregorian.localMoment requires a Time.Gregorian.moment to initialise within the simulator, while a Number to initialise within the watch.

    It looks as if the simulator is running a different API version than the watch? Or is it some configuration mistake on my side?

    My manifext.xml has 
    version="3" and minApiLevel="3.2.0", which I believe should be fine, given that localMoment is supported since 3.3.0.
  • No I don't. I only have it in my Debug version which I only run in the Simulator, sorry I can't help.