$extrastylesheet
avr-libc
2.0.0
Standard C library for AVR-GCC
|
AVR Libc Home Page |
![]() |
AVR Libc Development Pages |
|||
Main Page |
User Manual |
Library Reference |
FAQ |
Example Projects |
00001 /* 00002 * (c)2012 Michael Duane Rice All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions are 00006 * met: 00007 * 00008 * Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. Redistributions in binary 00010 * form must reproduce the above copyright notice, this list of conditions 00011 * and the following disclaimer in the documentation and/or other materials 00012 * provided with the distribution. Neither the name of the copyright holders 00013 * nor the names of contributors may be used to endorse or promote products 00014 * derived from this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00017 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00018 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00019 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00020 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00021 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00022 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00023 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00024 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00025 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00026 * POSSIBILITY OF SUCH DAMAGE. 00027 */ 00028 00029 /* $Id: eu_dst.h 2492 2015-10-27 09:07:56Z swfltek $ */ 00030 00031 /** 00032 Daylight Saving function for the European Union. To utilize this function, you must 00033 \code #include <util/eu_dst.h> \endcode 00034 and 00035 \code set_dst(eu_dst); \endcode 00036 00037 Given the time stamp and time zone parameters provided, the Daylight Saving function must 00038 return a value appropriate for the tm structures' tm_isdst element. That is... 00039 00040 0 : If Daylight Saving is not in effect. 00041 00042 -1 : If it cannot be determined if Daylight Saving is in effect. 00043 00044 A positive integer : Represents the number of seconds a clock is advanced for Daylight Saving. 00045 This will typically be ONE_HOUR. 00046 00047 Daylight Saving 'rules' are subject to frequent change. For production applications it is 00048 recommended to write your own DST function, which uses 'rules' obtained from, and modifiable by, 00049 the end user ( perhaps stored in EEPROM ). 00050 */ 00051 00052 #ifndef EU_DST_H 00053 #define EU_DST_H 00054 00055 #ifdef __cplusplus 00056 extern "C" { 00057 #endif 00058 00059 #include <time.h> 00060 #include <inttypes.h> 00061 00062 int eu_dst(const time_t * timer, int32_t * z) { 00063 struct tm tmptr; 00064 uint8_t month, mday, hour, day_of_week, d; 00065 int n; 00066 00067 /* obtain the variables */ 00068 gmtime_r(timer, &tmptr); 00069 month = tmptr.tm_mon; 00070 day_of_week = tmptr.tm_wday; 00071 mday = tmptr.tm_mday - 1; 00072 hour = tmptr.tm_hour; 00073 00074 if ((month > MARCH) && (month < OCTOBER)) 00075 return ONE_HOUR; 00076 00077 if (month < MARCH) 00078 return 0; 00079 if (month > OCTOBER) 00080 return 0; 00081 00082 /* determine mday of last Sunday */ 00083 n = tmptr.tm_mday - 1; 00084 n -= day_of_week; 00085 n += 7; 00086 d = n % 7; /* date of first Sunday */ 00087 00088 n = 31 - d; 00089 n /= 7; /* number of Sundays left in the month */ 00090 00091 d = d + 7 * n; /* mday of final Sunday */ 00092 00093 if (month == MARCH) { 00094 if (d < mday) 00095 return 0; 00096 if (d > mday) 00097 return ONE_HOUR; 00098 if (hour < 2) 00099 return 0; 00100 return ONE_HOUR; 00101 } 00102 if (d < mday) 00103 return ONE_HOUR; 00104 if (d > mday) 00105 return 0; 00106 if (hour < 2) 00107 return ONE_HOUR; 00108 return 0; 00109 00110 } 00111 00112 #ifdef __cplusplus 00113 } 00114 #endif 00115 00116 #endif