datetime.h
1 /*
2  * EEZ PSU Firmware
3  * Copyright (C) 2015-present, Envox d.o.o.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9 
10  * This program 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
13  * GNU General Public License for more details.
14 
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 namespace eez {
22 namespace psu {
24 namespace datetime {
25 
26 extern psu::TestResult g_testResult;
27 
28 void init();
29 bool test();
30 
31 bool isValidDate(uint8_t year, uint8_t month, uint8_t day);
32 bool getDate(uint8_t &year, uint8_t &month, uint8_t &day);
33 bool setDate(uint8_t year, uint8_t month, uint8_t day);
34 
35 bool isValidTime(uint8_t hour, uint8_t minute, uint8_t second);
36 bool getTime(uint8_t &hour, uint8_t &minute, uint8_t &second);
37 bool setTime(uint8_t hour, uint8_t minute, uint8_t second);
38 
39 bool getDateTime(uint8_t &year, uint8_t &month, uint8_t &day, uint8_t &hour, uint8_t &minute, uint8_t &second);
40 bool setDateTime(uint8_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
41 
45 bool getDateTimeAsString(char *buffer);
46 
47 uint32_t now();
48 uint32_t makeTime(int year, int month, int day, int hour, int minute, int second);
49 void breakTime(uint32_t time, int &resultYear, int &resultMonth, int &resultDay, int &resultHour, int &resultMinute, int &resultSecond);
50 
51 struct DateTime {
52  uint16_t year;
53  uint8_t month, day, hour, minute, second;
54 
55  DateTime();
56  DateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
57  DateTime(const DateTime& rhs);
58 
59  static DateTime now();
60 
61  bool operator ==(const DateTime &rhs);
62  bool operator !=(const DateTime &rhs);
63 };
64 
65 }
66 }
67 }; // namespace eez::psu::datetime
Namespace for the everything from the EEZ.
Definition: actions.cpp:41
bool getDateTimeAsString(char *buffer)
Returns date time as string in format YYYY-MM-DD HH:MM:SS.
Definition: datetime.cpp:178
Definition: datetime.h:51