Complete
over 5 years ago

Documentation updated and waiting for future release.

Runtime error with Moment.subtract() when subtracting a Duration


Hi
The following Simple Data Field code snippet fails on my Vivoactive HR. It works in the simulator.

using Toybox.WatchUi;
using Toybox.Time;
using Toybox.Time.Gregorian;

    function compute(info) {
		var aDuration = Gregorian.duration({:minutes => 10});
		var aMoment = Time.now();
		var anEarlierMoment = aMoment.subtract(aDuration);
        return 0.0;
    }


The error log (CIQ_LOG.TXT) says:
ERROR: System Error
DETAILS: Expected a Moment object
STORE_ID: 00000000000000000000000000000000
CALLSTACK:
@PC = 0x300013fe
F:\Eclipse2\workspace\ATest\source\ATestView.mc (compute:14)

where compute:14 is the line containing "var anEarlierMoment..."
The Connect IQ SDK documentation for Module: Toybox::Time says
Moment.subtract() can be used to subtract a Duration from a Moment to give "An earlier Moment"
and specifically in the Instance Methods Summary for Class: Toybox::Time::Moment it says
subtract(subtrahend) ⇒ Toybox::Time::Duration, Toybox::Time::Moment
Subtract a Duration or Moment from a Moment.

so I expected it to work.

Former Member
Former Member
Parents Comment Children
No Data