Wondering if DST code is slowing down my Core

I’m using the following DST code in my loop

bool daylightSavings = isDST(Time.day(), Time.month(), Time.weekday()); Time.zone(daylightSavings ? 1 : 0);

and this function

bool isDST(int day, int month, int dayOfWeek) {
    if (month < 3 || month > 10) {
        return false;
    }
    if (month > 3 && month < 10) {
        return true;
    }
    int previousSunday = day - dayOfWeek;
    if (month == 3) {
        return previousSunday >= 25;
    }
    if (month == 10) return previousSunday < 25; {
        return false;
    }
}

It works (after years of struggling with DST!) BUT I’m wondering if it’s slowing down my Core? Button presses which used to be recognised more or less instant sometimes get missed or there is a few seconds’ delay - is there any way I could move this to a twice daily check?

thanks!!

This code does not really do a lot, so I doubt it’s the reason for your issue.
However, there is little use in passing in three parameters when all the information needed is already present in Time.now().
Particularly when only using this function for the current time, there is little sense in passing it as a parameter at all.

I did a search on the topic "oneshot" and found two posts. These helped me square away potential issues I might have had on when to calculate DST (as well as other features in my code).

The first is: oneShotGuard
https://community.particle.io/t/doing-something-at-a-certain-time/40245/5

I took the time to implement what @ScruffR said about it. It worked great for me.

The second is: class OneShot
https://community.particle.io/t/water-tank-monitor-using-hall-effect-switches/24868/26

Then, I borrowed from @Ric and made my own small library. Once done, it was relatively easy to implement oneShotGuard's for many different tasks that I had going and be confident they would fire once and only once, at the appropriate time.

BTW, thanks to all of you for the contributions! :slightly_smiling_face:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.