tm.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 RenĂ© Kijewski
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
17 #ifndef TM_H
18 #define TM_H
19 
20 #include <time.h>
21 #include <sys/time.h>
22 #include <stdint.h>
23 
24 #include "kernel_defines.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #define TM_WDAY_SUN (0)
31 #define TM_WDAY_MON (1)
32 #define TM_WDAY_TUE (2)
33 #define TM_WDAY_WED (3)
34 #define TM_WDAY_THU (4)
35 #define TM_WDAY_FRI (5)
36 #define TM_WDAY_SAT (6)
38 #define TM_MON_JAN ( 0)
39 #define TM_MON_FEB ( 1)
40 #define TM_MON_MAR ( 2)
41 #define TM_MON_APR ( 3)
42 #define TM_MON_MAY ( 4)
43 #define TM_MON_JUN ( 5)
44 #define TM_MON_JUL ( 6)
45 #define TM_MON_AUG ( 7)
46 #define TM_MON_SEP ( 8)
47 #define TM_MON_OCT ( 9)
48 #define TM_MON_NOV (10)
49 #define TM_MON_DEC (11)
55 extern const int8_t TM_MON_DAYS[12];
56 
61 extern const int16_t TM_MON_DAYS_ACCU[12];
62 
68 int tm_is_leap_year(unsigned year) CONST;
69 
76 int tm_doomsday(int year) CONST;
77 
87 #ifndef ATMEGA_INCOMPATIBLE_TIME_H
88 void tm_get_wyday(int year, int mon, int mday, int *wday, int *yday);
89 #else
90 void tm_get_wyday(int year, int mon, int mday, int8_t *wday, int16_t *yday);
91 #endif
92 
100 void tm_fill_derived_values(struct tm *tm);
101 
110 int tm_is_valid_date(int year, int mon, int mday) CONST;
111 
120 int tm_is_valid_time(int hour, int min, int sec) CONST;
121 
122 #ifdef __cplusplus
123 }
124 #endif
125 
126 #endif /* TM_H */
127 
kernel_defines.h
Common macros and compiler attributes/pragmas configuration.
tm_is_leap_year
int tm_is_leap_year(unsigned year) CONST
Tells if a given year is a leap year in the Gregorian calendar.
TM_MON_DAYS_ACCU
const int16_t TM_MON_DAYS_ACCU[12]
The prefixsum of the number of days in common years.
tm_is_valid_date
int tm_is_valid_date(int year, int mon, int mday) CONST
Tests if a date is valid.
tm_is_valid_time
int tm_is_valid_time(int hour, int min, int sec) CONST
Shallow test if a time is valid.
tm_fill_derived_values
void tm_fill_derived_values(struct tm *tm)
Fills in struct tm::tm_wday and struct tm::tm_yday given a date.
tm_get_wyday
void tm_get_wyday(int year, int mon, int mday, int *wday, int *yday)
Calculates the day of the year and the weekday of a given date.
CONST
#define CONST
A function declared as CONST is PURE and also not allowed to examine global memory....
Definition: kernel_defines.h:86
tm_doomsday
int tm_doomsday(int year) CONST
Returns the congruent weekday of the Doomsday (March 0).