Arduino-RTC
Real-Time Clock (RTC) library for Arduino
Main Page
Related Pages
Classes
Files
File List
File Members
usa_dst.h
Go to the documentation of this file.
1
/*
2
* (c)2012 Michael Duane Rice All rights reserved.
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are
6
* met:
7
*
8
* Redistributions of source code must retain the above copyright notice, this
9
* list of conditions and the following disclaimer. Redistributions in binary
10
* form must reproduce the above copyright notice, this list of conditions
11
* and the following disclaimer in the documentation and/or other materials
12
* provided with the distribution. Neither the name of the copyright holders
13
* nor the names of contributors may be used to endorse or promote products
14
* derived from this software without specific prior written permission.
15
*
16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
* POSSIBILITY OF SUCH DAMAGE.
27
*/
28
50
#ifndef USA_DST_H
51
#define USA_DST_H
52
53
#include <
time.h
>
54
#include <inttypes.h>
55
56
#ifndef DST_START_MONTH
57
#define DST_START_MONTH MARCH
58
#endif
59
60
#ifndef DST_END_MONTH
61
#define DST_END_MONTH NOVEMBER
62
#endif
63
64
#ifndef DST_START_WEEK
65
#define DST_START_WEEK 2
66
#endif
67
68
#ifndef DST_END_WEEK
69
#define DST_END_WEEK 1
70
#endif
71
72
int
usa_dst
(
const
time_t
* timer, int32_t * z)
73
{
74
time_t
t;
75
struct
tm
tmptr;
76
uint8_t month, week, hour, day_of_week, d;
77
int
n;
78
79
// Obtain the variables
80
t = *timer + *z;
81
gmtime_r
(&t, &tmptr);
82
month = tmptr.
tm_mon
;
83
day_of_week = tmptr.
tm_wday
;
84
week = week_of_month(&tmptr, 0);
85
hour = tmptr.
tm_hour
;
86
87
if
((month >
DST_START_MONTH
) && (month <
DST_END_MONTH
))
88
return
ONE_HOUR
;
89
90
if
(month <
DST_START_MONTH
)
91
return
0;
92
if
(month >
DST_END_MONTH
)
93
return
0;
94
95
if
(month ==
DST_START_MONTH
) {
96
if
(week <
DST_START_WEEK
)
97
return
0;
98
if
(week >
DST_START_WEEK
)
99
return
ONE_HOUR
;
100
101
if
(day_of_week >
SUNDAY
)
102
return
ONE_HOUR
;
103
if
(hour >= 2)
104
return
ONE_HOUR
;
105
return
0;
106
}
107
108
if
(week >
DST_END_WEEK
)
109
return
0;
110
if
(week <
DST_END_WEEK
)
111
return
ONE_HOUR
;
112
if
(day_of_week >
SUNDAY
)
113
return
0;
114
if
(hour >= 1)
115
return
0;
116
return
ONE_HOUR
;
117
}
118
#endif
DST_START_WEEK
#define DST_START_WEEK
Definition:
usa_dst.h:65
SUNDAY
Definition:
time.h:68
time.h
DST_START_MONTH
#define DST_START_MONTH
Definition:
usa_dst.h:57
ONE_HOUR
#define ONE_HOUR
Definition:
time.h:148
gmtime_r
struct tm * gmtime_r(const time_t *timer, struct tm *timeptr)
Definition:
gmtime_r.cpp:33
time_t
uint32_t time_t
Definition:
time.h:30
usa_dst
int usa_dst(const time_t *timer, int32_t *z)
Definition:
usa_dst.h:72
tm::tm_hour
int8_t tm_hour
Hours [0-23].
Definition:
time.h:39
tm::tm_wday
int8_t tm_wday
Days since Sunday [0-6].
Definition:
time.h:41
tm
Definition:
time.h:36
DST_END_WEEK
#define DST_END_WEEK
Definition:
usa_dst.h:69
tm::tm_mon
int8_t tm_mon
0-11 Months since January [0-11].
Definition:
time.h:42
DST_END_MONTH
#define DST_END_MONTH
Definition:
usa_dst.h:61
src
Hardware
AVR
usa_dst.h
Generated on Sat Oct 14 2017 03:08:57 for Arduino-RTC by
1.8.11