• Hi, I'm having a look at the scheduler (apps/sched/lib.js) for dated alarms (i.e. where alarm.date is given).
    Since the time of the alarm is relative to the current time zone, shouldn't the date of the alarm also be?
    If so, I think we should change the code there from:

    ==time.toISOString().substr(0,10)
    

    to:

    ==time.toLocalISOString().substr(0,10)
    

    Would that make sense?
    There's a note on toLocalISOString that says the following, but I think this note applies to neither Bangle versions, right, so it shouldn't break anything?

    This is not available in devices with low flash memory

  • This is not available in devices with low flash memory

    just checked on Bangle 1:

    (new Date()).toLocalISOString()
    Uncaught Error: Function "toLocalISOString" not found!
    at line 1 col 14
    (new Date()).toLocalISOString()

  • Just updated my Bangle 1 to Firmware 2v16

    (new Date()).toLocalISOString()
    ="2022-12-03T13:51:58.925+0100"

    seems like toLocalISOString() is pretty new.

  • Looks like it was added 5 months ago for 2v15 - so I wouldn't worry too much about using it. I think if you're running with new software on 2v14 and earlier you may hit other issues too :)

    ... although we could still look at adding a polyfill to the bootloader to ensure this would work fine?

    Good spot about using toISOString when the rest of the check uses the timezone! Did you notice this because there was actually a problem, or were you just looking at the code?

    Before adding the change, it'd be really good to just verify that the scheduler does fail in some cases, and to then check that the change fixes it :)

  • Thanks. I am tweaking alarm.app.js to have dated events, and I had a similar problem (which occurs depending on the time of the day + if you are in a negative or positive time zone) when I had to save the alarm date. I didn't notice we had access to toLocalIsoString, so at first I used the following instead (which we could use in the scheduler if we prefer to stay backward compatible):

    new Date(date - (date.getTimezoneOffset() * 60000)).toISOString().slice(0,10)

    As you proposed, I'll document a failing example in the scheduler before proposing an official fix.

  • Thanks! Yes, that would have been a good fix.

    In the development app loader I have just pushed a new version of the bootloader, which contains a polyfill for toLocalIsoString - so now you should be able to use that even on firmware 2v14 and it'll be ok

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

toLocalISOString instead of toISOString in apps/sched/lib.js?

Posted by Avatar for lauzon @lauzon

Actions