date_time.h
Go to the documentation of this file.
1 /**
2  * @file date_time.h
3  * @brief Date and time management
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.6
27  **/
28 
29 #ifndef _DATE_TIME_H
30 #define _DATE_TIME_H
31 
32 //Dependencies
33 #include <time.h>
34 #include "os_port.h"
35 
36 //C++ guard
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 
42 /**
43  * @brief Date and time representation
44  **/
45 
46 typedef struct
47 {
48  uint16_t year;
49  uint8_t month;
50  uint8_t day;
51  uint8_t dayOfWeek;
52  uint8_t hours;
53  uint8_t minutes;
54  uint8_t seconds;
55  uint16_t milliseconds;
56 } DateTime;
57 
58 
59 //Date and time management
61 const char_t *formatDate(const DateTime *date, char_t *str);
62 
63 void getCurrentDate(DateTime *date);
64 time_t getCurrentUnixTime(void);
65 
66 void convertUnixTimeToDate(time_t t, DateTime *date);
67 time_t convertDateToUnixTime(const DateTime *date);
68 
69 int_t compareDateTime(const DateTime *date1, const DateTime *date2);
70 
71 uint8_t computeDayOfWeek(uint16_t y, uint8_t m, uint8_t d);
72 
73 //C++ guard
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 #endif
signed int int_t
Definition: compiler_port.h:44
uint16_t year
Definition: date_time.h:48
void getCurrentDate(DateTime *date)
Get current date and time.
Definition: date_time.c:165
time_t getCurrentUnixTime(void)
Get current time.
Definition: date_time.c:180
uint8_t day
Definition: date_time.h:50
const char_t * formatSystemTime(systime_t time, char_t *str)
Format system time.
Definition: date_time.c:77
uint8_t t
Definition: llmnr_common.h:81
void convertUnixTimeToDate(time_t t, DateTime *date)
Convert Unix timestamp to date.
Definition: date_time.c:198
uint8_t minutes
Definition: date_time.h:53
uint8_t hours
Definition: date_time.h:52
Date and time representation.
Definition: date_time.h:46
const char_t * formatDate(const DateTime *date, char_t *str)
Format date.
Definition: date_time.c:133
uint8_t seconds
Definition: date_time.h:54
uint8_t month
Definition: date_time.h:49
char char_t
Definition: compiler_port.h:43
uint8_t computeDayOfWeek(uint16_t y, uint8_t m, uint8_t d)
Calculate day of week.
Definition: date_time.c:351
uint32_t time
uint8_t m
Definition: ndp.h:302
time_t convertDateToUnixTime(const DateTime *date)
Convert date to Unix timestamp.
Definition: date_time.c:258
uint16_t milliseconds
Definition: date_time.h:55
int_t compareDateTime(const DateTime *date1, const DateTime *date2)
Compare dates.
Definition: date_time.c:302
uint8_t dayOfWeek
Definition: date_time.h:51
RTOS abstraction layer.
uint32_t systime_t
Definition: compiler_port.h:46