]> Pileus Git - lackey/blob - src/util.h
Start on events and calendars
[lackey] / src / util.h
1 /*
2  * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef UTIL_H
19 #define UTIL_H
20
21 /* Macros */
22 #define MIN(a,b) ((a) < (b) ? (a) : (b))
23 #define MAX(a,b) ((a) > (b) ? (a) : (b))
24 #define ROUND(x) ((int)((x)+0.5))
25 #define N_ELEMENTS(x) (sizeof(x)/sizeof((x)[0]))
26
27 /* Time types */
28 typedef int year_t;
29 typedef int day_t;
30 typedef int hour_t;
31 typedef int min_t;
32
33 typedef enum {
34         JAN =  0,
35         FEB =  1,
36         MAR =  2,
37         APR =  3,
38         MAY =  4,
39         JUN =  5,
40         JUL =  6,
41         AUG =  7,
42         SEP =  8,
43         OCT =  9,
44         NOV = 10,
45         DEC = 11,
46 } month_t;
47
48 typedef enum {
49         SUN = 0,
50         MON = 1,
51         TUE = 2,
52         WED = 3,
53         THU = 4,
54         FRI = 5,
55         SAT = 6,
56 } wday_t;
57
58 /* Time functions */
59 int is_leap_year(year_t year);
60 int days_in_year(year_t year);
61 int days_in_month(year_t year, month_t month);
62 int weeks_in_month(year_t year, month_t month);
63 wday_t day_of_week(year_t year, month_t month, day_t day);
64 wday_t start_of_month(year_t year, month_t month);
65 day_t start_of_week(year_t year, month_t month, day_t day);
66 void add_days(year_t *year, month_t *month, day_t *day, int days);
67 void add_months(year_t *year, month_t *month, int months);
68
69 /* Time to string functions */
70 const char *month_to_str(month_t month);
71 const char *month_to_string(month_t month);
72 const char *day_to_st(wday_t day);
73 const char *day_to_str(wday_t day);
74 const char *day_to_string(wday_t day);
75
76 /* Tests */
77 void test_time(void);
78
79 #endif