1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include "postgres.h"
#include "miscadmin.h"
#include "utils/builtins.h"
#include "access/xact.h"
time_t
timestamp_in(const char *timestamp_str)
{
int4 result;
result = nabstimein((char *) timestamp_str);
return result;
}
char *
timestamp_out(time_t timestamp)
{
char *result;
int tz;
double fsec = 0;
struct tm tt,
*tm = &tt;
char buf[MAXDATELEN + 1];
char zone[MAXDATELEN + 1],
*tzn = zone;
switch (timestamp)
{
case EPOCH_ABSTIME:
strcpy(buf, EPOCH);
break;
case INVALID_ABSTIME:
strcpy(buf, INVALID);
break;
case CURRENT_ABSTIME:
strcpy(buf, DCURRENT);
break;
case NOEND_ABSTIME:
strcpy(buf, LATE);
break;
case NOSTART_ABSTIME:
strcpy(buf, EARLY);
break;
default:
abstime2tm(timestamp, &tz, tm, tzn);
EncodeDateTime(tm, fsec, &tz, &tzn, USE_ISO_DATES, buf);
break;
}
result = palloc(strlen(buf) + 1);
strcpy(result, buf);
return result;
} /* timestamp_out() */
time_t
now(void)
{
time_t sec;
sec = GetCurrentTransactionStartTime();
return (sec);
}
bool
timestampeq(time_t t1, time_t t2)
{
return (abstimeeq(t1, t2));
}
bool
timestampne(time_t t1, time_t t2)
{
return (abstimene(t1, t2));
}
bool
timestamplt(time_t t1, time_t t2)
{
return (abstimelt(t1, t2));
}
bool
timestampgt(time_t t1, time_t t2)
{
return (abstimegt(t1, t2));
}
bool
timestample(time_t t1, time_t t2)
{
return (abstimele(t1, t2));
}
bool
timestampge(time_t t1, time_t t2)
{
return (abstimege(t1, t2));
}
DateTime *
timestamp_datetime(time_t timestamp)
{
return (abstime_datetime((AbsoluteTime) timestamp));
} /* timestamp_datetime() */
time_t
datetime_timestamp(DateTime *datetime)
{
return ((AbsoluteTime) datetime_abstime(datetime));
} /* datetime_timestamp() */
|