Skip to content

Commit 215356e

Browse files
authored
Merge pull request arduino#81 from bcmi-labs/unix_rtc
RTC: RTCTime add setUnixTime Former-commit-id: 3ef60fb
2 parents 73eb3f9 + 94823f4 commit 215356e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

libraries/RTC/src/RTC.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class RTCTime {
7979

8080
public:
8181
RTCTime();
82+
RTCTime(time_t t);
8283
RTCTime(struct tm &t);
8384
RTCTime(int _day, Month _m, int _year, int _hours, int _minutes, int _seconds, DayOfWeek _dof, SaveLight _sl);
8485
~RTCTime();
@@ -92,6 +93,7 @@ class RTCTime {
9293
bool setSecond(int second); /* from 0 to 59 */
9394
bool setDayOfWeek(DayOfWeek d);
9495
bool setSaveLight(SaveLight sl);
96+
bool setUnixTime(time_t time);
9597

9698
void setTM(struct tm &t);
9799
/* getters */

libraries/RTC/src/RTClock.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ SaveLight tm2SaveLight(struct tm &t) {
202202
return (t.tm_isdst == 0) ? SaveLight::SAVING_TIME_INACTIVE : SaveLight::SAVING_TIME_ACTIVE;
203203
}
204204

205+
RTCTime::RTCTime(time_t t) {
206+
setUnixTime(t);
207+
}
208+
205209
RTCTime::RTCTime(struct tm &t) {
206210
setTM(t);
207211
}
@@ -338,6 +342,13 @@ bool RTCTime::setSaveLight(SaveLight sl) {
338342
return true;
339343
}
340344

345+
bool RTCTime::setUnixTime(time_t time) {
346+
struct tm *t;
347+
t = localtime(&time);
348+
setTM(*t);
349+
return true;
350+
}
351+
341352
/* getters */
342353
int RTCTime::getDayOfMonth() { return day; }
343354
Month RTCTime::getMonth() { return month; }

0 commit comments

Comments
 (0)