dtcm: Resolve CID 87822
[oweals/cde.git] / cde / programs / dtcm / server / reutil.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: reutil.h /main/4 1995/11/09 12:51:01 rswiston $ */
24 /*
25  *  (c) Copyright 1993, 1994 Hewlett-Packard Company
26  *  (c) Copyright 1993, 1994 International Business Machines Corp.
27  *  (c) Copyright 1993, 1994 Novell, Inc.
28  *  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
29  */
30
31 #ifndef _REUTIL_H
32 #define _REUTIL_H
33
34 #include "rerule.h"
35 #include "repeat.h"
36
37 #define EOT     2147483647
38
39 #define RE_DAILY(re)    (re->re_data.re_daily)
40 #define RE_WEEKLY(re)   (re->re_data.re_weekly)
41 #define RE_MONTHLY(re)  (re->re_data.re_monthly)
42 #define RE_YEARLY(re)   (re->re_data.re_yearly)
43 #define RES_DSTATE(res) (res->res_data.ds)
44 #define RES_WSTATE(res) (res->res_data.ws)
45 #define RES_MSTATE(res) (res->res_data.ms)
46 #define RES_YSTATE(res) (res->res_data.ys)
47 #define SAME_DAY(tm1, tm2)  (((tm1)->tm_year == (tm2)->tm_year && \
48                              (tm1)->tm_mon == (tm2)->tm_mon && \
49                              (tm1)->tm_mday == (tm2)->tm_mday))
50 #define SAME_MONTH(tm1, tm2) (((tm1)->tm_year == (tm2)->tm_year && \
51                               (tm1)->tm_mon == (tm2)->tm_mon))
52 #define TIME_OF_DAY(tm)   ((tm)->tm_hour * 60 * 60 + \
53                          (tm)->tm_min * 60 + \
54                          (tm)->tm_sec)
55 #define TIMEOFMONTH(tm) (((tm)->tm_mday - 1) * 24 * 60 * 60 + \
56                          (tm)->tm_hour * 60 * 60 + \
57                          (tm)->tm_min * 60 + \
58                          (tm)->tm_sec)
59 #define HOURTOSEC(time) ((time/100) * 60 * 60 + \
60                          (time%100) * 60)
61
62 extern int GetWDayDiff(const int, const int);
63 extern int DayExists(const int, const int, const int);
64 extern WeekNumber GetWeekNumber(const Tick);
65 extern WeekNumber DayToWeekNumber(const Tick);
66 extern Tick WeekNumberToDay(const Tick, const WeekNumber, const WeekDay);
67 extern int OccurenceExists(const WeekDayTime *, const unsigned int, const Tick);
68 extern unsigned int DayOfMonth(const int, const int, const int);
69 extern int InTimeRange(const unsigned int, const Duration);
70 extern int same_week(struct tm *, struct tm *);
71
72 extern Tick ClosestTick(const Tick, const Tick, RepeatEvent *,
73                         RepeatEventState **);
74 extern Tick NextTick(const Tick, const Tick, RepeatEvent *,
75                         RepeatEventState *);
76 extern Tick PrevTick(const Tick, const Tick, RepeatEvent *,
77                         RepeatEventState *);
78 extern Tick LastTick(const Tick, RepeatEvent *);
79 extern int CountEvents(Tick, RepeatEvent *re, CSA_date_time_entry *);
80 extern Tick DeriveNewStartTime(const Tick, RepeatEvent *old_re, const Tick, 
81                         const Tick, RepeatEvent *new_re);
82
83
84 #endif /* _REUTIL_H */