nabstime.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*-------------------------------------------------------------------------
  2. *
  3. * nabstime.h
  4. * Definitions for the "new" abstime code.
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/utils/nabstime.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef NABSTIME_H
  15. #define NABSTIME_H
  16. #include <limits.h>
  17. #include "fmgr.h"
  18. #include "pgtime.h"
  19. /* ----------------------------------------------------------------
  20. *
  21. * time types + support macros
  22. *
  23. * ----------------------------------------------------------------
  24. */
  25. /*
  26. * Although time_t generally is a long int on 64 bit systems, these two
  27. * types must be 4 bytes, because that's what pg_type.h assumes. They
  28. * should be yanked (long) before 2038 and be replaced by timestamp and
  29. * interval.
  30. */
  31. typedef int32 AbsoluteTime;
  32. typedef int32 RelativeTime;
  33. typedef struct
  34. {
  35. int32 status;
  36. AbsoluteTime data[2];
  37. } TimeIntervalData;
  38. typedef TimeIntervalData *TimeInterval;
  39. /*
  40. * Macros for fmgr-callable functions.
  41. */
  42. #define DatumGetAbsoluteTime(X) ((AbsoluteTime) DatumGetInt32(X))
  43. #define DatumGetRelativeTime(X) ((RelativeTime) DatumGetInt32(X))
  44. #define DatumGetTimeInterval(X) ((TimeInterval) DatumGetPointer(X))
  45. #define AbsoluteTimeGetDatum(X) Int32GetDatum(X)
  46. #define RelativeTimeGetDatum(X) Int32GetDatum(X)
  47. #define TimeIntervalGetDatum(X) PointerGetDatum(X)
  48. #define PG_GETARG_ABSOLUTETIME(n) DatumGetAbsoluteTime(PG_GETARG_DATUM(n))
  49. #define PG_GETARG_RELATIVETIME(n) DatumGetRelativeTime(PG_GETARG_DATUM(n))
  50. #define PG_GETARG_TIMEINTERVAL(n) DatumGetTimeInterval(PG_GETARG_DATUM(n))
  51. #define PG_RETURN_ABSOLUTETIME(x) return AbsoluteTimeGetDatum(x)
  52. #define PG_RETURN_RELATIVETIME(x) return RelativeTimeGetDatum(x)
  53. #define PG_RETURN_TIMEINTERVAL(x) return TimeIntervalGetDatum(x)
  54. /*
  55. * Reserved values
  56. * Epoch is Unix system time zero, but needs to be kept as a reserved
  57. * value rather than converting to time since timezone calculations
  58. * might move it away from 1970-01-01 00:00:00Z - tgl 97/02/20
  59. *
  60. * Pre-v6.1 code had large decimal numbers for reserved values.
  61. * These were chosen as special 32-bit bit patterns,
  62. * so redefine them explicitly using these bit patterns. - tgl 97/02/24
  63. */
  64. #define INVALID_ABSTIME ((AbsoluteTime) 0x7FFFFFFE) /* 2147483647 (2^31 - 1) */
  65. #define NOEND_ABSTIME ((AbsoluteTime) 0x7FFFFFFC) /* 2147483645 (2^31 - 3) */
  66. #define NOSTART_ABSTIME ((AbsoluteTime) INT_MIN) /* -2147483648 */
  67. #define INVALID_RELTIME ((RelativeTime) 0x7FFFFFFE) /* 2147483647 (2^31 - 1) */
  68. #define AbsoluteTimeIsValid(time) \
  69. ((bool) ((time) != INVALID_ABSTIME))
  70. /*
  71. * Because NOSTART_ABSTIME is defined as INT_MIN, there can't be any
  72. * AbsoluteTime values less than it. Therefore, we can code the test
  73. * "time > NOSTART_ABSTIME" as "time != NOSTART_ABSTIME", which avoids
  74. * compiler bugs on some platforms. --- tgl & az, 11/2000
  75. */
  76. #define AbsoluteTimeIsReal(time) \
  77. ((bool) (((AbsoluteTime) (time)) < NOEND_ABSTIME && \
  78. ((AbsoluteTime) (time)) != NOSTART_ABSTIME))
  79. #define RelativeTimeIsValid(time) \
  80. ((bool) (((RelativeTime) (time)) != INVALID_RELTIME))
  81. /*
  82. * nabstime.c prototypes
  83. */
  84. extern Datum abstimein(PG_FUNCTION_ARGS);
  85. extern Datum abstimeout(PG_FUNCTION_ARGS);
  86. extern Datum abstimerecv(PG_FUNCTION_ARGS);
  87. extern Datum abstimesend(PG_FUNCTION_ARGS);
  88. extern Datum abstimeeq(PG_FUNCTION_ARGS);
  89. extern Datum abstimene(PG_FUNCTION_ARGS);
  90. extern Datum abstimelt(PG_FUNCTION_ARGS);
  91. extern Datum abstimegt(PG_FUNCTION_ARGS);
  92. extern Datum abstimele(PG_FUNCTION_ARGS);
  93. extern Datum abstimege(PG_FUNCTION_ARGS);
  94. extern Datum abstime_finite(PG_FUNCTION_ARGS);
  95. extern Datum timestamp_abstime(PG_FUNCTION_ARGS);
  96. extern Datum abstime_timestamp(PG_FUNCTION_ARGS);
  97. extern Datum timestamptz_abstime(PG_FUNCTION_ARGS);
  98. extern Datum abstime_timestamptz(PG_FUNCTION_ARGS);
  99. extern Datum reltimein(PG_FUNCTION_ARGS);
  100. extern Datum reltimeout(PG_FUNCTION_ARGS);
  101. extern Datum reltimerecv(PG_FUNCTION_ARGS);
  102. extern Datum reltimesend(PG_FUNCTION_ARGS);
  103. extern Datum tintervalin(PG_FUNCTION_ARGS);
  104. extern Datum tintervalout(PG_FUNCTION_ARGS);
  105. extern Datum tintervalrecv(PG_FUNCTION_ARGS);
  106. extern Datum tintervalsend(PG_FUNCTION_ARGS);
  107. extern Datum interval_reltime(PG_FUNCTION_ARGS);
  108. extern Datum reltime_interval(PG_FUNCTION_ARGS);
  109. extern Datum mktinterval(PG_FUNCTION_ARGS);
  110. extern Datum timepl(PG_FUNCTION_ARGS);
  111. extern Datum timemi(PG_FUNCTION_ARGS);
  112. extern Datum intinterval(PG_FUNCTION_ARGS);
  113. extern Datum tintervalrel(PG_FUNCTION_ARGS);
  114. extern Datum timenow(PG_FUNCTION_ARGS);
  115. extern Datum reltimeeq(PG_FUNCTION_ARGS);
  116. extern Datum reltimene(PG_FUNCTION_ARGS);
  117. extern Datum reltimelt(PG_FUNCTION_ARGS);
  118. extern Datum reltimegt(PG_FUNCTION_ARGS);
  119. extern Datum reltimele(PG_FUNCTION_ARGS);
  120. extern Datum reltimege(PG_FUNCTION_ARGS);
  121. extern Datum tintervalsame(PG_FUNCTION_ARGS);
  122. extern Datum tintervaleq(PG_FUNCTION_ARGS);
  123. extern Datum tintervalne(PG_FUNCTION_ARGS);
  124. extern Datum tintervallt(PG_FUNCTION_ARGS);
  125. extern Datum tintervalgt(PG_FUNCTION_ARGS);
  126. extern Datum tintervalle(PG_FUNCTION_ARGS);
  127. extern Datum tintervalge(PG_FUNCTION_ARGS);
  128. extern Datum tintervalleneq(PG_FUNCTION_ARGS);
  129. extern Datum tintervallenne(PG_FUNCTION_ARGS);
  130. extern Datum tintervallenlt(PG_FUNCTION_ARGS);
  131. extern Datum tintervallengt(PG_FUNCTION_ARGS);
  132. extern Datum tintervallenle(PG_FUNCTION_ARGS);
  133. extern Datum tintervallenge(PG_FUNCTION_ARGS);
  134. extern Datum tintervalct(PG_FUNCTION_ARGS);
  135. extern Datum tintervalov(PG_FUNCTION_ARGS);
  136. extern Datum tintervalstart(PG_FUNCTION_ARGS);
  137. extern Datum tintervalend(PG_FUNCTION_ARGS);
  138. extern Datum timeofday(PG_FUNCTION_ARGS);
  139. /* non-fmgr-callable support routines */
  140. extern AbsoluteTime GetCurrentAbsoluteTime(void);
  141. extern void abstime2tm(AbsoluteTime time, int *tzp, struct pg_tm * tm, char **tzn);
  142. #endif /* NABSTIME_H */