Skip to content

[sched] Setting an alarm for an earlier time of day makes the alarm fire immediately. #4232

@thyttan

Description

@thyttan

Affected hardware version

Bangle 2

Your firmware version

2v29.75

The bug

Setting an alarm using the sheduling library, for a time that already passed today makes the alarm fire immediately.

I am not sure if this is actually a bug. It may be the intended behavior.

My expectation would have been for the alarm to fire at the set time the next day instead.

Setting an alarm at such a time through the alarms app does indeed set the alarm for the next day instead. I am unsure of how this is achieved.

Here're the lines responsible for the behavior:

active = active.sort((a,b)=>a.t-b.t); // sort by time
var t = active[0].t-currentTime;
if (t<1000) t=1000; // start alarm minimum 1 sec from now

Here's a diff with a fix:
https://github.com/espruino/BangleApps/compare/master...thyttan:sched?expand=1

However that fix seems to go against recent changes to fix other bugs in issues #2712, #4220.

I wonder if you @ticalc-travis have any immediate thoughts regarding this since you seem to have thought about the scheduling library quite a bit not that long ago.

Reproduce

Use the Web IDE to upload the following script to RAM.

{
  S = require("sched");
  const TIME_AT_NEXT_BUZZ = 10 * 1000; //10 seconds after midnight.
  S.setAlarm("test", {
    on: true,
    t: TIME_AT_NEXT_BUZZ,
    //dow: 0b1111111, // all days of the week.
    //last: Date().getDate(), // Don't fire until tomorrow.
  });
  S.reload();
}

Background

I'm working on making the twenties app use the scheduling library instead of setting it's own timeouts. Draft PR at #4231. That's when I happened upon this behavior. Notably I set and make use of the .js attribute when scheduling the alarm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions