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