Zoltan Hudak / Timezone

Dependents:   WebTimer DISCO-F746NG_light_control_system_tth

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Timezone.h Source File

Timezone.h

00001 /*----------------------------------------------------------------------*
00002  * Arduino Timezone Library                                             *
00003  * Jack Christensen Mar 2012                                            *
00004  *                                                                      *
00005  * Arduino Timezone Library Copyright (C) 2018 by Jack Christensen and  *
00006  * licensed under GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html   *
00007  *----------------------------------------------------------------------*/
00008 #ifndef TIMEZONE_H_INCLUDED
00009 #define TIMEZONE_H_INCLUDED
00010 
00011 #include "mbed.h"
00012 
00013 #define SECS_PER_MIN    60
00014 #define SECS_PER_DAY    24*60*60
00015 
00016 /*$off*/
00017 // convenient constants for TimeChangeRules
00018 enum week_t {Last, First, Second, Third, Fourth};
00019 enum dow_t {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat};
00020 enum month_t {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
00021 /*$on*/
00022 
00023 // structure to describe rules for when daylight/summer time begins,
00024 
00025 // or when standard time begins.
00026 struct TimeChangeRule
00027 {
00028     char    abbrev[6];  // five chars max
00029     uint8_t week;       // First, Second, Third, Fourth, or Last week of the month
00030     uint8_t dow;        // day of week, 1=Sun, 2=Mon, ... 7=Sat
00031     uint8_t month;      // 1=Jan, 2=Feb, ... 12=Dec
00032     uint8_t hour;       // 0-23
00033     int     offset;     // offset from UTC in minutes
00034 };
00035 
00036 class   Timezone
00037 {
00038 public:
00039     Timezone(TimeChangeRule dstStart, TimeChangeRule stdStart);
00040     Timezone(TimeChangeRule stdTime);
00041     Timezone(int address);
00042     time_t  toLocal(time_t utc);
00043     time_t  toLocal(time_t utc, TimeChangeRule ** tcr);
00044     time_t  toUTC(time_t local);
00045     bool    utcIsDST(time_t utc);
00046     bool    locIsDST(time_t local);
00047     void    setRules(TimeChangeRule dstStart, TimeChangeRule stdStart);
00048     void    readRules(int address);
00049     void    writeRules(int address);
00050 private:
00051     void            calcTimeChanges(int yr);
00052     void            initTimeChanges();
00053     time_t          toTime_t(TimeChangeRule r, int yr);
00054     int             year(time_t seconds);
00055     TimeChangeRule  m_dst;      // rule for start of dst or summer time for any year
00056     TimeChangeRule  m_std;      // rule for start of standard time for any year
00057     time_t          m_dstUTC;   // dst start for given/current year, given in UTC
00058     time_t          m_stdUTC;   // std time start for given/current year, given in UTC
00059     time_t          m_dstLoc;   // dst start for given/current year, given in local time
00060     time_t          m_stdLoc;   // std time start for given/current year, given in local time
00061 };
00062 
00063 #endif // TIMEZONE_H_INCLUDED
00064