54
54
static unsigned long _carry = 0;
57
static int days_in_month( int month, int year )
60
return !( year % 4 ) && ( ( year % 100 ) || !( year % 400 ) )? 29 : 28;
61
else if( month == 9 || month == 6 || month == 4 || month == 11 )
68
void Time::load_time()
70
// get the time from the real-time clock
72
RTC.get( rtc_data, true );
73
_year = rtc_data[ DS1307_YR ];
74
_month = rtc_data[ DS1307_MTH ];
75
_day = rtc_data[ DS1307_DAY ];
76
_hours = rtc_data[ DS1307_HR ];
77
_minutes = rtc_data[ DS1307_MIN ];
78
_seconds = rtc_data[ DS1307_SEC ];
80
// make sure some numbers are in range
81
if( _year < YEAR_MIN || _year > YEAR_MAX ) _year = 2010;
82
if( _month < 1 || _month > 12 ) _month = 1;
83
if( _day < 1 || _day > days_in_month( _year, _month ) ) _day = 1;
87
void Time::save_time()
89
// set the time on the real-time clock
91
RTC.set( DS1307_YR, _year );
92
RTC.set( DS1307_MTH, _month );
93
RTC.set( DS1307_DAY, _day );
94
RTC.set( DS1307_HR, _hours );
95
RTC.set( DS1307_MIN, _minutes );
96
RTC.set( DS1307_SEC, _seconds );
58
101
int Time::get_year()
135
static int days_in_month( int month, int year )
138
return !( year % 4 ) && ( ( year % 100 ) || !( year % 400 ) )? 29 : 28;
139
else if( month == 9 || month == 6 || month == 4 || month == 11 )
146
static void load_time()
148
// get the time from the real-time clock
150
RTC.get( rtc_data, true );
151
_year = rtc_data[ DS1307_YR ];
152
_month = rtc_data[ DS1307_MTH ];
153
_day = rtc_data[ DS1307_DAY ];
154
_hours = rtc_data[ DS1307_HR ];
155
_minutes = rtc_data[ DS1307_MIN ];
156
_seconds = rtc_data[ DS1307_SEC ];
158
// make sure some numbers are in range
159
if( _year < YEAR_MIN || _year > YEAR_MAX ) _year = 2010;
160
if( _month < 1 || _month > 12 ) _month = 1;
161
if( _day < 1 || _day > days_in_month( _year, _month ) ) _day = 1;
165
178
void Time::update()
167
180
// how many milliseconds have elapsed since we last checked?
203
static void save_time()
205
// set the time on the real-time clock
207
RTC.set( DS1307_YR, _year );
208
RTC.set( DS1307_MTH, _month );
209
RTC.set( DS1307_DAY, _day );
210
RTC.set( DS1307_HR, _hours );
211
RTC.set( DS1307_MIN, _minutes );
212
RTC.set( DS1307_SEC, _seconds );
217
210
void Time::inc_hours()
219
212
if( ++_hours >= 24 )