Skip to content

Commit 43e722e

Browse files
committed
Use new RTCZero epoch API's
1 parent d66263a commit 43e722e

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

src/time.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,16 @@ RTCZero rtc;
1111
extern "C" {
1212
int _gettimeofday(struct timeval* tp, void* /*tzvp*/)
1313
{
14-
struct tm tm;
15-
16-
tm.tm_isdst = -1;
17-
tm.tm_yday = 0;
18-
tm.tm_wday = 0;
19-
tm.tm_year = rtc.getYear() + 100;
20-
tm.tm_mon = rtc.getMonth() + 1;
21-
tm.tm_mday = rtc.getDay();
22-
tm.tm_hour = rtc.getHours();
23-
tm.tm_min = rtc.getMinutes();
24-
tm.tm_sec = rtc.getSeconds();
25-
26-
tp->tv_sec = mktime(&tm);
14+
tp->tv_sec = rtc.getEpoch();
2715
tp->tv_usec = 0;
2816

2917
return 0;
3018
}
3119

3220
int settimeofday(const struct timeval* tp, const struct timezone* /*tzp*/)
3321
{
34-
struct tm* tmp = gmtime(&tp->tv_sec);
35-
3622
rtc.begin();
37-
rtc.setDate(tmp->tm_mday, tmp->tm_mon - 1, tmp->tm_year - 100);
38-
rtc.setTime(tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
23+
rtc.setEpoch(tp->tv_sec);
3924

4025
return 0;
4126
}

0 commit comments

Comments
 (0)