Developer World
Spresense Arduino Library v3.2.0-77d75a4
RtcTime.h
1/*
2 * RtcTime.h - Spresense Arduino RTC library
3 * Copyright 2018 Sony Semiconductor Solutions Corporation
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef __RTCTIME_H__
21#define __RTCTIME_H__
22
35{
36public:
40 RtcTime(uint32_t sec = 0, long nsec = 0);
41 RtcTime(int year, int month, int day, int hour = 0, int minute = 0, int second = 0, long nsec = 0);
42 RtcTime(const char* date, const char* time);
43
47 uint32_t unixtime() const { return _sec; }
48 long nsec() const { return _nsec; }
49 int year() const { return _year; }
50 int month() const { return _month; }
51 int day() const { return _day; }
52 int hour() const { return _hour; }
53 int minute() const { return _minute; }
54 int second() const { return _second; }
55
59 void unixtime(uint32_t sec);
60 void nsec(long nsec);
61 void year(int year);
62 void month(int month);
63 void day(int day);
64 void hour(int hour);
65 void minute(int minute);
66 void second(int second);
67
71 bool operator == (const RtcTime& other) const {
72 return (_sec == other._sec);
73 }
74
75 bool operator != (const RtcTime& other) const {
76 return !(*this == other);
77 }
78
79 void operator += (uint32_t seconds) {
80 RtcTime after = RtcTime(unixtime() + seconds);
81 *this = after;
82 }
83
84 void operator -= (uint32_t seconds) {
85 RtcTime before = RtcTime(unixtime() - seconds);
86 *this = before;
87 }
88
89 operator uint32_t() const {
90 return unixtime();
91 }
92
93private:
94 uint32_t _sec; /* UNIX time in Seconds (time_t) */
95 long _nsec; /* Nanoseconds */
96 int _year; /* Years */
97 int _month; /* Month (1-12) */
98 int _day; /* Day of the month (1-31) */
99 int _hour; /* Hours (0-23) */
100 int _minute; /* Minutes (0-59) */
101 int _second; /* Seconds (0-61, allows for leap seconds) */
102 void update(int year, int month, int day, int hour, int minute, int second);
103 void update();
104};
105
108#endif // __RTCETIME_H__
RTC time definitions.
Definition: RtcTime.h:35
void unixtime(uint32_t sec)
Setter APIs of RtcTime.
RtcTime(uint32_t sec=0, long nsec=0)
Create RtcTime object.
bool operator==(const RtcTime &other) const
operator APIs to compare and calculate with RtcTime
Definition: RtcTime.h:71
uint32_t unixtime() const
Getter APIs of RtcTime.
Definition: RtcTime.h:47