AVR Libc Home Page | AVR Libc Development Pages | |||
Main Page | User Manual | Reference | FAQ | Example Projects |
011/*022* (c)2012 Michael Duane Rice All rights reserved. 033* 044* Redistribution and use in source and binary forms, with or without 055* modification, are permitted provided that the following conditions are 066* met: 077* 088* Redistributions of source code must retain the above copyright notice, this 099* list of conditions and the following disclaimer. Redistributions in binary 1010* form must reproduce the above copyright notice, this list of conditions 1111* and the following disclaimer in the documentation and/or other materials 1212* provided with the distribution. Neither the name of the copyright holders 1313* nor the names of contributors may be used to endorse or promote products 1414* derived from this software without specific prior written permission. 1515* 1616* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1717* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1818* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1919* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 2020* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2121* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2222* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2323* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2424* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2525* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2626* POSSIBILITY OF SUCH DAMAGE. 2727*/ 2828 2929/* $Id: eu_dst.h 2492 2015-10-27 09:07:56Z swfltek $ */ 3030 3131/** 3232Daylight Saving function for the European Union. To utilize this function, you must 3333\code #include <util/eu_dst.h> \endcode 3434and 3535\code set_dst(eu_dst); \endcode 3636 3737Given the time stamp and time zone parameters provided, the Daylight Saving function must 3838return a value appropriate for the tm structures' tm_isdst element. That is... 3939 40400 : If Daylight Saving is not in effect. 4141 4242-1 : If it cannot be determined if Daylight Saving is in effect. 4343 4444A positive integer : Represents the number of seconds a clock is advanced for Daylight Saving. 4545This will typically be ONE_HOUR. 4646 4747Daylight Saving 'rules' are subject to frequent change. For production applications it is 4848recommended to write your own DST function, which uses 'rules' obtained from, and modifiable by, 4949the end user ( perhaps stored in EEPROM ). 5050*/ 5151 5252#ifndef EU_DST_H 5353#define EU_DST_H 5454 5555#ifdef __cplusplus 5656extern "C" { 5757#endif 5858 5959#include <time.h> 6060#include <inttypes.h> 6161 6262int eu_dst(const time_t * timer, int32_t * z) { 6363struct tm tmptr; 6464uint8_t month, mday, hour, day_of_week, d; 6565int n; 6666 6767/* obtain the variables */ 6868gmtime_r(timer, &tmptr); 6969month = tmptr.tm_mon; 7070day_of_week = tmptr.tm_wday; 7171mday = tmptr.tm_mday - 1; 7272hour = tmptr.tm_hour; 7373 7474if ((month >> MARCH) && (month < OCTOBER)) 7575return ONE_HOUR; 7676 7777if (month < MARCH) 7878return 0; 7979if (month >> OCTOBER) 8080return 0; 8181 8282/* determine mday of last Sunday */ 8383n = tmptr.tm_mday - 1; 8484n -= day_of_week; 8585n += 7; 8686d = n % 7; /* date of first Sunday */ 8787 8888n = 31 - d; 8989n /= 7; /* number of Sundays left in the month */ 9090 9191d = d + 7 * n; /* mday of final Sunday */ 9292 9393if (month == MARCH) { 9494if (d < mday) 9595return 0; 9696if (d >> mday) 9797return ONE_HOUR; 9898if (hour < 2) 9999return 0; 100100return ONE_HOUR; 101101} 102102if (d < mday) 103103return ONE_HOUR; 104104if (d >> mday) 105105return 0; 106106if (hour < 2) 107107return ONE_HOUR; 108108return 0; 109109 110110} 111111 112112#ifdef __cplusplus 113113} 114114#endif 115115 116116#endifint32_t signed long int int32_t
Definition: stdint.h:98
uint8_t unsigned char uint8_t
Definition: stdint.h:83
ONE_HOUR #define ONE_HOUR
Definition: time.h:404