Timezone.h
/*----------------------------------------------------------------------*
 * Arduino Timezone Library                                             *
 * Jack Christensen Mar 2012                                            *
 *                                                                      *
 * Arduino Timezone Library Copyright (C ) 2018 by Jack Christensen and  *
 * licensed under GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html   *
 *----------------------------------------------------------------------*/

#ifndef TIMEZONE_H_INCLUDED
#define TIMEZONE_H_INCLUDED
#if ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#include <TimeLib.h>    // https://github.com/PaulStoffregen/Time

// CONVENIENT CONSTANTS FOR TimeChangeRules
enum week_t {Last, First, Second, Third, Fourth};
enum dow_t {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat};
enum month_t {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};

// STRUCTURE TO DESCRIBE RULES FOR WHEN DAYLIGHT/SUMMER TIME BEGINS,
// OR WHEN STANDARD TIME BEGINS.
struct   TimeChangeRule
{
    char abbrev[6];    // FIVE CHARS MAX
    uint8_t week;      // 1ST, 2ND, 3RD, 4TH, OR lAST WEEK OF THE MONTH
    uint8_t dow;       // DAY OF WEEK, 1=SUN, 2=MON, ... 7=SAT
    uint8_t month;     // 1=Jan, 2=Feb, ... 12=Dec
    uint8_t hour;      // 0-23
    int offset;        // offset from UTC in minutes
};

class Timezone
{
    public:
        Timezone( TimeChangeRule dstStart, TimeChangeRule stdStart );
        Timezone( TimeChangeRule stdTime );
        Timezone( int address );
        time_t toLocal( time_t utc );
        time_t toLocal( time_t utc, TimeChangeRule **tcr );
        time_t toUTC( time_t local );
        bool utcIsDST( time_t utc );
        bool locIsDST( time_t local );
        void setRules( TimeChangeRule dstStart, TimeChangeRule stdStart );
        void readRules( int address );
        void writeRules( int address );

    private:
        void calcTimeChanges( int yr );
        void initTimeChanges();
        time_t toTime_t( TimeChangeRule r, int yr );
        TimeChangeRule m_dst;// RULE FOR START OF DST OR SUMMER TIME FOR ANY YR
        TimeChangeRule m_std;   // RULE FOR START OF STANDARD TIME FOR ANY YR
        time_t m_dstUTC;    // DST START FOR GIVEN/CURRENT YEAR, GIVEN IN UTC
        time_t m_stdUTC; // STD TIME START FOR GIVEN/CURRENT YEAR, GIVEN IN UTC
        time_t m_dstLoc; // DST START FOR GIVEN/CURRENT YR, GIVEN IN LOCAL TIME
        time_t m_stdLoc; // STD TIME START FOR GIVEN/CURRENT YR, GIVEN IN LOCAL TIME
};
#endif