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