My attempt at detecting EST/EDT change automatically

@bko, nice code…very clean.

Slightly optimized code…version 2 below:

//
//  Last update:  03/11/18
//

typedef struct DSTStruct
{
    int year;
    int startDay;                                               // DST start day in Mar
    int endDay;                                                 // DST end day in Nov
} DST;

DST dst[] = {                                                   // Table data for Richmond, VA
    12,0,0,                                                     // dst[0].year field holds # of elements
    2018,11,4,
    2019,10,3,
    2020,8,1,
    2021,14,7,
    2022,13,6,
    2023,12,5,
    2024,10,3,
    2025,9,2,
    2026,8,1,
    2027,14,7,
    2028,12,5,
    2029,11,4
};

void setup(void) 
{
    int rc;
    
    Serial.begin(115200);
    Time.zone(-5);                                              // EST/EDT
    rc = isDSTActive();
    if (rc == 0)
    {
        Time.endDST();    
        Serial.println("DST not active");
    }
    else if (rc == 1)
    {
        Time.setDSTOffset(1.0);                                 // Offset is 1 hour
        Time.beginDST();        
        Serial.println("DST active");
    }
    else Serial.println("Error determining DST");
}

void loop(void) 
{
    Serial.println(Time.format("%r"));
    delay(1000);
}

int isDSTActive(void)
{
    int sDay,                                                   // Start day in Mar    
        eDay;                                                   // End day in Nov

    if (Time.month() > 3 && Time.month() < 11)                  // Apr - Oct = EDT
        return 1;
    else if (Time.month() < 3 || Time.month() == 12)            // Jan, Feb, Dec = EST
        return 0;

    if (!findYear(Time.year(), &sDay, &eDay))                   // Did we find this year's data?
    {
        Serial.println("Error - couldn't find data for this year");
        return 2;
    }

    switch (Time.month())
    {
        case 3:                                                 // March (spring forward)
            if ((Time.day() > sDay) || (Time.day() == sDay && Time.hour() > 1))
                return 1;
            else 
                return 0;
        case 11:                                                // November (fall back)
            if ((Time.day() < eDay) || (Time.day() == eDay && Time.hour() < 2))
                return 1;
            else 
                return 0;
    }
}

bool findYear(int year, int *sDay, int *eDay)
{
    int numItems = dst[0].year;                                 // How many structure items?
    
    for (int x = 1; x <= numItems; x++)
    {
        if (dst[x].year == year)
        {
            *sDay = dst[x].startDay;
            *eDay = dst[x].endDay;
            return true;                                        // Found current year's data
        }
    }
    return false;
}