]> Pileus Git - lackey/blob - src/date.h
Start on iCalendar support
[lackey] / src / date.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 /* Time types */
19 typedef int year_t;
20 typedef int day_t;
21 typedef int hour_t;
22 typedef int min_t;
23
24 typedef enum {
25         JAN =  0,
26         FEB =  1,
27         MAR =  2,
28         APR =  3,
29         MAY =  4,
30         JUN =  5,
31         JUL =  6,
32         AUG =  7,
33         SEP =  8,
34         OCT =  9,
35         NOV = 10,
36         DEC = 11,
37 } month_t;
38
39 typedef enum {
40         SUN = 0,
41         MON = 1,
42         TUE = 2,
43         WED = 3,
44         THU = 4,
45         FRI = 5,
46         SAT = 6,
47 } wday_t;
48
49 /* Global data */
50 extern year_t  YEAR;
51 extern month_t MONTH;
52 extern day_t   DAY;
53
54 /* Initialize */
55 void date_init(void);
56
57 /* Time functions */
58 int is_leap_year(year_t year);
59 int days_in_year(year_t year);
60 int days_in_month(year_t year, month_t month);
61 int weeks_in_month(year_t year, month_t month);
62 wday_t day_of_week(year_t year, month_t month, day_t day);
63 wday_t start_of_month(year_t year, month_t month);
64 day_t start_of_week(year_t year, month_t month, day_t day);
65 void add_days(year_t *year, month_t *month, day_t *day, int days);
66 void add_months(year_t *year, month_t *month, int months);
67
68 /* Time to string functions */
69 const char *month_to_str(month_t month);
70 const char *month_to_string(month_t month);
71 const char *day_to_st(wday_t day);
72 const char *day_to_str(wday_t day);
73 const char *day_to_string(wday_t day);
74
75 /* Tests */
76 void date_test(void);