Port of Arduino Timezone library to Mbed for setting daylight saving/summer time

Dependents:   WebTimer DISCO-F746NG_light_control_system_tth

Committer:
hudakz
Date:
Wed Nov 11 16:53:04 2020 +0000
Revision:
0:38a95c82b08c
Port of Arduino Timezone library to set daylight saving/summer time.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:38a95c82b08c 1 /*----------------------------------------------------------------------*
hudakz 0:38a95c82b08c 2 * Arduino Timezone Library *
hudakz 0:38a95c82b08c 3 * Jack Christensen Mar 2012 *
hudakz 0:38a95c82b08c 4 * *
hudakz 0:38a95c82b08c 5 * Arduino Timezone Library Copyright (C) 2018 by Jack Christensen and *
hudakz 0:38a95c82b08c 6 * licensed under GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html *
hudakz 0:38a95c82b08c 7 *----------------------------------------------------------------------*/
hudakz 0:38a95c82b08c 8 #ifndef TIMEZONE_H_INCLUDED
hudakz 0:38a95c82b08c 9 #define TIMEZONE_H_INCLUDED
hudakz 0:38a95c82b08c 10
hudakz 0:38a95c82b08c 11 #include "mbed.h"
hudakz 0:38a95c82b08c 12
hudakz 0:38a95c82b08c 13 #define SECS_PER_MIN 60
hudakz 0:38a95c82b08c 14 #define SECS_PER_DAY 24*60*60
hudakz 0:38a95c82b08c 15
hudakz 0:38a95c82b08c 16 /*$off*/
hudakz 0:38a95c82b08c 17 // convenient constants for TimeChangeRules
hudakz 0:38a95c82b08c 18 enum week_t {Last, First, Second, Third, Fourth};
hudakz 0:38a95c82b08c 19 enum dow_t {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat};
hudakz 0:38a95c82b08c 20 enum month_t {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
hudakz 0:38a95c82b08c 21 /*$on*/
hudakz 0:38a95c82b08c 22
hudakz 0:38a95c82b08c 23 // structure to describe rules for when daylight/summer time begins,
hudakz 0:38a95c82b08c 24
hudakz 0:38a95c82b08c 25 // or when standard time begins.
hudakz 0:38a95c82b08c 26 struct TimeChangeRule
hudakz 0:38a95c82b08c 27 {
hudakz 0:38a95c82b08c 28 char abbrev[6]; // five chars max
hudakz 0:38a95c82b08c 29 uint8_t week; // First, Second, Third, Fourth, or Last week of the month
hudakz 0:38a95c82b08c 30 uint8_t dow; // day of week, 1=Sun, 2=Mon, ... 7=Sat
hudakz 0:38a95c82b08c 31 uint8_t month; // 1=Jan, 2=Feb, ... 12=Dec
hudakz 0:38a95c82b08c 32 uint8_t hour; // 0-23
hudakz 0:38a95c82b08c 33 int offset; // offset from UTC in minutes
hudakz 0:38a95c82b08c 34 };
hudakz 0:38a95c82b08c 35
hudakz 0:38a95c82b08c 36 class Timezone
hudakz 0:38a95c82b08c 37 {
hudakz 0:38a95c82b08c 38 public:
hudakz 0:38a95c82b08c 39 Timezone(TimeChangeRule dstStart, TimeChangeRule stdStart);
hudakz 0:38a95c82b08c 40 Timezone(TimeChangeRule stdTime);
hudakz 0:38a95c82b08c 41 Timezone(int address);
hudakz 0:38a95c82b08c 42 time_t toLocal(time_t utc);
hudakz 0:38a95c82b08c 43 time_t toLocal(time_t utc, TimeChangeRule ** tcr);
hudakz 0:38a95c82b08c 44 time_t toUTC(time_t local);
hudakz 0:38a95c82b08c 45 bool utcIsDST(time_t utc);
hudakz 0:38a95c82b08c 46 bool locIsDST(time_t local);
hudakz 0:38a95c82b08c 47 void setRules(TimeChangeRule dstStart, TimeChangeRule stdStart);
hudakz 0:38a95c82b08c 48 void readRules(int address);
hudakz 0:38a95c82b08c 49 void writeRules(int address);
hudakz 0:38a95c82b08c 50 private:
hudakz 0:38a95c82b08c 51 void calcTimeChanges(int yr);
hudakz 0:38a95c82b08c 52 void initTimeChanges();
hudakz 0:38a95c82b08c 53 time_t toTime_t(TimeChangeRule r, int yr);
hudakz 0:38a95c82b08c 54 int year(time_t seconds);
hudakz 0:38a95c82b08c 55 TimeChangeRule m_dst; // rule for start of dst or summer time for any year
hudakz 0:38a95c82b08c 56 TimeChangeRule m_std; // rule for start of standard time for any year
hudakz 0:38a95c82b08c 57 time_t m_dstUTC; // dst start for given/current year, given in UTC
hudakz 0:38a95c82b08c 58 time_t m_stdUTC; // std time start for given/current year, given in UTC
hudakz 0:38a95c82b08c 59 time_t m_dstLoc; // dst start for given/current year, given in local time
hudakz 0:38a95c82b08c 60 time_t m_stdLoc; // std time start for given/current year, given in local time
hudakz 0:38a95c82b08c 61 };
hudakz 0:38a95c82b08c 62
hudakz 0:38a95c82b08c 63 #endif // TIMEZONE_H_INCLUDED
hudakz 0:38a95c82b08c 64