4 ms·
The most disturbing thing about this bug is that an RTC which can count days of the month and even leap years correctly is not at all new leading-edge technolog
by userbinator 5y ago
The most disturbing thing about this bug is that an RTC which can count days of the month and even leap years correctly is not at all new leading-edge technology. The pattern is simple enough that you can write a single expression to calculate it, which could be compiled down to a similarly compact arrangement of gates, but I'm guessing someone went the "lame" way with an array of entries -- and typo'd the November entry. Then no one noticed nor tested until it was far too late.
With the exception of February and an inversion after July, the pattern alternates binarily between 30 and 31. Thus, assuming zero-based months,
days = 30 + ((m+1 & 1) ^ (m > 6)) - (2 - isleap) * (m == 1);