]> granicus.if.org Git - postgresql/blob - src/include/utils/nabstime.h
Massive commit to run PGINDENT on all *.c and *.h files.
[postgresql] / src / include / utils / nabstime.h
1 /*-------------------------------------------------------------------------
2  *
3  * nabstime.h--
4  *        Definitions for the "new" abstime code.
5  *
6  *
7  * Copyright (c) 1994, Regents of the University of California
8  *
9  * $Id: nabstime.h,v 1.11 1997/09/07 05:02:46 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef NABSTIME_H
14 #define NABSTIME_H
15
16 #include <time.h>
17 #include "utils/dt.h"
18
19
20 /* ----------------------------------------------------------------
21  *                              time types + support macros
22  *
23  *
24  * ----------------------------------------------------------------
25  */
26 typedef int32   AbsoluteTime;
27 typedef int32   RelativeTime;
28
29 typedef struct
30 {
31         int32                   status;
32         AbsoluteTime    data[2];
33 }                               TimeIntervalData;
34 typedef TimeIntervalData *TimeInterval;
35
36 /*
37  * Reserved values
38  * Epoch is Unix system time zero, but needs to be kept as a reserved
39  *      value rather than converting to time since timezone calculations
40  *      might move it away from 1970-01-01 00:00:00Z - tgl 97/02/20
41  *
42  * Pre-v6.1 code had large decimal numbers for reserved values.
43  * These were chosen as special 32-bit bit patterns,
44  *      so redefine them explicitly using these bit patterns. - tgl 97/02/24
45  */
46 #define EPOCH_ABSTIME   ((AbsoluteTime) 0)
47 #define INVALID_ABSTIME ((AbsoluteTime) 0x7FFFFFFE)             /* 2147483647 == 2^31 -
48                                                                                                                  * 1 */
49 #define CURRENT_ABSTIME ((AbsoluteTime) 0x7FFFFFFD)             /* 2147483646 == 2^31 -
50                                                                                                                  * 2 */
51 #define NOEND_ABSTIME   ((AbsoluteTime) 0x7FFFFFFC)             /* 2147483645 == 2^31 -
52                                                                                                                  * 3 */
53 #define BIG_ABSTIME             ((AbsoluteTime) 0x7FFFFFFB)             /* 2147483644 == 2^31 -
54                                                                                                                  * 4 */
55
56 #if defined(aix)
57 /*
58  * AIX considers 2147483648 == -2147483648 (since they have the same bit
59  * representation) but uses a different sign sense in a comparison to
60  * these integer constants depending on whether the constant is signed
61  * or not!
62  */
63 #define NOSTART_ABSTIME          ((AbsoluteTime) INT_MIN)
64 #else
65 #define NOSTART_ABSTIME ((AbsoluteTime) 0x80000001)             /* -2147483647 == - 2^31 */
66 #endif                                                  /* aix */
67
68 #define INVALID_RELTIME ((RelativeTime) 0x7FFFFFFE)             /* 2147483647 == 2^31 -
69                                                                                                                  * 1 */
70
71 #define AbsoluteTimeIsValid(time) \
72         ((bool) ((time) != INVALID_ABSTIME))
73
74 #define AbsoluteTimeIsReal(time) \
75         ((bool) (((AbsoluteTime) time) < NOEND_ABSTIME && \
76                          ((AbsoluteTime) time) > NOSTART_ABSTIME))
77
78 /* have to include this because EPOCH_ABSTIME used to be invalid - yuk */
79 #define AbsoluteTimeIsBackwardCompatiblyValid(time) \
80         ((bool) (((AbsoluteTime) time) != INVALID_ABSTIME && \
81                          ((AbsoluteTime) time) > EPOCH_ABSTIME))
82
83 #define AbsoluteTimeIsBackwardCompatiblyReal(time) \
84         ((bool) (((AbsoluteTime) time) < NOEND_ABSTIME && \
85                          ((AbsoluteTime) time) > NOSTART_ABSTIME && \
86                          ((AbsoluteTime) time) > EPOCH_ABSTIME))
87
88 #define RelativeTimeIsValid(time) \
89         ((bool) (((RelativeTime) time) != INVALID_RELTIME))
90
91 extern AbsoluteTime GetCurrentAbsoluteTime(void);
92
93 /*
94  * getSystemTime --
95  *              Returns system time.
96  */
97 #define getSystemTime() \
98         ((time_t) (time(0l)))
99
100
101 /*
102  * nabstime.c prototypes
103  */
104 extern AbsoluteTime nabstimein(char *timestr);
105 extern char    *nabstimeout(AbsoluteTime time);
106
107 extern bool             abstimeeq(AbsoluteTime t1, AbsoluteTime t2);
108 extern bool             abstimene(AbsoluteTime t1, AbsoluteTime t2);
109 extern bool             abstimelt(AbsoluteTime t1, AbsoluteTime t2);
110 extern bool             abstimegt(AbsoluteTime t1, AbsoluteTime t2);
111 extern bool             abstimele(AbsoluteTime t1, AbsoluteTime t2);
112 extern bool             abstimege(AbsoluteTime t1, AbsoluteTime t2);
113 extern bool             abstime_finite(AbsoluteTime time);
114
115 extern AbsoluteTime datetime_abstime(DateTime * datetime);
116 extern DateTime *abstime_datetime(AbsoluteTime abstime);
117
118 extern bool             AbsoluteTimeIsBefore(AbsoluteTime time1, AbsoluteTime time2);
119 extern bool             AbsoluteTimeIsAfter(AbsoluteTime time1, AbsoluteTime time2);
120
121 extern void             abstime2tm(AbsoluteTime time, int *tzp, struct tm * tm, char *tzn);
122
123 #endif                                                  /* NABSTIME_H */