According to the documentation: https://developer.garmin.com/connect-iq/api-docs/Toybox/Background.html#registerForTemporalEvent-instance_function : "If a temporal event is scheduled for a time in the past, the event will trigger immediately."
When I try the following code in my datafield with SDK 4.1.7 simulator (fr255) {did not try on any real device, so I don't know if it works there}:
var lastTime = Background.getLastTemporalEventTime();
var nextTime = lastTime != null ? lastTime.add(new Time.Duration(300)) : Time.now();
log("now: " + timeFormat(Time.now()) + "lastTime: " + (lastTime == null ? null : timeFormat(lastTime)) + ", nextTime: " + timeFormat(nextTime));
Background.registerForTemporalEvent(nextTime);
I see this in the log:
now: 23:05:37, lastTime: 22:33:28, nextTime: 22:38:28
It doesn't throw an InvalidBackgroundTimeException, so I know that more than 5 minutes passed since last time it was called, and also from the logs we know that more than 30 minutes passed since last temporal event. And still it's not triggered immediately. In fact it's always triggered exactly 5 minutes later:
Background: 23:10:37 onTemporalEvent