Why does this work in the Simulator but not on the watch?

I have a Vivoactive 4S and am using Connect IQ v3.1.9 on a Windows 10 laptop.  I want to display a message on the phone every alternate evening to remind me to take a tablet (a pill not an iPad lol!).  I am using a version of the Analog clockface example that came with v3.1.9 and have modified (amongst other things) the drawDateString function to do what I want.  drawDateString is called as part of the onUpdate function and the relevant code is:-

    var takeTablet = false;         //  Class declarations
    var tabletSeconds = 59;         //     ditto

		if (info.hour == 5 && info.min == 0 && info.sec <= tabletSeconds) {
			takeTablet = ! takeTablet;
			tabletSeconds = info.sec;
			System.print("tabletSeconds = ");
			System.print(tabletSeconds);
			System.print(" - takeTablet = ");
			System.println(takeTablet);
		}
		if (takeTablet && (info.hour > 21 || info.hour < 5)) {
	        dc.drawText(x, y+24, datefont, "Take Tablet", Graphics.TEXT_JUSTIFY_CENTER);
		}

This all works fine in the simulator with Low Power Mode set but not at all on the watch itself.  As far as I can see the 'takeTablet' boolean is never changed.  I don't think that my code is at fault (hubris not being a fault of mine!!!) because it works properly in the Simulator so what is it that is different on the watch?  And, more importantly, what should I do to get it to work?

  • I know that this thread is now 3 months old but I have thought of (what I think is ) a much better way of achieving this which is to use Unix time mod total elapsed seconds of the rotation :-

        // Draw the date string into the provided buffer at the specified location
        function drawDateString( dc, x, y ) {
        	
            var info = Gregorian.info(Time.now(), Time.FORMAT_LONG);
            var dateStr = Lang.format("$1$ $2$ $3$", [info.day_of_week, info.month, info.day]);
    
            dc.setColor(Graphics.COLOR_LT_GRAY, Graphics.COLOR_TRANSPARENT);
            dc.drawText(x, y, datefont, dateStr, Graphics.TEXT_JUSTIFY_CENTER);
            
            var rotationDays = 2;			//  # of days per rotation
            var displayStart = 22;			//	display start time, hours from midnight
            var displayEnd = 05 + 24;		//  display end time, roll over to next day
    
        	var now = Time.now().value() % (rotationDays * Time.Gregorian.SECONDS_PER_DAY);	//  172800 = 2 days
    		if (now >= (displayStart * Time.Gregorian.SECONDS_PER_HOUR) && now < (displayEnd * Time.Gregorian.SECONDS_PER_HOUR)) {
    	        dc.drawText(x, y+24, datefont, "Take Tablet", Graphics.TEXT_JUSTIFY_CENTER);
    		}
        }
    

    Doing it this way makes it much easier to change the number of rotation days and start /.end time.  The one thing to watch out for is if the end time goes beyond the number of rotation seconds, in which case the test should be OR rather than AND.