]> Pileus Git - lackey/blob - src/date.h
600f26283509c704ccb9e1ecf4f846d33e6637ef
[lackey] / src / date.h
1 /*
2  * Copyright (C) 2012-2013 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 long long stamp_t;
20
21 typedef int year_t;
22 typedef int day_t;
23 typedef int hour_t;
24 typedef int min_t;
25 typedef int sec_t;
26
27 typedef enum {
28         JAN =  0,
29         FEB =  1,
30         MAR =  2,
31         APR =  3,
32         MAY =  4,
33         JUN =  5,
34         JUL =  6,
35         AUG =  7,
36         SEP =  8,
37         OCT =  9,
38         NOV = 10,
39         DEC = 11,
40 } month_t;
41
42 typedef enum {
43         SUN = 0,
44         MON = 1,
45         TUE = 2,
46         WED = 3,
47         THU = 4,
48         FRI = 5,
49         SAT = 6,
50 } wday_t;
51
52 typedef struct {
53         year_t  year;
54         month_t month;
55         day_t   day;
56         hour_t  hour;
57         min_t   min;
58         sec_t   sec;
59 } date_t;
60
61 /* Global data */
62 extern date_t NOW; // current wall clock time, refreshed at 10 Hz
63 extern date_t SEL; // date and time the user is looking at
64
65 /* Initialize */
66 void date_init(void);
67 void date_sync(void);
68
69 /* Time functions */
70 int is_leap_year(year_t year);
71 int days_in_year(year_t year);
72 int days_in_month(year_t year, month_t month);
73 int weeks_in_month(year_t year, month_t month);
74 wday_t day_of_week(year_t year, month_t month, day_t day);
75 wday_t start_of_month(year_t year, month_t month);
76 day_t start_of_week(year_t year, month_t month, day_t day);
77 void add_days(year_t *year, month_t *month, day_t *day, int days);
78 void add_months(year_t *year, month_t *month, int months);
79
80 stamp_t get_stamp(date_t *date);
81 int get_mins(date_t *start, date_t *end);
82 int compare(date_t *a, date_t *b);
83 int before(date_t *start, int year, int month, int day, int hour, int min);
84
85 int all_day(date_t *start, date_t *end);
86 int no_date(date_t *date);
87
88 /* Time to string functions */
89 const char *month_to_str(month_t month);
90 const char *month_to_string(month_t month);
91 const char *day_to_st(wday_t day);
92 const char *day_to_str(wday_t day);
93 const char *day_to_string(wday_t day);