I have an if statement that checks for 03::00 on the last Sunday in October:
if (dow == 0 && mo == 10 && d >= 25 && h == 3){DSTToggle()}
And I have another statement that checks for 02:00 on the last Sunday in March
if (dow == 0 && mo == 3 && d >= 25 && h ==2){DSTToggle()}
How can I combine them both into a single if statement?
(Which will go to an existing function to toggle a DST toggle on or off)
if ((dow == 0 && mo == 10 && d >= 25 && h == 3) ||
(dow == 0 && mo == 3 && d >= 25 && h ==2))
{
DSTToggle();
}
You can pull out two of your conditions:
if (dow == 0 && d >= 25 &&
((mo == 10 && h == 3) || (mo == 3 && h ==2)))
{
DSTToggle();
}
Hopefully you have code defending against calling this multiple times in the same hour.
Remember to check EXACTLY once an hour. Any more often and DST will toggle more than once in that hour. Any less often and you may miss the hour completely.
It would be MUCH safer to keep the two separate 'if' statements and call separate functions to switch DST on and off. If there is only a function to toggle, and it's not your code so you can't fix that deficiency, and there is a function to check the current DST state: you could write a function that checks the current state against the desired state and only toggle on mismatch.